ReactFabric-dev.fb.js 624 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @noflow
  8. * @nolint
  9. * @preventMunge
  10. * @generated
  11. */
  12. 'use strict';
  13. if (__DEV__) {
  14. (function() {
  15. "use strict";
  16. var React = require("react");
  17. require("react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore");
  18. var ReactNativePrivateInterface = require("react-native/Libraries/ReactPrivate/ReactNativePrivateInterface");
  19. var Scheduler = require("scheduler");
  20. var tracing = require("scheduler/tracing");
  21. var ReactSharedInternals =
  22. React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Prevent newer renderers from RTE when used with older react package versions.
  23. // Current owner and dispatcher used to share the same ref,
  24. // but PR #14548 split them out to better support the react-debug-tools package.
  25. if (!ReactSharedInternals.hasOwnProperty("ReactCurrentDispatcher")) {
  26. ReactSharedInternals.ReactCurrentDispatcher = {
  27. current: null
  28. };
  29. }
  30. if (!ReactSharedInternals.hasOwnProperty("ReactCurrentBatchConfig")) {
  31. ReactSharedInternals.ReactCurrentBatchConfig = {
  32. suspense: null
  33. };
  34. }
  35. // by calls to these methods by a Babel plugin.
  36. //
  37. // In PROD (or in packages without access to React internals),
  38. // they are left as they are instead.
  39. function warn(format) {
  40. {
  41. for (
  42. var _len = arguments.length,
  43. args = new Array(_len > 1 ? _len - 1 : 0),
  44. _key = 1;
  45. _key < _len;
  46. _key++
  47. ) {
  48. args[_key - 1] = arguments[_key];
  49. }
  50. printWarning("warn", format, args);
  51. }
  52. }
  53. function error(format) {
  54. {
  55. for (
  56. var _len2 = arguments.length,
  57. args = new Array(_len2 > 1 ? _len2 - 1 : 0),
  58. _key2 = 1;
  59. _key2 < _len2;
  60. _key2++
  61. ) {
  62. args[_key2 - 1] = arguments[_key2];
  63. }
  64. printWarning("error", format, args);
  65. }
  66. }
  67. function printWarning(level, format, args) {
  68. // When changing this logic, you might want to also
  69. // update consoleWithStackDev.www.js as well.
  70. {
  71. var hasExistingStack =
  72. args.length > 0 &&
  73. typeof args[args.length - 1] === "string" &&
  74. args[args.length - 1].indexOf("\n in") === 0;
  75. if (!hasExistingStack) {
  76. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  77. var stack = ReactDebugCurrentFrame.getStackAddendum();
  78. if (stack !== "") {
  79. format += "%s";
  80. args = args.concat([stack]);
  81. }
  82. }
  83. var argsWithFormat = args.map(function(item) {
  84. return "" + item;
  85. }); // Careful: RN currently depends on this prefix
  86. argsWithFormat.unshift("Warning: " + format); // We intentionally don't use spread (or .apply) directly because it
  87. // breaks IE9: https://github.com/facebook/react/issues/13610
  88. // eslint-disable-next-line react-internal/no-production-logging
  89. Function.prototype.apply.call(console[level], console, argsWithFormat);
  90. try {
  91. // --- Welcome to debugging React ---
  92. // This error was thrown as a convenience so that you can use this stack
  93. // to find the callsite that caused this warning to fire.
  94. var argIndex = 0;
  95. var message =
  96. "Warning: " +
  97. format.replace(/%s/g, function() {
  98. return args[argIndex++];
  99. });
  100. throw new Error(message);
  101. } catch (x) {}
  102. }
  103. }
  104. var FunctionComponent = 0;
  105. var ClassComponent = 1;
  106. var IndeterminateComponent = 2; // Before we know whether it is function or class
  107. var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
  108. var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
  109. var HostComponent = 5;
  110. var HostText = 6;
  111. var Fragment = 7;
  112. var Mode = 8;
  113. var ContextConsumer = 9;
  114. var ContextProvider = 10;
  115. var ForwardRef = 11;
  116. var Profiler = 12;
  117. var SuspenseComponent = 13;
  118. var MemoComponent = 14;
  119. var SimpleMemoComponent = 15;
  120. var LazyComponent = 16;
  121. var IncompleteClassComponent = 17;
  122. var DehydratedFragment = 18;
  123. var SuspenseListComponent = 19;
  124. var FundamentalComponent = 20;
  125. var ScopeComponent = 21;
  126. var Block = 22;
  127. function getParent(inst) {
  128. do {
  129. inst = inst.return; // TODO: If this is a HostRoot we might want to bail out.
  130. // That is depending on if we want nested subtrees (layers) to bubble
  131. // events to their parent. We could also go through parentNode on the
  132. // host node but that wouldn't work for React Native and doesn't let us
  133. // do the portal feature.
  134. } while (inst && inst.tag !== HostComponent);
  135. if (inst) {
  136. return inst;
  137. }
  138. return null;
  139. }
  140. /**
  141. * Return the lowest common ancestor of A and B, or null if they are in
  142. * different trees.
  143. */
  144. function getLowestCommonAncestor(instA, instB) {
  145. var depthA = 0;
  146. for (var tempA = instA; tempA; tempA = getParent(tempA)) {
  147. depthA++;
  148. }
  149. var depthB = 0;
  150. for (var tempB = instB; tempB; tempB = getParent(tempB)) {
  151. depthB++;
  152. } // If A is deeper, crawl up.
  153. while (depthA - depthB > 0) {
  154. instA = getParent(instA);
  155. depthA--;
  156. } // If B is deeper, crawl up.
  157. while (depthB - depthA > 0) {
  158. instB = getParent(instB);
  159. depthB--;
  160. } // Walk in lockstep until we find a match.
  161. var depth = depthA;
  162. while (depth--) {
  163. if (instA === instB || instA === instB.alternate) {
  164. return instA;
  165. }
  166. instA = getParent(instA);
  167. instB = getParent(instB);
  168. }
  169. return null;
  170. }
  171. /**
  172. * Return if A is an ancestor of B.
  173. */
  174. function isAncestor(instA, instB) {
  175. while (instB) {
  176. if (instA === instB || instA === instB.alternate) {
  177. return true;
  178. }
  179. instB = getParent(instB);
  180. }
  181. return false;
  182. }
  183. /**
  184. * Return the parent instance of the passed-in instance.
  185. */
  186. function getParentInstance(inst) {
  187. return getParent(inst);
  188. }
  189. /**
  190. * Simulates the traversal of a two-phase, capture/bubble event dispatch.
  191. */
  192. function traverseTwoPhase(inst, fn, arg) {
  193. var path = [];
  194. while (inst) {
  195. path.push(inst);
  196. inst = getParent(inst);
  197. }
  198. var i;
  199. for (i = path.length; i-- > 0; ) {
  200. fn(path[i], "captured", arg);
  201. }
  202. for (i = 0; i < path.length; i++) {
  203. fn(path[i], "bubbled", arg);
  204. }
  205. }
  206. var invokeGuardedCallbackImpl = function(
  207. name,
  208. func,
  209. context,
  210. a,
  211. b,
  212. c,
  213. d,
  214. e,
  215. f
  216. ) {
  217. var funcArgs = Array.prototype.slice.call(arguments, 3);
  218. try {
  219. func.apply(context, funcArgs);
  220. } catch (error) {
  221. this.onError(error);
  222. }
  223. };
  224. {
  225. // In DEV mode, we swap out invokeGuardedCallback for a special version
  226. // that plays more nicely with the browser's DevTools. The idea is to preserve
  227. // "Pause on exceptions" behavior. Because React wraps all user-provided
  228. // functions in invokeGuardedCallback, and the production version of
  229. // invokeGuardedCallback uses a try-catch, all user exceptions are treated
  230. // like caught exceptions, and the DevTools won't pause unless the developer
  231. // takes the extra step of enabling pause on caught exceptions. This is
  232. // unintuitive, though, because even though React has caught the error, from
  233. // the developer's perspective, the error is uncaught.
  234. //
  235. // To preserve the expected "Pause on exceptions" behavior, we don't use a
  236. // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
  237. // DOM node, and call the user-provided callback from inside an event handler
  238. // for that fake event. If the callback throws, the error is "captured" using
  239. // a global event handler. But because the error happens in a different
  240. // event loop context, it does not interrupt the normal program flow.
  241. // Effectively, this gives us try-catch behavior without actually using
  242. // try-catch. Neat!
  243. // Check that the browser supports the APIs we need to implement our special
  244. // DEV version of invokeGuardedCallback
  245. if (
  246. typeof window !== "undefined" &&
  247. typeof window.dispatchEvent === "function" &&
  248. typeof document !== "undefined" &&
  249. typeof document.createEvent === "function"
  250. ) {
  251. var fakeNode = document.createElement("react");
  252. var invokeGuardedCallbackDev = function(
  253. name,
  254. func,
  255. context,
  256. a,
  257. b,
  258. c,
  259. d,
  260. e,
  261. f
  262. ) {
  263. // If document doesn't exist we know for sure we will crash in this method
  264. // when we call document.createEvent(). However this can cause confusing
  265. // errors: https://github.com/facebookincubator/create-react-app/issues/3482
  266. // So we preemptively throw with a better message instead.
  267. if (!(typeof document !== "undefined")) {
  268. throw Error(
  269. "The `document` global was defined when React was initialized, but is not defined anymore. This can happen in a test environment if a component schedules an update from an asynchronous callback, but the test has already finished running. To solve this, you can either unmount the component at the end of your test (and ensure that any asynchronous operations get canceled in `componentWillUnmount`), or you can change the test itself to be asynchronous."
  270. );
  271. }
  272. var evt = document.createEvent("Event"); // Keeps track of whether the user-provided callback threw an error. We
  273. // set this to true at the beginning, then set it to false right after
  274. // calling the function. If the function errors, `didError` will never be
  275. // set to false. This strategy works even if the browser is flaky and
  276. // fails to call our global error handler, because it doesn't rely on
  277. // the error event at all.
  278. var didError = true; // Keeps track of the value of window.event so that we can reset it
  279. // during the callback to let user code access window.event in the
  280. // browsers that support it.
  281. var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
  282. // dispatching: https://github.com/facebook/react/issues/13688
  283. var windowEventDescriptor = Object.getOwnPropertyDescriptor(
  284. window,
  285. "event"
  286. ); // Create an event handler for our fake event. We will synchronously
  287. // dispatch our fake event using `dispatchEvent`. Inside the handler, we
  288. // call the user-provided callback.
  289. var funcArgs = Array.prototype.slice.call(arguments, 3);
  290. function callCallback() {
  291. // We immediately remove the callback from event listeners so that
  292. // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
  293. // nested call would trigger the fake event handlers of any call higher
  294. // in the stack.
  295. fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
  296. // window.event assignment in both IE <= 10 as they throw an error
  297. // "Member not found" in strict mode, and in Firefox which does not
  298. // support window.event.
  299. if (
  300. typeof window.event !== "undefined" &&
  301. window.hasOwnProperty("event")
  302. ) {
  303. window.event = windowEvent;
  304. }
  305. func.apply(context, funcArgs);
  306. didError = false;
  307. } // Create a global error event handler. We use this to capture the value
  308. // that was thrown. It's possible that this error handler will fire more
  309. // than once; for example, if non-React code also calls `dispatchEvent`
  310. // and a handler for that event throws. We should be resilient to most of
  311. // those cases. Even if our error event handler fires more than once, the
  312. // last error event is always used. If the callback actually does error,
  313. // we know that the last error event is the correct one, because it's not
  314. // possible for anything else to have happened in between our callback
  315. // erroring and the code that follows the `dispatchEvent` call below. If
  316. // the callback doesn't error, but the error event was fired, we know to
  317. // ignore it because `didError` will be false, as described above.
  318. var error; // Use this to track whether the error event is ever called.
  319. var didSetError = false;
  320. var isCrossOriginError = false;
  321. function handleWindowError(event) {
  322. error = event.error;
  323. didSetError = true;
  324. if (error === null && event.colno === 0 && event.lineno === 0) {
  325. isCrossOriginError = true;
  326. }
  327. if (event.defaultPrevented) {
  328. // Some other error handler has prevented default.
  329. // Browsers silence the error report if this happens.
  330. // We'll remember this to later decide whether to log it or not.
  331. if (error != null && typeof error === "object") {
  332. try {
  333. error._suppressLogging = true;
  334. } catch (inner) {
  335. // Ignore.
  336. }
  337. }
  338. }
  339. } // Create a fake event type.
  340. var evtType = "react-" + (name ? name : "invokeguardedcallback"); // Attach our event handlers
  341. window.addEventListener("error", handleWindowError);
  342. fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
  343. // errors, it will trigger our global error handler.
  344. evt.initEvent(evtType, false, false);
  345. fakeNode.dispatchEvent(evt);
  346. if (windowEventDescriptor) {
  347. Object.defineProperty(window, "event", windowEventDescriptor);
  348. }
  349. if (didError) {
  350. if (!didSetError) {
  351. // The callback errored, but the error event never fired.
  352. error = new Error(
  353. "An error was thrown inside one of your components, but React " +
  354. "doesn't know what it was. This is likely due to browser " +
  355. 'flakiness. React does its best to preserve the "Pause on ' +
  356. 'exceptions" behavior of the DevTools, which requires some ' +
  357. "DEV-mode only tricks. It's possible that these don't work in " +
  358. "your browser. Try triggering the error in production mode, " +
  359. "or switching to a modern browser. If you suspect that this is " +
  360. "actually an issue with React, please file an issue."
  361. );
  362. } else if (isCrossOriginError) {
  363. error = new Error(
  364. "A cross-origin error was thrown. React doesn't have access to " +
  365. "the actual error object in development. " +
  366. "See https://fb.me/react-crossorigin-error for more information."
  367. );
  368. }
  369. this.onError(error);
  370. } // Remove our event listeners
  371. window.removeEventListener("error", handleWindowError);
  372. };
  373. invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
  374. }
  375. }
  376. var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
  377. var hasError = false;
  378. var caughtError = null; // Used by event system to capture/rethrow the first error.
  379. var hasRethrowError = false;
  380. var rethrowError = null;
  381. var reporter = {
  382. onError: function(error) {
  383. hasError = true;
  384. caughtError = error;
  385. }
  386. };
  387. /**
  388. * Call a function while guarding against errors that happens within it.
  389. * Returns an error if it throws, otherwise null.
  390. *
  391. * In production, this is implemented using a try-catch. The reason we don't
  392. * use a try-catch directly is so that we can swap out a different
  393. * implementation in DEV mode.
  394. *
  395. * @param {String} name of the guard to use for logging or debugging
  396. * @param {Function} func The function to invoke
  397. * @param {*} context The context to use when calling the function
  398. * @param {...*} args Arguments for function
  399. */
  400. function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
  401. hasError = false;
  402. caughtError = null;
  403. invokeGuardedCallbackImpl$1.apply(reporter, arguments);
  404. }
  405. /**
  406. * Same as invokeGuardedCallback, but instead of returning an error, it stores
  407. * it in a global so it can be rethrown by `rethrowCaughtError` later.
  408. * TODO: See if caughtError and rethrowError can be unified.
  409. *
  410. * @param {String} name of the guard to use for logging or debugging
  411. * @param {Function} func The function to invoke
  412. * @param {*} context The context to use when calling the function
  413. * @param {...*} args Arguments for function
  414. */
  415. function invokeGuardedCallbackAndCatchFirstError(
  416. name,
  417. func,
  418. context,
  419. a,
  420. b,
  421. c,
  422. d,
  423. e,
  424. f
  425. ) {
  426. invokeGuardedCallback.apply(this, arguments);
  427. if (hasError) {
  428. var error = clearCaughtError();
  429. if (!hasRethrowError) {
  430. hasRethrowError = true;
  431. rethrowError = error;
  432. }
  433. }
  434. }
  435. /**
  436. * During execution of guarded functions we will capture the first error which
  437. * we will rethrow to be handled by the top level error handler.
  438. */
  439. function rethrowCaughtError() {
  440. if (hasRethrowError) {
  441. var error = rethrowError;
  442. hasRethrowError = false;
  443. rethrowError = null;
  444. throw error;
  445. }
  446. }
  447. function hasCaughtError() {
  448. return hasError;
  449. }
  450. function clearCaughtError() {
  451. if (hasError) {
  452. var error = caughtError;
  453. hasError = false;
  454. caughtError = null;
  455. return error;
  456. } else {
  457. {
  458. throw Error(
  459. "clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue."
  460. );
  461. }
  462. }
  463. }
  464. var getFiberCurrentPropsFromNode = null;
  465. var getInstanceFromNode = null;
  466. var getNodeFromInstance = null;
  467. function setComponentTree(
  468. getFiberCurrentPropsFromNodeImpl,
  469. getInstanceFromNodeImpl,
  470. getNodeFromInstanceImpl
  471. ) {
  472. getFiberCurrentPropsFromNode = getFiberCurrentPropsFromNodeImpl;
  473. getInstanceFromNode = getInstanceFromNodeImpl;
  474. getNodeFromInstance = getNodeFromInstanceImpl;
  475. {
  476. if (!getNodeFromInstance || !getInstanceFromNode) {
  477. error(
  478. "EventPluginUtils.setComponentTree(...): Injected " +
  479. "module is missing getNodeFromInstance or getInstanceFromNode."
  480. );
  481. }
  482. }
  483. }
  484. var validateEventDispatches;
  485. {
  486. validateEventDispatches = function(event) {
  487. var dispatchListeners = event._dispatchListeners;
  488. var dispatchInstances = event._dispatchInstances;
  489. var listenersIsArr = Array.isArray(dispatchListeners);
  490. var listenersLen = listenersIsArr
  491. ? dispatchListeners.length
  492. : dispatchListeners
  493. ? 1
  494. : 0;
  495. var instancesIsArr = Array.isArray(dispatchInstances);
  496. var instancesLen = instancesIsArr
  497. ? dispatchInstances.length
  498. : dispatchInstances
  499. ? 1
  500. : 0;
  501. if (instancesIsArr !== listenersIsArr || instancesLen !== listenersLen) {
  502. error("EventPluginUtils: Invalid `event`.");
  503. }
  504. };
  505. }
  506. /**
  507. * Dispatch the event to the listener.
  508. * @param {SyntheticEvent} event SyntheticEvent to handle
  509. * @param {function} listener Application-level callback
  510. * @param {*} inst Internal component instance
  511. */
  512. function executeDispatch(event, listener, inst) {
  513. var type = event.type || "unknown-event";
  514. event.currentTarget = getNodeFromInstance(inst);
  515. invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event);
  516. event.currentTarget = null;
  517. }
  518. /**
  519. * Standard/simple iteration through an event's collected dispatches.
  520. */
  521. function executeDispatchesInOrder(event) {
  522. var dispatchListeners = event._dispatchListeners;
  523. var dispatchInstances = event._dispatchInstances;
  524. {
  525. validateEventDispatches(event);
  526. }
  527. if (Array.isArray(dispatchListeners)) {
  528. for (var i = 0; i < dispatchListeners.length; i++) {
  529. if (event.isPropagationStopped()) {
  530. break;
  531. } // Listeners and Instances are two parallel arrays that are always in sync.
  532. executeDispatch(event, dispatchListeners[i], dispatchInstances[i]);
  533. }
  534. } else if (dispatchListeners) {
  535. executeDispatch(event, dispatchListeners, dispatchInstances);
  536. }
  537. event._dispatchListeners = null;
  538. event._dispatchInstances = null;
  539. }
  540. /**
  541. * Standard/simple iteration through an event's collected dispatches, but stops
  542. * at the first dispatch execution returning true, and returns that id.
  543. *
  544. * @return {?string} id of the first dispatch execution who's listener returns
  545. * true, or null if no listener returned true.
  546. */
  547. function executeDispatchesInOrderStopAtTrueImpl(event) {
  548. var dispatchListeners = event._dispatchListeners;
  549. var dispatchInstances = event._dispatchInstances;
  550. {
  551. validateEventDispatches(event);
  552. }
  553. if (Array.isArray(dispatchListeners)) {
  554. for (var i = 0; i < dispatchListeners.length; i++) {
  555. if (event.isPropagationStopped()) {
  556. break;
  557. } // Listeners and Instances are two parallel arrays that are always in sync.
  558. if (dispatchListeners[i](event, dispatchInstances[i])) {
  559. return dispatchInstances[i];
  560. }
  561. }
  562. } else if (dispatchListeners) {
  563. if (dispatchListeners(event, dispatchInstances)) {
  564. return dispatchInstances;
  565. }
  566. }
  567. return null;
  568. }
  569. /**
  570. * @see executeDispatchesInOrderStopAtTrueImpl
  571. */
  572. function executeDispatchesInOrderStopAtTrue(event) {
  573. var ret = executeDispatchesInOrderStopAtTrueImpl(event);
  574. event._dispatchInstances = null;
  575. event._dispatchListeners = null;
  576. return ret;
  577. }
  578. /**
  579. * Execution of a "direct" dispatch - there must be at most one dispatch
  580. * accumulated on the event or it is considered an error. It doesn't really make
  581. * sense for an event with multiple dispatches (bubbled) to keep track of the
  582. * return values at each dispatch execution, but it does tend to make sense when
  583. * dealing with "direct" dispatches.
  584. *
  585. * @return {*} The return value of executing the single dispatch.
  586. */
  587. function executeDirectDispatch(event) {
  588. {
  589. validateEventDispatches(event);
  590. }
  591. var dispatchListener = event._dispatchListeners;
  592. var dispatchInstance = event._dispatchInstances;
  593. if (!!Array.isArray(dispatchListener)) {
  594. throw Error("executeDirectDispatch(...): Invalid `event`.");
  595. }
  596. event.currentTarget = dispatchListener
  597. ? getNodeFromInstance(dispatchInstance)
  598. : null;
  599. var res = dispatchListener ? dispatchListener(event) : null;
  600. event.currentTarget = null;
  601. event._dispatchListeners = null;
  602. event._dispatchInstances = null;
  603. return res;
  604. }
  605. /**
  606. * @param {SyntheticEvent} event
  607. * @return {boolean} True iff number of dispatches accumulated is greater than 0.
  608. */
  609. function hasDispatches(event) {
  610. return !!event._dispatchListeners;
  611. }
  612. function isInteractive(tag) {
  613. return (
  614. tag === "button" ||
  615. tag === "input" ||
  616. tag === "select" ||
  617. tag === "textarea"
  618. );
  619. }
  620. function shouldPreventMouseEvent(name, type, props) {
  621. switch (name) {
  622. case "onClick":
  623. case "onClickCapture":
  624. case "onDoubleClick":
  625. case "onDoubleClickCapture":
  626. case "onMouseDown":
  627. case "onMouseDownCapture":
  628. case "onMouseMove":
  629. case "onMouseMoveCapture":
  630. case "onMouseUp":
  631. case "onMouseUpCapture":
  632. case "onMouseEnter":
  633. return !!(props.disabled && isInteractive(type));
  634. default:
  635. return false;
  636. }
  637. }
  638. /**
  639. * @param {object} inst The instance, which is the source of events.
  640. * @param {string} registrationName Name of listener (e.g. `onClick`).
  641. * @return {?function} The stored callback.
  642. */
  643. function getListener(inst, registrationName) {
  644. var listener; // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
  645. // live here; needs to be moved to a better place soon
  646. var stateNode = inst.stateNode;
  647. if (!stateNode) {
  648. // Work in progress (ex: onload events in incremental mode).
  649. return null;
  650. }
  651. var props = getFiberCurrentPropsFromNode(stateNode);
  652. if (!props) {
  653. // Work in progress.
  654. return null;
  655. }
  656. listener = props[registrationName];
  657. if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
  658. return null;
  659. }
  660. if (!(!listener || typeof listener === "function")) {
  661. throw Error(
  662. "Expected `" +
  663. registrationName +
  664. "` listener to be a function, instead got a value of `" +
  665. typeof listener +
  666. "` type."
  667. );
  668. }
  669. return listener;
  670. }
  671. /**
  672. * Accumulates items that must not be null or undefined into the first one. This
  673. * is used to conserve memory by avoiding array allocations, and thus sacrifices
  674. * API cleanness. Since `current` can be null before being passed in and not
  675. * null after this function, make sure to assign it back to `current`:
  676. *
  677. * `a = accumulateInto(a, b);`
  678. *
  679. * This API should be sparingly used. Try `accumulate` for something cleaner.
  680. *
  681. * @return {*|array<*>} An accumulation of items.
  682. */
  683. function accumulateInto(current, next) {
  684. if (!(next != null)) {
  685. throw Error(
  686. "accumulateInto(...): Accumulated items must not be null or undefined."
  687. );
  688. }
  689. if (current == null) {
  690. return next;
  691. } // Both are not empty. Warning: Never call x.concat(y) when you are not
  692. // certain that x is an Array (x could be a string with concat method).
  693. if (Array.isArray(current)) {
  694. if (Array.isArray(next)) {
  695. current.push.apply(current, next);
  696. return current;
  697. }
  698. current.push(next);
  699. return current;
  700. }
  701. if (Array.isArray(next)) {
  702. // A bit too dangerous to mutate `next`.
  703. return [current].concat(next);
  704. }
  705. return [current, next];
  706. }
  707. /**
  708. * @param {array} arr an "accumulation" of items which is either an Array or
  709. * a single item. Useful when paired with the `accumulate` module. This is a
  710. * simple utility that allows us to reason about a collection of items, but
  711. * handling the case when there is exactly one item (and we do not need to
  712. * allocate an array).
  713. * @param {function} cb Callback invoked with each element or a collection.
  714. * @param {?} [scope] Scope used as `this` in a callback.
  715. */
  716. function forEachAccumulated(arr, cb, scope) {
  717. if (Array.isArray(arr)) {
  718. arr.forEach(cb, scope);
  719. } else if (arr) {
  720. cb.call(scope, arr);
  721. }
  722. }
  723. /**
  724. * Some event types have a notion of different registration names for different
  725. * "phases" of propagation. This finds listeners by a given phase.
  726. */
  727. function listenerAtPhase(inst, event, propagationPhase) {
  728. var registrationName =
  729. event.dispatchConfig.phasedRegistrationNames[propagationPhase];
  730. return getListener(inst, registrationName);
  731. }
  732. /**
  733. * A small set of propagation patterns, each of which will accept a small amount
  734. * of information, and generate a set of "dispatch ready event objects" - which
  735. * are sets of events that have already been annotated with a set of dispatched
  736. * listener functions/ids. The API is designed this way to discourage these
  737. * propagation strategies from actually executing the dispatches, since we
  738. * always want to collect the entire set of dispatches before executing even a
  739. * single one.
  740. */
  741. /**
  742. * Tags a `SyntheticEvent` with dispatched listeners. Creating this function
  743. * here, allows us to not have to bind or create functions for each event.
  744. * Mutating the event's members allows us to not have to create a wrapping
  745. * "dispatch" object that pairs the event with the listener.
  746. */
  747. function accumulateDirectionalDispatches(inst, phase, event) {
  748. {
  749. if (!inst) {
  750. error("Dispatching inst must not be null");
  751. }
  752. }
  753. var listener = listenerAtPhase(inst, event, phase);
  754. if (listener) {
  755. event._dispatchListeners = accumulateInto(
  756. event._dispatchListeners,
  757. listener
  758. );
  759. event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
  760. }
  761. }
  762. /**
  763. * Collect dispatches (must be entirely collected before dispatching - see unit
  764. * tests). Lazily allocate the array to conserve memory. We must loop through
  765. * each event and perform the traversal for each one. We cannot perform a
  766. * single traversal for the entire collection of events because each event may
  767. * have a different target.
  768. */
  769. function accumulateTwoPhaseDispatchesSingle(event) {
  770. if (event && event.dispatchConfig.phasedRegistrationNames) {
  771. traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
  772. }
  773. }
  774. /**
  775. * Same as `accumulateTwoPhaseDispatchesSingle`, but skips over the targetID.
  776. */
  777. function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
  778. if (event && event.dispatchConfig.phasedRegistrationNames) {
  779. var targetInst = event._targetInst;
  780. var parentInst = targetInst ? getParentInstance(targetInst) : null;
  781. traverseTwoPhase(parentInst, accumulateDirectionalDispatches, event);
  782. }
  783. }
  784. /**
  785. * Accumulates without regard to direction, does not look for phased
  786. * registration names. Same as `accumulateDirectDispatchesSingle` but without
  787. * requiring that the `dispatchMarker` be the same as the dispatched ID.
  788. */
  789. function accumulateDispatches(inst, ignoredDirection, event) {
  790. if (inst && event && event.dispatchConfig.registrationName) {
  791. var registrationName = event.dispatchConfig.registrationName;
  792. var listener = getListener(inst, registrationName);
  793. if (listener) {
  794. event._dispatchListeners = accumulateInto(
  795. event._dispatchListeners,
  796. listener
  797. );
  798. event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
  799. }
  800. }
  801. }
  802. /**
  803. * Accumulates dispatches on an `SyntheticEvent`, but only for the
  804. * `dispatchMarker`.
  805. * @param {SyntheticEvent} event
  806. */
  807. function accumulateDirectDispatchesSingle(event) {
  808. if (event && event.dispatchConfig.registrationName) {
  809. accumulateDispatches(event._targetInst, null, event);
  810. }
  811. }
  812. function accumulateTwoPhaseDispatches(events) {
  813. forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle);
  814. }
  815. function accumulateTwoPhaseDispatchesSkipTarget(events) {
  816. forEachAccumulated(events, accumulateTwoPhaseDispatchesSingleSkipTarget);
  817. }
  818. function accumulateDirectDispatches(events) {
  819. forEachAccumulated(events, accumulateDirectDispatchesSingle);
  820. }
  821. var EVENT_POOL_SIZE = 10;
  822. /**
  823. * @interface Event
  824. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  825. */
  826. var EventInterface = {
  827. type: null,
  828. target: null,
  829. // currentTarget is set when dispatching; no use in copying it here
  830. currentTarget: function() {
  831. return null;
  832. },
  833. eventPhase: null,
  834. bubbles: null,
  835. cancelable: null,
  836. timeStamp: function(event) {
  837. return event.timeStamp || Date.now();
  838. },
  839. defaultPrevented: null,
  840. isTrusted: null
  841. };
  842. function functionThatReturnsTrue() {
  843. return true;
  844. }
  845. function functionThatReturnsFalse() {
  846. return false;
  847. }
  848. /**
  849. * Synthetic events are dispatched by event plugins, typically in response to a
  850. * top-level event delegation handler.
  851. *
  852. * These systems should generally use pooling to reduce the frequency of garbage
  853. * collection. The system should check `isPersistent` to determine whether the
  854. * event should be released into the pool after being dispatched. Users that
  855. * need a persisted event should invoke `persist`.
  856. *
  857. * Synthetic events (and subclasses) implement the DOM Level 3 Events API by
  858. * normalizing browser quirks. Subclasses do not necessarily have to implement a
  859. * DOM interface; custom application-specific events can also subclass this.
  860. *
  861. * @param {object} dispatchConfig Configuration used to dispatch this event.
  862. * @param {*} targetInst Marker identifying the event target.
  863. * @param {object} nativeEvent Native browser event.
  864. * @param {DOMEventTarget} nativeEventTarget Target node.
  865. */
  866. function SyntheticEvent(
  867. dispatchConfig,
  868. targetInst,
  869. nativeEvent,
  870. nativeEventTarget
  871. ) {
  872. {
  873. // these have a getter/setter for warnings
  874. delete this.nativeEvent;
  875. delete this.preventDefault;
  876. delete this.stopPropagation;
  877. delete this.isDefaultPrevented;
  878. delete this.isPropagationStopped;
  879. }
  880. this.dispatchConfig = dispatchConfig;
  881. this._targetInst = targetInst;
  882. this.nativeEvent = nativeEvent;
  883. var Interface = this.constructor.Interface;
  884. for (var propName in Interface) {
  885. if (!Interface.hasOwnProperty(propName)) {
  886. continue;
  887. }
  888. {
  889. delete this[propName]; // this has a getter/setter for warnings
  890. }
  891. var normalize = Interface[propName];
  892. if (normalize) {
  893. this[propName] = normalize(nativeEvent);
  894. } else {
  895. if (propName === "target") {
  896. this.target = nativeEventTarget;
  897. } else {
  898. this[propName] = nativeEvent[propName];
  899. }
  900. }
  901. }
  902. var defaultPrevented =
  903. nativeEvent.defaultPrevented != null
  904. ? nativeEvent.defaultPrevented
  905. : nativeEvent.returnValue === false;
  906. if (defaultPrevented) {
  907. this.isDefaultPrevented = functionThatReturnsTrue;
  908. } else {
  909. this.isDefaultPrevented = functionThatReturnsFalse;
  910. }
  911. this.isPropagationStopped = functionThatReturnsFalse;
  912. return this;
  913. }
  914. Object.assign(SyntheticEvent.prototype, {
  915. preventDefault: function() {
  916. this.defaultPrevented = true;
  917. var event = this.nativeEvent;
  918. if (!event) {
  919. return;
  920. }
  921. if (event.preventDefault) {
  922. event.preventDefault();
  923. } else if (typeof event.returnValue !== "unknown") {
  924. event.returnValue = false;
  925. }
  926. this.isDefaultPrevented = functionThatReturnsTrue;
  927. },
  928. stopPropagation: function() {
  929. var event = this.nativeEvent;
  930. if (!event) {
  931. return;
  932. }
  933. if (event.stopPropagation) {
  934. event.stopPropagation();
  935. } else if (typeof event.cancelBubble !== "unknown") {
  936. // The ChangeEventPlugin registers a "propertychange" event for
  937. // IE. This event does not support bubbling or cancelling, and
  938. // any references to cancelBubble throw "Member not found". A
  939. // typeof check of "unknown" circumvents this issue (and is also
  940. // IE specific).
  941. event.cancelBubble = true;
  942. }
  943. this.isPropagationStopped = functionThatReturnsTrue;
  944. },
  945. /**
  946. * We release all dispatched `SyntheticEvent`s after each event loop, adding
  947. * them back into the pool. This allows a way to hold onto a reference that
  948. * won't be added back into the pool.
  949. */
  950. persist: function() {
  951. this.isPersistent = functionThatReturnsTrue;
  952. },
  953. /**
  954. * Checks if this event should be released back into the pool.
  955. *
  956. * @return {boolean} True if this should not be released, false otherwise.
  957. */
  958. isPersistent: functionThatReturnsFalse,
  959. /**
  960. * `PooledClass` looks for `destructor` on each instance it releases.
  961. */
  962. destructor: function() {
  963. var Interface = this.constructor.Interface;
  964. for (var propName in Interface) {
  965. {
  966. Object.defineProperty(
  967. this,
  968. propName,
  969. getPooledWarningPropertyDefinition(propName, Interface[propName])
  970. );
  971. }
  972. }
  973. this.dispatchConfig = null;
  974. this._targetInst = null;
  975. this.nativeEvent = null;
  976. this.isDefaultPrevented = functionThatReturnsFalse;
  977. this.isPropagationStopped = functionThatReturnsFalse;
  978. this._dispatchListeners = null;
  979. this._dispatchInstances = null;
  980. {
  981. Object.defineProperty(
  982. this,
  983. "nativeEvent",
  984. getPooledWarningPropertyDefinition("nativeEvent", null)
  985. );
  986. Object.defineProperty(
  987. this,
  988. "isDefaultPrevented",
  989. getPooledWarningPropertyDefinition(
  990. "isDefaultPrevented",
  991. functionThatReturnsFalse
  992. )
  993. );
  994. Object.defineProperty(
  995. this,
  996. "isPropagationStopped",
  997. getPooledWarningPropertyDefinition(
  998. "isPropagationStopped",
  999. functionThatReturnsFalse
  1000. )
  1001. );
  1002. Object.defineProperty(
  1003. this,
  1004. "preventDefault",
  1005. getPooledWarningPropertyDefinition("preventDefault", function() {})
  1006. );
  1007. Object.defineProperty(
  1008. this,
  1009. "stopPropagation",
  1010. getPooledWarningPropertyDefinition("stopPropagation", function() {})
  1011. );
  1012. }
  1013. }
  1014. });
  1015. SyntheticEvent.Interface = EventInterface;
  1016. /**
  1017. * Helper to reduce boilerplate when creating subclasses.
  1018. */
  1019. SyntheticEvent.extend = function(Interface) {
  1020. var Super = this;
  1021. var E = function() {};
  1022. E.prototype = Super.prototype;
  1023. var prototype = new E();
  1024. function Class() {
  1025. return Super.apply(this, arguments);
  1026. }
  1027. Object.assign(prototype, Class.prototype);
  1028. Class.prototype = prototype;
  1029. Class.prototype.constructor = Class;
  1030. Class.Interface = Object.assign({}, Super.Interface, Interface);
  1031. Class.extend = Super.extend;
  1032. addEventPoolingTo(Class);
  1033. return Class;
  1034. };
  1035. addEventPoolingTo(SyntheticEvent);
  1036. /**
  1037. * Helper to nullify syntheticEvent instance properties when destructing
  1038. *
  1039. * @param {String} propName
  1040. * @param {?object} getVal
  1041. * @return {object} defineProperty object
  1042. */
  1043. function getPooledWarningPropertyDefinition(propName, getVal) {
  1044. var isFunction = typeof getVal === "function";
  1045. return {
  1046. configurable: true,
  1047. set: set,
  1048. get: get
  1049. };
  1050. function set(val) {
  1051. var action = isFunction ? "setting the method" : "setting the property";
  1052. warn(action, "This is effectively a no-op");
  1053. return val;
  1054. }
  1055. function get() {
  1056. var action = isFunction ? "accessing the method" : "accessing the property";
  1057. var result = isFunction
  1058. ? "This is a no-op function"
  1059. : "This is set to null";
  1060. warn(action, result);
  1061. return getVal;
  1062. }
  1063. function warn(action, result) {
  1064. {
  1065. error(
  1066. "This synthetic event is reused for performance reasons. If you're seeing this, " +
  1067. "you're %s `%s` on a released/nullified synthetic event. %s. " +
  1068. "If you must keep the original synthetic event around, use event.persist(). " +
  1069. "See https://fb.me/react-event-pooling for more information.",
  1070. action,
  1071. propName,
  1072. result
  1073. );
  1074. }
  1075. }
  1076. }
  1077. function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) {
  1078. var EventConstructor = this;
  1079. if (EventConstructor.eventPool.length) {
  1080. var instance = EventConstructor.eventPool.pop();
  1081. EventConstructor.call(
  1082. instance,
  1083. dispatchConfig,
  1084. targetInst,
  1085. nativeEvent,
  1086. nativeInst
  1087. );
  1088. return instance;
  1089. }
  1090. return new EventConstructor(
  1091. dispatchConfig,
  1092. targetInst,
  1093. nativeEvent,
  1094. nativeInst
  1095. );
  1096. }
  1097. function releasePooledEvent(event) {
  1098. var EventConstructor = this;
  1099. if (!(event instanceof EventConstructor)) {
  1100. throw Error(
  1101. "Trying to release an event instance into a pool of a different type."
  1102. );
  1103. }
  1104. event.destructor();
  1105. if (EventConstructor.eventPool.length < EVENT_POOL_SIZE) {
  1106. EventConstructor.eventPool.push(event);
  1107. }
  1108. }
  1109. function addEventPoolingTo(EventConstructor) {
  1110. EventConstructor.eventPool = [];
  1111. EventConstructor.getPooled = getPooledEvent;
  1112. EventConstructor.release = releasePooledEvent;
  1113. }
  1114. /**
  1115. * `touchHistory` isn't actually on the native event, but putting it in the
  1116. * interface will ensure that it is cleaned up when pooled/destroyed. The
  1117. * `ResponderEventPlugin` will populate it appropriately.
  1118. */
  1119. var ResponderSyntheticEvent = SyntheticEvent.extend({
  1120. touchHistory: function(nativeEvent) {
  1121. return null; // Actually doesn't even look at the native event.
  1122. }
  1123. });
  1124. var TOP_TOUCH_START = "topTouchStart";
  1125. var TOP_TOUCH_MOVE = "topTouchMove";
  1126. var TOP_TOUCH_END = "topTouchEnd";
  1127. var TOP_TOUCH_CANCEL = "topTouchCancel";
  1128. var TOP_SCROLL = "topScroll";
  1129. var TOP_SELECTION_CHANGE = "topSelectionChange";
  1130. function isStartish(topLevelType) {
  1131. return topLevelType === TOP_TOUCH_START;
  1132. }
  1133. function isMoveish(topLevelType) {
  1134. return topLevelType === TOP_TOUCH_MOVE;
  1135. }
  1136. function isEndish(topLevelType) {
  1137. return topLevelType === TOP_TOUCH_END || topLevelType === TOP_TOUCH_CANCEL;
  1138. }
  1139. var startDependencies = [TOP_TOUCH_START];
  1140. var moveDependencies = [TOP_TOUCH_MOVE];
  1141. var endDependencies = [TOP_TOUCH_CANCEL, TOP_TOUCH_END];
  1142. /**
  1143. * Tracks the position and time of each active touch by `touch.identifier`. We
  1144. * should typically only see IDs in the range of 1-20 because IDs get recycled
  1145. * when touches end and start again.
  1146. */
  1147. var MAX_TOUCH_BANK = 20;
  1148. var touchBank = [];
  1149. var touchHistory = {
  1150. touchBank: touchBank,
  1151. numberActiveTouches: 0,
  1152. // If there is only one active touch, we remember its location. This prevents
  1153. // us having to loop through all of the touches all the time in the most
  1154. // common case.
  1155. indexOfSingleActiveTouch: -1,
  1156. mostRecentTimeStamp: 0
  1157. };
  1158. function timestampForTouch(touch) {
  1159. // The legacy internal implementation provides "timeStamp", which has been
  1160. // renamed to "timestamp". Let both work for now while we iron it out
  1161. // TODO (evv): rename timeStamp to timestamp in internal code
  1162. return touch.timeStamp || touch.timestamp;
  1163. }
  1164. /**
  1165. * TODO: Instead of making gestures recompute filtered velocity, we could
  1166. * include a built in velocity computation that can be reused globally.
  1167. */
  1168. function createTouchRecord(touch) {
  1169. return {
  1170. touchActive: true,
  1171. startPageX: touch.pageX,
  1172. startPageY: touch.pageY,
  1173. startTimeStamp: timestampForTouch(touch),
  1174. currentPageX: touch.pageX,
  1175. currentPageY: touch.pageY,
  1176. currentTimeStamp: timestampForTouch(touch),
  1177. previousPageX: touch.pageX,
  1178. previousPageY: touch.pageY,
  1179. previousTimeStamp: timestampForTouch(touch)
  1180. };
  1181. }
  1182. function resetTouchRecord(touchRecord, touch) {
  1183. touchRecord.touchActive = true;
  1184. touchRecord.startPageX = touch.pageX;
  1185. touchRecord.startPageY = touch.pageY;
  1186. touchRecord.startTimeStamp = timestampForTouch(touch);
  1187. touchRecord.currentPageX = touch.pageX;
  1188. touchRecord.currentPageY = touch.pageY;
  1189. touchRecord.currentTimeStamp = timestampForTouch(touch);
  1190. touchRecord.previousPageX = touch.pageX;
  1191. touchRecord.previousPageY = touch.pageY;
  1192. touchRecord.previousTimeStamp = timestampForTouch(touch);
  1193. }
  1194. function getTouchIdentifier(_ref) {
  1195. var identifier = _ref.identifier;
  1196. if (!(identifier != null)) {
  1197. throw Error("Touch object is missing identifier.");
  1198. }
  1199. {
  1200. if (identifier > MAX_TOUCH_BANK) {
  1201. error(
  1202. "Touch identifier %s is greater than maximum supported %s which causes " +
  1203. "performance issues backfilling array locations for all of the indices.",
  1204. identifier,
  1205. MAX_TOUCH_BANK
  1206. );
  1207. }
  1208. }
  1209. return identifier;
  1210. }
  1211. function recordTouchStart(touch) {
  1212. var identifier = getTouchIdentifier(touch);
  1213. var touchRecord = touchBank[identifier];
  1214. if (touchRecord) {
  1215. resetTouchRecord(touchRecord, touch);
  1216. } else {
  1217. touchBank[identifier] = createTouchRecord(touch);
  1218. }
  1219. touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
  1220. }
  1221. function recordTouchMove(touch) {
  1222. var touchRecord = touchBank[getTouchIdentifier(touch)];
  1223. if (touchRecord) {
  1224. touchRecord.touchActive = true;
  1225. touchRecord.previousPageX = touchRecord.currentPageX;
  1226. touchRecord.previousPageY = touchRecord.currentPageY;
  1227. touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
  1228. touchRecord.currentPageX = touch.pageX;
  1229. touchRecord.currentPageY = touch.pageY;
  1230. touchRecord.currentTimeStamp = timestampForTouch(touch);
  1231. touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
  1232. } else {
  1233. {
  1234. warn(
  1235. "Cannot record touch move without a touch start.\n" +
  1236. "Touch Move: %s\n" +
  1237. "Touch Bank: %s",
  1238. printTouch(touch),
  1239. printTouchBank()
  1240. );
  1241. }
  1242. }
  1243. }
  1244. function recordTouchEnd(touch) {
  1245. var touchRecord = touchBank[getTouchIdentifier(touch)];
  1246. if (touchRecord) {
  1247. touchRecord.touchActive = false;
  1248. touchRecord.previousPageX = touchRecord.currentPageX;
  1249. touchRecord.previousPageY = touchRecord.currentPageY;
  1250. touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
  1251. touchRecord.currentPageX = touch.pageX;
  1252. touchRecord.currentPageY = touch.pageY;
  1253. touchRecord.currentTimeStamp = timestampForTouch(touch);
  1254. touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
  1255. } else {
  1256. {
  1257. warn(
  1258. "Cannot record touch end without a touch start.\n" +
  1259. "Touch End: %s\n" +
  1260. "Touch Bank: %s",
  1261. printTouch(touch),
  1262. printTouchBank()
  1263. );
  1264. }
  1265. }
  1266. }
  1267. function printTouch(touch) {
  1268. return JSON.stringify({
  1269. identifier: touch.identifier,
  1270. pageX: touch.pageX,
  1271. pageY: touch.pageY,
  1272. timestamp: timestampForTouch(touch)
  1273. });
  1274. }
  1275. function printTouchBank() {
  1276. var printed = JSON.stringify(touchBank.slice(0, MAX_TOUCH_BANK));
  1277. if (touchBank.length > MAX_TOUCH_BANK) {
  1278. printed += " (original size: " + touchBank.length + ")";
  1279. }
  1280. return printed;
  1281. }
  1282. var ResponderTouchHistoryStore = {
  1283. recordTouchTrack: function(topLevelType, nativeEvent) {
  1284. if (isMoveish(topLevelType)) {
  1285. nativeEvent.changedTouches.forEach(recordTouchMove);
  1286. } else if (isStartish(topLevelType)) {
  1287. nativeEvent.changedTouches.forEach(recordTouchStart);
  1288. touchHistory.numberActiveTouches = nativeEvent.touches.length;
  1289. if (touchHistory.numberActiveTouches === 1) {
  1290. touchHistory.indexOfSingleActiveTouch =
  1291. nativeEvent.touches[0].identifier;
  1292. }
  1293. } else if (isEndish(topLevelType)) {
  1294. nativeEvent.changedTouches.forEach(recordTouchEnd);
  1295. touchHistory.numberActiveTouches = nativeEvent.touches.length;
  1296. if (touchHistory.numberActiveTouches === 1) {
  1297. for (var i = 0; i < touchBank.length; i++) {
  1298. var touchTrackToCheck = touchBank[i];
  1299. if (touchTrackToCheck != null && touchTrackToCheck.touchActive) {
  1300. touchHistory.indexOfSingleActiveTouch = i;
  1301. break;
  1302. }
  1303. }
  1304. {
  1305. var activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch];
  1306. if (activeRecord == null || !activeRecord.touchActive) {
  1307. error("Cannot find single active touch.");
  1308. }
  1309. }
  1310. }
  1311. }
  1312. },
  1313. touchHistory: touchHistory
  1314. };
  1315. /**
  1316. * Accumulates items that must not be null or undefined.
  1317. *
  1318. * This is used to conserve memory by avoiding array allocations.
  1319. *
  1320. * @return {*|array<*>} An accumulation of items.
  1321. */
  1322. function accumulate(current, next) {
  1323. if (!(next != null)) {
  1324. throw Error(
  1325. "accumulate(...): Accumulated items must not be null or undefined."
  1326. );
  1327. }
  1328. if (current == null) {
  1329. return next;
  1330. } // Both are not empty. Warning: Never call x.concat(y) when you are not
  1331. // certain that x is an Array (x could be a string with concat method).
  1332. if (Array.isArray(current)) {
  1333. return current.concat(next);
  1334. }
  1335. if (Array.isArray(next)) {
  1336. return [current].concat(next);
  1337. }
  1338. return [current, next];
  1339. }
  1340. /**
  1341. * Instance of element that should respond to touch/move types of interactions,
  1342. * as indicated explicitly by relevant callbacks.
  1343. */
  1344. var responderInst = null;
  1345. /**
  1346. * Count of current touches. A textInput should become responder iff the
  1347. * selection changes while there is a touch on the screen.
  1348. */
  1349. var trackedTouchCount = 0;
  1350. var changeResponder = function(nextResponderInst, blockHostResponder) {
  1351. var oldResponderInst = responderInst;
  1352. responderInst = nextResponderInst;
  1353. if (ResponderEventPlugin.GlobalResponderHandler !== null) {
  1354. ResponderEventPlugin.GlobalResponderHandler.onChange(
  1355. oldResponderInst,
  1356. nextResponderInst,
  1357. blockHostResponder
  1358. );
  1359. }
  1360. };
  1361. var eventTypes = {
  1362. /**
  1363. * On a `touchStart`/`mouseDown`, is it desired that this element become the
  1364. * responder?
  1365. */
  1366. startShouldSetResponder: {
  1367. phasedRegistrationNames: {
  1368. bubbled: "onStartShouldSetResponder",
  1369. captured: "onStartShouldSetResponderCapture"
  1370. },
  1371. dependencies: startDependencies
  1372. },
  1373. /**
  1374. * On a `scroll`, is it desired that this element become the responder? This
  1375. * is usually not needed, but should be used to retroactively infer that a
  1376. * `touchStart` had occurred during momentum scroll. During a momentum scroll,
  1377. * a touch start will be immediately followed by a scroll event if the view is
  1378. * currently scrolling.
  1379. *
  1380. * TODO: This shouldn't bubble.
  1381. */
  1382. scrollShouldSetResponder: {
  1383. phasedRegistrationNames: {
  1384. bubbled: "onScrollShouldSetResponder",
  1385. captured: "onScrollShouldSetResponderCapture"
  1386. },
  1387. dependencies: [TOP_SCROLL]
  1388. },
  1389. /**
  1390. * On text selection change, should this element become the responder? This
  1391. * is needed for text inputs or other views with native selection, so the
  1392. * JS view can claim the responder.
  1393. *
  1394. * TODO: This shouldn't bubble.
  1395. */
  1396. selectionChangeShouldSetResponder: {
  1397. phasedRegistrationNames: {
  1398. bubbled: "onSelectionChangeShouldSetResponder",
  1399. captured: "onSelectionChangeShouldSetResponderCapture"
  1400. },
  1401. dependencies: [TOP_SELECTION_CHANGE]
  1402. },
  1403. /**
  1404. * On a `touchMove`/`mouseMove`, is it desired that this element become the
  1405. * responder?
  1406. */
  1407. moveShouldSetResponder: {
  1408. phasedRegistrationNames: {
  1409. bubbled: "onMoveShouldSetResponder",
  1410. captured: "onMoveShouldSetResponderCapture"
  1411. },
  1412. dependencies: moveDependencies
  1413. },
  1414. /**
  1415. * Direct responder events dispatched directly to responder. Do not bubble.
  1416. */
  1417. responderStart: {
  1418. registrationName: "onResponderStart",
  1419. dependencies: startDependencies
  1420. },
  1421. responderMove: {
  1422. registrationName: "onResponderMove",
  1423. dependencies: moveDependencies
  1424. },
  1425. responderEnd: {
  1426. registrationName: "onResponderEnd",
  1427. dependencies: endDependencies
  1428. },
  1429. responderRelease: {
  1430. registrationName: "onResponderRelease",
  1431. dependencies: endDependencies
  1432. },
  1433. responderTerminationRequest: {
  1434. registrationName: "onResponderTerminationRequest",
  1435. dependencies: []
  1436. },
  1437. responderGrant: {
  1438. registrationName: "onResponderGrant",
  1439. dependencies: []
  1440. },
  1441. responderReject: {
  1442. registrationName: "onResponderReject",
  1443. dependencies: []
  1444. },
  1445. responderTerminate: {
  1446. registrationName: "onResponderTerminate",
  1447. dependencies: []
  1448. }
  1449. };
  1450. /**
  1451. *
  1452. * Responder System:
  1453. * ----------------
  1454. *
  1455. * - A global, solitary "interaction lock" on a view.
  1456. * - If a node becomes the responder, it should convey visual feedback
  1457. * immediately to indicate so, either by highlighting or moving accordingly.
  1458. * - To be the responder means, that touches are exclusively important to that
  1459. * responder view, and no other view.
  1460. * - While touches are still occurring, the responder lock can be transferred to
  1461. * a new view, but only to increasingly "higher" views (meaning ancestors of
  1462. * the current responder).
  1463. *
  1464. * Responder being granted:
  1465. * ------------------------
  1466. *
  1467. * - Touch starts, moves, and scrolls can cause an ID to become the responder.
  1468. * - We capture/bubble `startShouldSetResponder`/`moveShouldSetResponder` to
  1469. * the "appropriate place".
  1470. * - If nothing is currently the responder, the "appropriate place" is the
  1471. * initiating event's `targetID`.
  1472. * - If something *is* already the responder, the "appropriate place" is the
  1473. * first common ancestor of the event target and the current `responderInst`.
  1474. * - Some negotiation happens: See the timing diagram below.
  1475. * - Scrolled views automatically become responder. The reasoning is that a
  1476. * platform scroll view that isn't built on top of the responder system has
  1477. * began scrolling, and the active responder must now be notified that the
  1478. * interaction is no longer locked to it - the system has taken over.
  1479. *
  1480. * - Responder being released:
  1481. * As soon as no more touches that *started* inside of descendants of the
  1482. * *current* responderInst, an `onResponderRelease` event is dispatched to the
  1483. * current responder, and the responder lock is released.
  1484. *
  1485. * TODO:
  1486. * - on "end", a callback hook for `onResponderEndShouldRemainResponder` that
  1487. * determines if the responder lock should remain.
  1488. * - If a view shouldn't "remain" the responder, any active touches should by
  1489. * default be considered "dead" and do not influence future negotiations or
  1490. * bubble paths. It should be as if those touches do not exist.
  1491. * -- For multitouch: Usually a translate-z will choose to "remain" responder
  1492. * after one out of many touches ended. For translate-y, usually the view
  1493. * doesn't wish to "remain" responder after one of many touches end.
  1494. * - Consider building this on top of a `stopPropagation` model similar to
  1495. * `W3C` events.
  1496. * - Ensure that `onResponderTerminate` is called on touch cancels, whether or
  1497. * not `onResponderTerminationRequest` returns `true` or `false`.
  1498. *
  1499. */
  1500. /* Negotiation Performed
  1501. +-----------------------+
  1502. / \
  1503. Process low level events to + Current Responder + wantsResponderID
  1504. determine who to perform negot-| (if any exists at all) |
  1505. iation/transition | Otherwise just pass through|
  1506. -------------------------------+----------------------------+------------------+
  1507. Bubble to find first ID | |
  1508. to return true:wantsResponderID| |
  1509. | |
  1510. +-------------+ | |
  1511. | onTouchStart| | |
  1512. +------+------+ none | |
  1513. | return| |
  1514. +-----------v-------------+true| +------------------------+ |
  1515. |onStartShouldSetResponder|----->|onResponderStart (cur) |<-----------+
  1516. +-----------+-------------+ | +------------------------+ | |
  1517. | | | +--------+-------+
  1518. | returned true for| false:REJECT +-------->|onResponderReject
  1519. | wantsResponderID | | | +----------------+
  1520. | (now attempt | +------------------+-----+ |
  1521. | handoff) | | onResponder | |
  1522. +------------------->| TerminationRequest| |
  1523. | +------------------+-----+ |
  1524. | | | +----------------+
  1525. | true:GRANT +-------->|onResponderGrant|
  1526. | | +--------+-------+
  1527. | +------------------------+ | |
  1528. | | onResponderTerminate |<-----------+
  1529. | +------------------+-----+ |
  1530. | | | +----------------+
  1531. | +-------->|onResponderStart|
  1532. | | +----------------+
  1533. Bubble to find first ID | |
  1534. to return true:wantsResponderID| |
  1535. | |
  1536. +-------------+ | |
  1537. | onTouchMove | | |
  1538. +------+------+ none | |
  1539. | return| |
  1540. +-----------v-------------+true| +------------------------+ |
  1541. |onMoveShouldSetResponder |----->|onResponderMove (cur) |<-----------+
  1542. +-----------+-------------+ | +------------------------+ | |
  1543. | | | +--------+-------+
  1544. | returned true for| false:REJECT +-------->|onResponderRejec|
  1545. | wantsResponderID | | | +----------------+
  1546. | (now attempt | +------------------+-----+ |
  1547. | handoff) | | onResponder | |
  1548. +------------------->| TerminationRequest| |
  1549. | +------------------+-----+ |
  1550. | | | +----------------+
  1551. | true:GRANT +-------->|onResponderGrant|
  1552. | | +--------+-------+
  1553. | +------------------------+ | |
  1554. | | onResponderTerminate |<-----------+
  1555. | +------------------+-----+ |
  1556. | | | +----------------+
  1557. | +-------->|onResponderMove |
  1558. | | +----------------+
  1559. | |
  1560. | |
  1561. Some active touch started| |
  1562. inside current responder | +------------------------+ |
  1563. +------------------------->| onResponderEnd | |
  1564. | | +------------------------+ |
  1565. +---+---------+ | |
  1566. | onTouchEnd | | |
  1567. +---+---------+ | |
  1568. | | +------------------------+ |
  1569. +------------------------->| onResponderEnd | |
  1570. No active touches started| +-----------+------------+ |
  1571. inside current responder | | |
  1572. | v |
  1573. | +------------------------+ |
  1574. | | onResponderRelease | |
  1575. | +------------------------+ |
  1576. | |
  1577. + + */
  1578. /**
  1579. * A note about event ordering in the `EventPluginRegistry`.
  1580. *
  1581. * Suppose plugins are injected in the following order:
  1582. *
  1583. * `[R, S, C]`
  1584. *
  1585. * To help illustrate the example, assume `S` is `SimpleEventPlugin` (for
  1586. * `onClick` etc) and `R` is `ResponderEventPlugin`.
  1587. *
  1588. * "Deferred-Dispatched Events":
  1589. *
  1590. * - The current event plugin system will traverse the list of injected plugins,
  1591. * in order, and extract events by collecting the plugin's return value of
  1592. * `extractEvents()`.
  1593. * - These events that are returned from `extractEvents` are "deferred
  1594. * dispatched events".
  1595. * - When returned from `extractEvents`, deferred-dispatched events contain an
  1596. * "accumulation" of deferred dispatches.
  1597. * - These deferred dispatches are accumulated/collected before they are
  1598. * returned, but processed at a later time by the `EventPluginRegistry` (hence the
  1599. * name deferred).
  1600. *
  1601. * In the process of returning their deferred-dispatched events, event plugins
  1602. * themselves can dispatch events on-demand without returning them from
  1603. * `extractEvents`. Plugins might want to do this, so that they can use event
  1604. * dispatching as a tool that helps them decide which events should be extracted
  1605. * in the first place.
  1606. *
  1607. * "On-Demand-Dispatched Events":
  1608. *
  1609. * - On-demand-dispatched events are not returned from `extractEvents`.
  1610. * - On-demand-dispatched events are dispatched during the process of returning
  1611. * the deferred-dispatched events.
  1612. * - They should not have side effects.
  1613. * - They should be avoided, and/or eventually be replaced with another
  1614. * abstraction that allows event plugins to perform multiple "rounds" of event
  1615. * extraction.
  1616. *
  1617. * Therefore, the sequence of event dispatches becomes:
  1618. *
  1619. * - `R`s on-demand events (if any) (dispatched by `R` on-demand)
  1620. * - `S`s on-demand events (if any) (dispatched by `S` on-demand)
  1621. * - `C`s on-demand events (if any) (dispatched by `C` on-demand)
  1622. * - `R`s extracted events (if any) (dispatched by `EventPluginRegistry`)
  1623. * - `S`s extracted events (if any) (dispatched by `EventPluginRegistry`)
  1624. * - `C`s extracted events (if any) (dispatched by `EventPluginRegistry`)
  1625. *
  1626. * In the case of `ResponderEventPlugin`: If the `startShouldSetResponder`
  1627. * on-demand dispatch returns `true` (and some other details are satisfied) the
  1628. * `onResponderGrant` deferred dispatched event is returned from
  1629. * `extractEvents`. The sequence of dispatch executions in this case
  1630. * will appear as follows:
  1631. *
  1632. * - `startShouldSetResponder` (`ResponderEventPlugin` dispatches on-demand)
  1633. * - `touchStartCapture` (`EventPluginRegistry` dispatches as usual)
  1634. * - `touchStart` (`EventPluginRegistry` dispatches as usual)
  1635. * - `responderGrant/Reject` (`EventPluginRegistry` dispatches as usual)
  1636. */
  1637. function setResponderAndExtractTransfer(
  1638. topLevelType,
  1639. targetInst,
  1640. nativeEvent,
  1641. nativeEventTarget
  1642. ) {
  1643. var shouldSetEventType = isStartish(topLevelType)
  1644. ? eventTypes.startShouldSetResponder
  1645. : isMoveish(topLevelType)
  1646. ? eventTypes.moveShouldSetResponder
  1647. : topLevelType === TOP_SELECTION_CHANGE
  1648. ? eventTypes.selectionChangeShouldSetResponder
  1649. : eventTypes.scrollShouldSetResponder; // TODO: stop one short of the current responder.
  1650. var bubbleShouldSetFrom = !responderInst
  1651. ? targetInst
  1652. : getLowestCommonAncestor(responderInst, targetInst); // When capturing/bubbling the "shouldSet" event, we want to skip the target
  1653. // (deepest ID) if it happens to be the current responder. The reasoning:
  1654. // It's strange to get an `onMoveShouldSetResponder` when you're *already*
  1655. // the responder.
  1656. var skipOverBubbleShouldSetFrom = bubbleShouldSetFrom === responderInst;
  1657. var shouldSetEvent = ResponderSyntheticEvent.getPooled(
  1658. shouldSetEventType,
  1659. bubbleShouldSetFrom,
  1660. nativeEvent,
  1661. nativeEventTarget
  1662. );
  1663. shouldSetEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1664. if (skipOverBubbleShouldSetFrom) {
  1665. accumulateTwoPhaseDispatchesSkipTarget(shouldSetEvent);
  1666. } else {
  1667. accumulateTwoPhaseDispatches(shouldSetEvent);
  1668. }
  1669. var wantsResponderInst = executeDispatchesInOrderStopAtTrue(shouldSetEvent);
  1670. if (!shouldSetEvent.isPersistent()) {
  1671. shouldSetEvent.constructor.release(shouldSetEvent);
  1672. }
  1673. if (!wantsResponderInst || wantsResponderInst === responderInst) {
  1674. return null;
  1675. }
  1676. var extracted;
  1677. var grantEvent = ResponderSyntheticEvent.getPooled(
  1678. eventTypes.responderGrant,
  1679. wantsResponderInst,
  1680. nativeEvent,
  1681. nativeEventTarget
  1682. );
  1683. grantEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1684. accumulateDirectDispatches(grantEvent);
  1685. var blockHostResponder = executeDirectDispatch(grantEvent) === true;
  1686. if (responderInst) {
  1687. var terminationRequestEvent = ResponderSyntheticEvent.getPooled(
  1688. eventTypes.responderTerminationRequest,
  1689. responderInst,
  1690. nativeEvent,
  1691. nativeEventTarget
  1692. );
  1693. terminationRequestEvent.touchHistory =
  1694. ResponderTouchHistoryStore.touchHistory;
  1695. accumulateDirectDispatches(terminationRequestEvent);
  1696. var shouldSwitch =
  1697. !hasDispatches(terminationRequestEvent) ||
  1698. executeDirectDispatch(terminationRequestEvent);
  1699. if (!terminationRequestEvent.isPersistent()) {
  1700. terminationRequestEvent.constructor.release(terminationRequestEvent);
  1701. }
  1702. if (shouldSwitch) {
  1703. var terminateEvent = ResponderSyntheticEvent.getPooled(
  1704. eventTypes.responderTerminate,
  1705. responderInst,
  1706. nativeEvent,
  1707. nativeEventTarget
  1708. );
  1709. terminateEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1710. accumulateDirectDispatches(terminateEvent);
  1711. extracted = accumulate(extracted, [grantEvent, terminateEvent]);
  1712. changeResponder(wantsResponderInst, blockHostResponder);
  1713. } else {
  1714. var rejectEvent = ResponderSyntheticEvent.getPooled(
  1715. eventTypes.responderReject,
  1716. wantsResponderInst,
  1717. nativeEvent,
  1718. nativeEventTarget
  1719. );
  1720. rejectEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1721. accumulateDirectDispatches(rejectEvent);
  1722. extracted = accumulate(extracted, rejectEvent);
  1723. }
  1724. } else {
  1725. extracted = accumulate(extracted, grantEvent);
  1726. changeResponder(wantsResponderInst, blockHostResponder);
  1727. }
  1728. return extracted;
  1729. }
  1730. /**
  1731. * A transfer is a negotiation between a currently set responder and the next
  1732. * element to claim responder status. Any start event could trigger a transfer
  1733. * of responderInst. Any move event could trigger a transfer.
  1734. *
  1735. * @param {string} topLevelType Record from `BrowserEventConstants`.
  1736. * @return {boolean} True if a transfer of responder could possibly occur.
  1737. */
  1738. function canTriggerTransfer(topLevelType, topLevelInst, nativeEvent) {
  1739. return (
  1740. topLevelInst && // responderIgnoreScroll: We are trying to migrate away from specifically
  1741. // tracking native scroll events here and responderIgnoreScroll indicates we
  1742. // will send topTouchCancel to handle canceling touch events instead
  1743. ((topLevelType === TOP_SCROLL && !nativeEvent.responderIgnoreScroll) ||
  1744. (trackedTouchCount > 0 && topLevelType === TOP_SELECTION_CHANGE) ||
  1745. isStartish(topLevelType) ||
  1746. isMoveish(topLevelType))
  1747. );
  1748. }
  1749. /**
  1750. * Returns whether or not this touch end event makes it such that there are no
  1751. * longer any touches that started inside of the current `responderInst`.
  1752. *
  1753. * @param {NativeEvent} nativeEvent Native touch end event.
  1754. * @return {boolean} Whether or not this touch end event ends the responder.
  1755. */
  1756. function noResponderTouches(nativeEvent) {
  1757. var touches = nativeEvent.touches;
  1758. if (!touches || touches.length === 0) {
  1759. return true;
  1760. }
  1761. for (var i = 0; i < touches.length; i++) {
  1762. var activeTouch = touches[i];
  1763. var target = activeTouch.target;
  1764. if (target !== null && target !== undefined && target !== 0) {
  1765. // Is the original touch location inside of the current responder?
  1766. var targetInst = getInstanceFromNode(target);
  1767. if (isAncestor(responderInst, targetInst)) {
  1768. return false;
  1769. }
  1770. }
  1771. }
  1772. return true;
  1773. }
  1774. var ResponderEventPlugin = {
  1775. /* For unit testing only */
  1776. _getResponder: function() {
  1777. return responderInst;
  1778. },
  1779. eventTypes: eventTypes,
  1780. /**
  1781. * We must be resilient to `targetInst` being `null` on `touchMove` or
  1782. * `touchEnd`. On certain platforms, this means that a native scroll has
  1783. * assumed control and the original touch targets are destroyed.
  1784. */
  1785. extractEvents: function(
  1786. topLevelType,
  1787. targetInst,
  1788. nativeEvent,
  1789. nativeEventTarget,
  1790. eventSystemFlags
  1791. ) {
  1792. if (isStartish(topLevelType)) {
  1793. trackedTouchCount += 1;
  1794. } else if (isEndish(topLevelType)) {
  1795. if (trackedTouchCount >= 0) {
  1796. trackedTouchCount -= 1;
  1797. } else {
  1798. {
  1799. warn(
  1800. "Ended a touch event which was not counted in `trackedTouchCount`."
  1801. );
  1802. }
  1803. return null;
  1804. }
  1805. }
  1806. ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent);
  1807. var extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent)
  1808. ? setResponderAndExtractTransfer(
  1809. topLevelType,
  1810. targetInst,
  1811. nativeEvent,
  1812. nativeEventTarget
  1813. )
  1814. : null; // Responder may or may not have transferred on a new touch start/move.
  1815. // Regardless, whoever is the responder after any potential transfer, we
  1816. // direct all touch start/move/ends to them in the form of
  1817. // `onResponderMove/Start/End`. These will be called for *every* additional
  1818. // finger that move/start/end, dispatched directly to whoever is the
  1819. // current responder at that moment, until the responder is "released".
  1820. //
  1821. // These multiple individual change touch events are are always bookended
  1822. // by `onResponderGrant`, and one of
  1823. // (`onResponderRelease/onResponderTerminate`).
  1824. var isResponderTouchStart = responderInst && isStartish(topLevelType);
  1825. var isResponderTouchMove = responderInst && isMoveish(topLevelType);
  1826. var isResponderTouchEnd = responderInst && isEndish(topLevelType);
  1827. var incrementalTouch = isResponderTouchStart
  1828. ? eventTypes.responderStart
  1829. : isResponderTouchMove
  1830. ? eventTypes.responderMove
  1831. : isResponderTouchEnd
  1832. ? eventTypes.responderEnd
  1833. : null;
  1834. if (incrementalTouch) {
  1835. var gesture = ResponderSyntheticEvent.getPooled(
  1836. incrementalTouch,
  1837. responderInst,
  1838. nativeEvent,
  1839. nativeEventTarget
  1840. );
  1841. gesture.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1842. accumulateDirectDispatches(gesture);
  1843. extracted = accumulate(extracted, gesture);
  1844. }
  1845. var isResponderTerminate =
  1846. responderInst && topLevelType === TOP_TOUCH_CANCEL;
  1847. var isResponderRelease =
  1848. responderInst &&
  1849. !isResponderTerminate &&
  1850. isEndish(topLevelType) &&
  1851. noResponderTouches(nativeEvent);
  1852. var finalTouch = isResponderTerminate
  1853. ? eventTypes.responderTerminate
  1854. : isResponderRelease
  1855. ? eventTypes.responderRelease
  1856. : null;
  1857. if (finalTouch) {
  1858. var finalEvent = ResponderSyntheticEvent.getPooled(
  1859. finalTouch,
  1860. responderInst,
  1861. nativeEvent,
  1862. nativeEventTarget
  1863. );
  1864. finalEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1865. accumulateDirectDispatches(finalEvent);
  1866. extracted = accumulate(extracted, finalEvent);
  1867. changeResponder(null);
  1868. }
  1869. return extracted;
  1870. },
  1871. GlobalResponderHandler: null,
  1872. injection: {
  1873. /**
  1874. * @param {{onChange: (ReactID, ReactID) => void} GlobalResponderHandler
  1875. * Object that handles any change in responder. Use this to inject
  1876. * integration with an existing touch handling system etc.
  1877. */
  1878. injectGlobalResponderHandler: function(GlobalResponderHandler) {
  1879. ResponderEventPlugin.GlobalResponderHandler = GlobalResponderHandler;
  1880. }
  1881. }
  1882. };
  1883. /**
  1884. * Injectable ordering of event plugins.
  1885. */
  1886. var eventPluginOrder = null;
  1887. /**
  1888. * Injectable mapping from names to event plugin modules.
  1889. */
  1890. var namesToPlugins = {};
  1891. /**
  1892. * Recomputes the plugin list using the injected plugins and plugin ordering.
  1893. *
  1894. * @private
  1895. */
  1896. function recomputePluginOrdering() {
  1897. if (!eventPluginOrder) {
  1898. // Wait until an `eventPluginOrder` is injected.
  1899. return;
  1900. }
  1901. for (var pluginName in namesToPlugins) {
  1902. var pluginModule = namesToPlugins[pluginName];
  1903. var pluginIndex = eventPluginOrder.indexOf(pluginName);
  1904. if (!(pluginIndex > -1)) {
  1905. throw Error(
  1906. "EventPluginRegistry: Cannot inject event plugins that do not exist in the plugin ordering, `" +
  1907. pluginName +
  1908. "`."
  1909. );
  1910. }
  1911. if (plugins[pluginIndex]) {
  1912. continue;
  1913. }
  1914. if (!pluginModule.extractEvents) {
  1915. throw Error(
  1916. "EventPluginRegistry: Event plugins must implement an `extractEvents` method, but `" +
  1917. pluginName +
  1918. "` does not."
  1919. );
  1920. }
  1921. plugins[pluginIndex] = pluginModule;
  1922. var publishedEvents = pluginModule.eventTypes;
  1923. for (var eventName in publishedEvents) {
  1924. if (
  1925. !publishEventForPlugin(
  1926. publishedEvents[eventName],
  1927. pluginModule,
  1928. eventName
  1929. )
  1930. ) {
  1931. throw Error(
  1932. "EventPluginRegistry: Failed to publish event `" +
  1933. eventName +
  1934. "` for plugin `" +
  1935. pluginName +
  1936. "`."
  1937. );
  1938. }
  1939. }
  1940. }
  1941. }
  1942. /**
  1943. * Publishes an event so that it can be dispatched by the supplied plugin.
  1944. *
  1945. * @param {object} dispatchConfig Dispatch configuration for the event.
  1946. * @param {object} PluginModule Plugin publishing the event.
  1947. * @return {boolean} True if the event was successfully published.
  1948. * @private
  1949. */
  1950. function publishEventForPlugin(dispatchConfig, pluginModule, eventName) {
  1951. if (!!eventNameDispatchConfigs.hasOwnProperty(eventName)) {
  1952. throw Error(
  1953. "EventPluginRegistry: More than one plugin attempted to publish the same event name, `" +
  1954. eventName +
  1955. "`."
  1956. );
  1957. }
  1958. eventNameDispatchConfigs[eventName] = dispatchConfig;
  1959. var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
  1960. if (phasedRegistrationNames) {
  1961. for (var phaseName in phasedRegistrationNames) {
  1962. if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
  1963. var phasedRegistrationName = phasedRegistrationNames[phaseName];
  1964. publishRegistrationName(
  1965. phasedRegistrationName,
  1966. pluginModule,
  1967. eventName
  1968. );
  1969. }
  1970. }
  1971. return true;
  1972. } else if (dispatchConfig.registrationName) {
  1973. publishRegistrationName(
  1974. dispatchConfig.registrationName,
  1975. pluginModule,
  1976. eventName
  1977. );
  1978. return true;
  1979. }
  1980. return false;
  1981. }
  1982. /**
  1983. * Publishes a registration name that is used to identify dispatched events.
  1984. *
  1985. * @param {string} registrationName Registration name to add.
  1986. * @param {object} PluginModule Plugin publishing the event.
  1987. * @private
  1988. */
  1989. function publishRegistrationName(registrationName, pluginModule, eventName) {
  1990. if (!!registrationNameModules[registrationName]) {
  1991. throw Error(
  1992. "EventPluginRegistry: More than one plugin attempted to publish the same registration name, `" +
  1993. registrationName +
  1994. "`."
  1995. );
  1996. }
  1997. registrationNameModules[registrationName] = pluginModule;
  1998. registrationNameDependencies[registrationName] =
  1999. pluginModule.eventTypes[eventName].dependencies;
  2000. {
  2001. var lowerCasedName = registrationName.toLowerCase();
  2002. }
  2003. }
  2004. /**
  2005. * Registers plugins so that they can extract and dispatch events.
  2006. */
  2007. /**
  2008. * Ordered list of injected plugins.
  2009. */
  2010. var plugins = [];
  2011. /**
  2012. * Mapping from event name to dispatch config
  2013. */
  2014. var eventNameDispatchConfigs = {};
  2015. /**
  2016. * Mapping from registration name to plugin module
  2017. */
  2018. var registrationNameModules = {};
  2019. /**
  2020. * Mapping from registration name to event name
  2021. */
  2022. var registrationNameDependencies = {};
  2023. /**
  2024. * Injects an ordering of plugins (by plugin name). This allows the ordering
  2025. * to be decoupled from injection of the actual plugins so that ordering is
  2026. * always deterministic regardless of packaging, on-the-fly injection, etc.
  2027. *
  2028. * @param {array} InjectedEventPluginOrder
  2029. * @internal
  2030. */
  2031. function injectEventPluginOrder(injectedEventPluginOrder) {
  2032. if (!!eventPluginOrder) {
  2033. throw Error(
  2034. "EventPluginRegistry: Cannot inject event plugin ordering more than once. You are likely trying to load more than one copy of React."
  2035. );
  2036. } // Clone the ordering so it cannot be dynamically mutated.
  2037. eventPluginOrder = Array.prototype.slice.call(injectedEventPluginOrder);
  2038. recomputePluginOrdering();
  2039. }
  2040. /**
  2041. * Injects plugins to be used by plugin event system. The plugin names must be
  2042. * in the ordering injected by `injectEventPluginOrder`.
  2043. *
  2044. * Plugins can be injected as part of page initialization or on-the-fly.
  2045. *
  2046. * @param {object} injectedNamesToPlugins Map from names to plugin modules.
  2047. * @internal
  2048. */
  2049. function injectEventPluginsByName(injectedNamesToPlugins) {
  2050. var isOrderingDirty = false;
  2051. for (var pluginName in injectedNamesToPlugins) {
  2052. if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
  2053. continue;
  2054. }
  2055. var pluginModule = injectedNamesToPlugins[pluginName];
  2056. if (
  2057. !namesToPlugins.hasOwnProperty(pluginName) ||
  2058. namesToPlugins[pluginName] !== pluginModule
  2059. ) {
  2060. if (!!namesToPlugins[pluginName]) {
  2061. throw Error(
  2062. "EventPluginRegistry: Cannot inject two different event plugins using the same name, `" +
  2063. pluginName +
  2064. "`."
  2065. );
  2066. }
  2067. namesToPlugins[pluginName] = pluginModule;
  2068. isOrderingDirty = true;
  2069. }
  2070. }
  2071. if (isOrderingDirty) {
  2072. recomputePluginOrdering();
  2073. }
  2074. }
  2075. var customBubblingEventTypes =
  2076. ReactNativePrivateInterface.ReactNativeViewConfigRegistry
  2077. .customBubblingEventTypes,
  2078. customDirectEventTypes =
  2079. ReactNativePrivateInterface.ReactNativeViewConfigRegistry
  2080. .customDirectEventTypes;
  2081. var ReactNativeBridgeEventPlugin = {
  2082. eventTypes: {},
  2083. extractEvents: function(
  2084. topLevelType,
  2085. targetInst,
  2086. nativeEvent,
  2087. nativeEventTarget,
  2088. eventSystemFlags
  2089. ) {
  2090. if (targetInst == null) {
  2091. // Probably a node belonging to another renderer's tree.
  2092. return null;
  2093. }
  2094. var bubbleDispatchConfig = customBubblingEventTypes[topLevelType];
  2095. var directDispatchConfig = customDirectEventTypes[topLevelType];
  2096. if (!(bubbleDispatchConfig || directDispatchConfig)) {
  2097. throw Error(
  2098. 'Unsupported top level event type "' + topLevelType + '" dispatched'
  2099. );
  2100. }
  2101. var event = SyntheticEvent.getPooled(
  2102. bubbleDispatchConfig || directDispatchConfig,
  2103. targetInst,
  2104. nativeEvent,
  2105. nativeEventTarget
  2106. );
  2107. if (bubbleDispatchConfig) {
  2108. accumulateTwoPhaseDispatches(event);
  2109. } else if (directDispatchConfig) {
  2110. accumulateDirectDispatches(event);
  2111. } else {
  2112. return null;
  2113. }
  2114. return event;
  2115. }
  2116. };
  2117. var ReactNativeEventPluginOrder = [
  2118. "ResponderEventPlugin",
  2119. "ReactNativeBridgeEventPlugin"
  2120. ];
  2121. /**
  2122. * Make sure essential globals are available and are patched correctly. Please don't remove this
  2123. * line. Bundles created by react-packager `require` it before executing any application code. This
  2124. * ensures it exists in the dependency graph and can be `require`d.
  2125. * TODO: require this in packager, not in React #10932517
  2126. */
  2127. /**
  2128. * Inject module for resolving DOM hierarchy and plugin ordering.
  2129. */
  2130. injectEventPluginOrder(ReactNativeEventPluginOrder);
  2131. /**
  2132. * Some important event plugins included by default (without having to require
  2133. * them).
  2134. */
  2135. injectEventPluginsByName({
  2136. ResponderEventPlugin: ResponderEventPlugin,
  2137. ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin
  2138. });
  2139. function getInstanceFromInstance(instanceHandle) {
  2140. return instanceHandle;
  2141. }
  2142. function getTagFromInstance(inst) {
  2143. var nativeInstance = inst.stateNode.canonical;
  2144. if (!nativeInstance._nativeTag) {
  2145. throw Error("All native instances should have a tag.");
  2146. }
  2147. return nativeInstance;
  2148. }
  2149. function getFiberCurrentPropsFromNode$1(inst) {
  2150. return inst.canonical.currentProps;
  2151. }
  2152. // Module provided by RN:
  2153. var ReactFabricGlobalResponderHandler = {
  2154. onChange: function(from, to, blockNativeResponder) {
  2155. if (to !== null) {
  2156. var tag = to.stateNode.canonical._nativeTag;
  2157. ReactNativePrivateInterface.UIManager.setJSResponder(
  2158. tag,
  2159. blockNativeResponder
  2160. );
  2161. } else {
  2162. ReactNativePrivateInterface.UIManager.clearJSResponder();
  2163. }
  2164. }
  2165. };
  2166. setComponentTree(
  2167. getFiberCurrentPropsFromNode$1,
  2168. getInstanceFromInstance,
  2169. getTagFromInstance
  2170. );
  2171. ResponderEventPlugin.injection.injectGlobalResponderHandler(
  2172. ReactFabricGlobalResponderHandler
  2173. );
  2174. /**
  2175. * `ReactInstanceMap` maintains a mapping from a public facing stateful
  2176. * instance (key) and the internal representation (value). This allows public
  2177. * methods to accept the user facing instance as an argument and map them back
  2178. * to internal methods.
  2179. *
  2180. * Note that this module is currently shared and assumed to be stateless.
  2181. * If this becomes an actual Map, that will break.
  2182. */
  2183. function get(key) {
  2184. return key._reactInternalFiber;
  2185. }
  2186. function set(key, value) {
  2187. key._reactInternalFiber = value;
  2188. }
  2189. // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
  2190. // nor polyfill, then a plain number is used for performance.
  2191. var hasSymbol = typeof Symbol === "function" && Symbol.for;
  2192. var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for("react.element") : 0xeac7;
  2193. var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for("react.portal") : 0xeaca;
  2194. var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for("react.fragment") : 0xeacb;
  2195. var REACT_STRICT_MODE_TYPE = hasSymbol
  2196. ? Symbol.for("react.strict_mode")
  2197. : 0xeacc;
  2198. var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for("react.profiler") : 0xead2;
  2199. var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for("react.provider") : 0xeacd;
  2200. var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for("react.context") : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
  2201. var REACT_CONCURRENT_MODE_TYPE = hasSymbol
  2202. ? Symbol.for("react.concurrent_mode")
  2203. : 0xeacf;
  2204. var REACT_FORWARD_REF_TYPE = hasSymbol
  2205. ? Symbol.for("react.forward_ref")
  2206. : 0xead0;
  2207. var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for("react.suspense") : 0xead1;
  2208. var REACT_SUSPENSE_LIST_TYPE = hasSymbol
  2209. ? Symbol.for("react.suspense_list")
  2210. : 0xead8;
  2211. var REACT_MEMO_TYPE = hasSymbol ? Symbol.for("react.memo") : 0xead3;
  2212. var REACT_LAZY_TYPE = hasSymbol ? Symbol.for("react.lazy") : 0xead4;
  2213. var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for("react.block") : 0xead9;
  2214. var MAYBE_ITERATOR_SYMBOL = typeof Symbol === "function" && Symbol.iterator;
  2215. var FAUX_ITERATOR_SYMBOL = "@@iterator";
  2216. function getIteratorFn(maybeIterable) {
  2217. if (maybeIterable === null || typeof maybeIterable !== "object") {
  2218. return null;
  2219. }
  2220. var maybeIterator =
  2221. (MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL]) ||
  2222. maybeIterable[FAUX_ITERATOR_SYMBOL];
  2223. if (typeof maybeIterator === "function") {
  2224. return maybeIterator;
  2225. }
  2226. return null;
  2227. }
  2228. // TODO: Move this to "react" once we can import from externals.
  2229. var Uninitialized = -1;
  2230. var Pending = 0;
  2231. var Resolved = 1;
  2232. var Rejected = 2;
  2233. function refineResolvedLazyComponent(lazyComponent) {
  2234. return lazyComponent._status === Resolved ? lazyComponent._result : null;
  2235. }
  2236. function initializeLazyComponentType(lazyComponent) {
  2237. if (lazyComponent._status === Uninitialized) {
  2238. var ctor = lazyComponent._result;
  2239. if (!ctor) {
  2240. // TODO: Remove this later. THis only exists in case you use an older "react" package.
  2241. ctor = lazyComponent._ctor;
  2242. }
  2243. var thenable = ctor(); // Transition to the next state.
  2244. var pending = lazyComponent;
  2245. pending._status = Pending;
  2246. pending._result = thenable;
  2247. thenable.then(
  2248. function(moduleObject) {
  2249. if (lazyComponent._status === Pending) {
  2250. var defaultExport = moduleObject.default;
  2251. {
  2252. if (defaultExport === undefined) {
  2253. error(
  2254. "lazy: Expected the result of a dynamic import() call. " +
  2255. "Instead received: %s\n\nYour code should look like: \n " + // Break up imports to avoid accidentally parsing them as dependencies.
  2256. "const MyComponent = lazy(() => imp" +
  2257. "ort('./MyComponent'))",
  2258. moduleObject
  2259. );
  2260. }
  2261. } // Transition to the next state.
  2262. var resolved = lazyComponent;
  2263. resolved._status = Resolved;
  2264. resolved._result = defaultExport;
  2265. }
  2266. },
  2267. function(error) {
  2268. if (lazyComponent._status === Pending) {
  2269. // Transition to the next state.
  2270. var rejected = lazyComponent;
  2271. rejected._status = Rejected;
  2272. rejected._result = error;
  2273. }
  2274. }
  2275. );
  2276. }
  2277. }
  2278. function getWrappedName(outerType, innerType, wrapperName) {
  2279. var functionName = innerType.displayName || innerType.name || "";
  2280. return (
  2281. outerType.displayName ||
  2282. (functionName !== "" ? wrapperName + "(" + functionName + ")" : wrapperName)
  2283. );
  2284. }
  2285. function getContextName(type) {
  2286. return type.displayName || "Context";
  2287. }
  2288. function getComponentName(type) {
  2289. if (type == null) {
  2290. // Host root, text node or just invalid type.
  2291. return null;
  2292. }
  2293. {
  2294. if (typeof type.tag === "number") {
  2295. error(
  2296. "Received an unexpected object in getComponentName(). " +
  2297. "This is likely a bug in React. Please file an issue."
  2298. );
  2299. }
  2300. }
  2301. if (typeof type === "function") {
  2302. return type.displayName || type.name || null;
  2303. }
  2304. if (typeof type === "string") {
  2305. return type;
  2306. }
  2307. switch (type) {
  2308. case REACT_FRAGMENT_TYPE:
  2309. return "Fragment";
  2310. case REACT_PORTAL_TYPE:
  2311. return "Portal";
  2312. case REACT_PROFILER_TYPE:
  2313. return "Profiler";
  2314. case REACT_STRICT_MODE_TYPE:
  2315. return "StrictMode";
  2316. case REACT_SUSPENSE_TYPE:
  2317. return "Suspense";
  2318. case REACT_SUSPENSE_LIST_TYPE:
  2319. return "SuspenseList";
  2320. }
  2321. if (typeof type === "object") {
  2322. switch (type.$$typeof) {
  2323. case REACT_CONTEXT_TYPE:
  2324. var context = type;
  2325. return getContextName(context) + ".Consumer";
  2326. case REACT_PROVIDER_TYPE:
  2327. var provider = type;
  2328. return getContextName(provider._context) + ".Provider";
  2329. case REACT_FORWARD_REF_TYPE:
  2330. return getWrappedName(type, type.render, "ForwardRef");
  2331. case REACT_MEMO_TYPE:
  2332. return getComponentName(type.type);
  2333. case REACT_BLOCK_TYPE:
  2334. return getComponentName(type.render);
  2335. case REACT_LAZY_TYPE: {
  2336. var thenable = type;
  2337. var resolvedThenable = refineResolvedLazyComponent(thenable);
  2338. if (resolvedThenable) {
  2339. return getComponentName(resolvedThenable);
  2340. }
  2341. break;
  2342. }
  2343. }
  2344. }
  2345. return null;
  2346. }
  2347. // Don't change these two values. They're used by React Dev Tools.
  2348. var NoEffect =
  2349. /* */
  2350. 0;
  2351. var PerformedWork =
  2352. /* */
  2353. 1; // You can change the rest (and add more).
  2354. var Placement =
  2355. /* */
  2356. 2;
  2357. var Update =
  2358. /* */
  2359. 4;
  2360. var PlacementAndUpdate =
  2361. /* */
  2362. 6;
  2363. var Deletion =
  2364. /* */
  2365. 8;
  2366. var ContentReset =
  2367. /* */
  2368. 16;
  2369. var Callback =
  2370. /* */
  2371. 32;
  2372. var DidCapture =
  2373. /* */
  2374. 64;
  2375. var Ref =
  2376. /* */
  2377. 128;
  2378. var Snapshot =
  2379. /* */
  2380. 256;
  2381. var Passive =
  2382. /* */
  2383. 512;
  2384. var Hydrating =
  2385. /* */
  2386. 1024;
  2387. var HydratingAndUpdate =
  2388. /* */
  2389. 1028; // Passive & Update & Callback & Ref & Snapshot
  2390. var LifecycleEffectMask =
  2391. /* */
  2392. 932; // Union of all host effects
  2393. var HostEffectMask =
  2394. /* */
  2395. 2047;
  2396. var Incomplete =
  2397. /* */
  2398. 2048;
  2399. var ShouldCapture =
  2400. /* */
  2401. 4096;
  2402. var enableProfilerTimer = true;
  2403. var warnAboutStringRefs = false;
  2404. var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
  2405. function getNearestMountedFiber(fiber) {
  2406. var node = fiber;
  2407. var nearestMounted = fiber;
  2408. if (!fiber.alternate) {
  2409. // If there is no alternate, this might be a new tree that isn't inserted
  2410. // yet. If it is, then it will have a pending insertion effect on it.
  2411. var nextNode = node;
  2412. do {
  2413. node = nextNode;
  2414. if ((node.effectTag & (Placement | Hydrating)) !== NoEffect) {
  2415. // This is an insertion or in-progress hydration. The nearest possible
  2416. // mounted fiber is the parent but we need to continue to figure out
  2417. // if that one is still mounted.
  2418. nearestMounted = node.return;
  2419. }
  2420. nextNode = node.return;
  2421. } while (nextNode);
  2422. } else {
  2423. while (node.return) {
  2424. node = node.return;
  2425. }
  2426. }
  2427. if (node.tag === HostRoot) {
  2428. // TODO: Check if this was a nested HostRoot when used with
  2429. // renderContainerIntoSubtree.
  2430. return nearestMounted;
  2431. } // If we didn't hit the root, that means that we're in an disconnected tree
  2432. // that has been unmounted.
  2433. return null;
  2434. }
  2435. function isFiberMounted(fiber) {
  2436. return getNearestMountedFiber(fiber) === fiber;
  2437. }
  2438. function isMounted(component) {
  2439. {
  2440. var owner = ReactCurrentOwner.current;
  2441. if (owner !== null && owner.tag === ClassComponent) {
  2442. var ownerFiber = owner;
  2443. var instance = ownerFiber.stateNode;
  2444. if (!instance._warnedAboutRefsInRender) {
  2445. error(
  2446. "%s is accessing isMounted inside its render() function. " +
  2447. "render() should be a pure function of props and state. It should " +
  2448. "never access something that requires stale data from the previous " +
  2449. "render, such as refs. Move this logic to componentDidMount and " +
  2450. "componentDidUpdate instead.",
  2451. getComponentName(ownerFiber.type) || "A component"
  2452. );
  2453. }
  2454. instance._warnedAboutRefsInRender = true;
  2455. }
  2456. }
  2457. var fiber = get(component);
  2458. if (!fiber) {
  2459. return false;
  2460. }
  2461. return getNearestMountedFiber(fiber) === fiber;
  2462. }
  2463. function assertIsMounted(fiber) {
  2464. if (!(getNearestMountedFiber(fiber) === fiber)) {
  2465. throw Error("Unable to find node on an unmounted component.");
  2466. }
  2467. }
  2468. function findCurrentFiberUsingSlowPath(fiber) {
  2469. var alternate = fiber.alternate;
  2470. if (!alternate) {
  2471. // If there is no alternate, then we only need to check if it is mounted.
  2472. var nearestMounted = getNearestMountedFiber(fiber);
  2473. if (!(nearestMounted !== null)) {
  2474. throw Error("Unable to find node on an unmounted component.");
  2475. }
  2476. if (nearestMounted !== fiber) {
  2477. return null;
  2478. }
  2479. return fiber;
  2480. } // If we have two possible branches, we'll walk backwards up to the root
  2481. // to see what path the root points to. On the way we may hit one of the
  2482. // special cases and we'll deal with them.
  2483. var a = fiber;
  2484. var b = alternate;
  2485. while (true) {
  2486. var parentA = a.return;
  2487. if (parentA === null) {
  2488. // We're at the root.
  2489. break;
  2490. }
  2491. var parentB = parentA.alternate;
  2492. if (parentB === null) {
  2493. // There is no alternate. This is an unusual case. Currently, it only
  2494. // happens when a Suspense component is hidden. An extra fragment fiber
  2495. // is inserted in between the Suspense fiber and its children. Skip
  2496. // over this extra fragment fiber and proceed to the next parent.
  2497. var nextParent = parentA.return;
  2498. if (nextParent !== null) {
  2499. a = b = nextParent;
  2500. continue;
  2501. } // If there's no parent, we're at the root.
  2502. break;
  2503. } // If both copies of the parent fiber point to the same child, we can
  2504. // assume that the child is current. This happens when we bailout on low
  2505. // priority: the bailed out fiber's child reuses the current child.
  2506. if (parentA.child === parentB.child) {
  2507. var child = parentA.child;
  2508. while (child) {
  2509. if (child === a) {
  2510. // We've determined that A is the current branch.
  2511. assertIsMounted(parentA);
  2512. return fiber;
  2513. }
  2514. if (child === b) {
  2515. // We've determined that B is the current branch.
  2516. assertIsMounted(parentA);
  2517. return alternate;
  2518. }
  2519. child = child.sibling;
  2520. } // We should never have an alternate for any mounting node. So the only
  2521. // way this could possibly happen is if this was unmounted, if at all.
  2522. {
  2523. throw Error("Unable to find node on an unmounted component.");
  2524. }
  2525. }
  2526. if (a.return !== b.return) {
  2527. // The return pointer of A and the return pointer of B point to different
  2528. // fibers. We assume that return pointers never criss-cross, so A must
  2529. // belong to the child set of A.return, and B must belong to the child
  2530. // set of B.return.
  2531. a = parentA;
  2532. b = parentB;
  2533. } else {
  2534. // The return pointers point to the same fiber. We'll have to use the
  2535. // default, slow path: scan the child sets of each parent alternate to see
  2536. // which child belongs to which set.
  2537. //
  2538. // Search parent A's child set
  2539. var didFindChild = false;
  2540. var _child = parentA.child;
  2541. while (_child) {
  2542. if (_child === a) {
  2543. didFindChild = true;
  2544. a = parentA;
  2545. b = parentB;
  2546. break;
  2547. }
  2548. if (_child === b) {
  2549. didFindChild = true;
  2550. b = parentA;
  2551. a = parentB;
  2552. break;
  2553. }
  2554. _child = _child.sibling;
  2555. }
  2556. if (!didFindChild) {
  2557. // Search parent B's child set
  2558. _child = parentB.child;
  2559. while (_child) {
  2560. if (_child === a) {
  2561. didFindChild = true;
  2562. a = parentB;
  2563. b = parentA;
  2564. break;
  2565. }
  2566. if (_child === b) {
  2567. didFindChild = true;
  2568. b = parentB;
  2569. a = parentA;
  2570. break;
  2571. }
  2572. _child = _child.sibling;
  2573. }
  2574. if (!didFindChild) {
  2575. throw Error(
  2576. "Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue."
  2577. );
  2578. }
  2579. }
  2580. }
  2581. if (!(a.alternate === b)) {
  2582. throw Error(
  2583. "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue."
  2584. );
  2585. }
  2586. } // If the root is not a host container, we're in a disconnected tree. I.e.
  2587. // unmounted.
  2588. if (!(a.tag === HostRoot)) {
  2589. throw Error("Unable to find node on an unmounted component.");
  2590. }
  2591. if (a.stateNode.current === a) {
  2592. // We've determined that A is the current branch.
  2593. return fiber;
  2594. } // Otherwise B has to be current branch.
  2595. return alternate;
  2596. }
  2597. function findCurrentHostFiber(parent) {
  2598. var currentParent = findCurrentFiberUsingSlowPath(parent);
  2599. if (!currentParent) {
  2600. return null;
  2601. } // Next we'll drill down this component to find the first HostComponent/Text.
  2602. var node = currentParent;
  2603. while (true) {
  2604. if (node.tag === HostComponent || node.tag === HostText) {
  2605. return node;
  2606. } else if (node.child) {
  2607. node.child.return = node;
  2608. node = node.child;
  2609. continue;
  2610. }
  2611. if (node === currentParent) {
  2612. return null;
  2613. }
  2614. while (!node.sibling) {
  2615. if (!node.return || node.return === currentParent) {
  2616. return null;
  2617. }
  2618. node = node.return;
  2619. }
  2620. node.sibling.return = node.return;
  2621. node = node.sibling;
  2622. } // Flow needs the return null here, but ESLint complains about it.
  2623. // eslint-disable-next-line no-unreachable
  2624. return null;
  2625. }
  2626. /**
  2627. * In the future, we should cleanup callbacks by cancelling them instead of
  2628. * using this.
  2629. */
  2630. function mountSafeCallback_NOT_REALLY_SAFE(context, callback) {
  2631. return function() {
  2632. if (!callback) {
  2633. return undefined;
  2634. } // This protects against createClass() components.
  2635. // We don't know if there is code depending on it.
  2636. // We intentionally don't use isMounted() because even accessing
  2637. // isMounted property on a React ES6 class will trigger a warning.
  2638. if (typeof context.__isMounted === "boolean") {
  2639. if (!context.__isMounted) {
  2640. return undefined;
  2641. }
  2642. } // FIXME: there used to be other branches that protected
  2643. // against unmounted host components. But RN host components don't
  2644. // define isMounted() anymore, so those checks didn't do anything.
  2645. // They caused false positive warning noise so we removed them:
  2646. // https://github.com/facebook/react-native/issues/18868#issuecomment-413579095
  2647. // However, this means that the callback is NOT guaranteed to be safe
  2648. // for host components. The solution we should implement is to make
  2649. // UIManager.measure() and similar calls truly cancelable. Then we
  2650. // can change our own code calling them to cancel when something unmounts.
  2651. return callback.apply(context, arguments);
  2652. };
  2653. }
  2654. // Modules provided by RN:
  2655. var emptyObject = {};
  2656. /**
  2657. * Create a payload that contains all the updates between two sets of props.
  2658. *
  2659. * These helpers are all encapsulated into a single module, because they use
  2660. * mutation as a performance optimization which leads to subtle shared
  2661. * dependencies between the code paths. To avoid this mutable state leaking
  2662. * across modules, I've kept them isolated to this module.
  2663. */
  2664. // Tracks removed keys
  2665. var removedKeys = null;
  2666. var removedKeyCount = 0;
  2667. var deepDifferOptions = {
  2668. unsafelyIgnoreFunctions: true
  2669. };
  2670. function defaultDiffer(prevProp, nextProp) {
  2671. if (typeof nextProp !== "object" || nextProp === null) {
  2672. // Scalars have already been checked for equality
  2673. return true;
  2674. } else {
  2675. // For objects and arrays, the default diffing algorithm is a deep compare
  2676. return ReactNativePrivateInterface.deepDiffer(
  2677. prevProp,
  2678. nextProp,
  2679. deepDifferOptions
  2680. );
  2681. }
  2682. }
  2683. function restoreDeletedValuesInNestedArray(
  2684. updatePayload,
  2685. node,
  2686. validAttributes
  2687. ) {
  2688. if (Array.isArray(node)) {
  2689. var i = node.length;
  2690. while (i-- && removedKeyCount > 0) {
  2691. restoreDeletedValuesInNestedArray(
  2692. updatePayload,
  2693. node[i],
  2694. validAttributes
  2695. );
  2696. }
  2697. } else if (node && removedKeyCount > 0) {
  2698. var obj = node;
  2699. for (var propKey in removedKeys) {
  2700. if (!removedKeys[propKey]) {
  2701. continue;
  2702. }
  2703. var nextProp = obj[propKey];
  2704. if (nextProp === undefined) {
  2705. continue;
  2706. }
  2707. var attributeConfig = validAttributes[propKey];
  2708. if (!attributeConfig) {
  2709. continue; // not a valid native prop
  2710. }
  2711. if (typeof nextProp === "function") {
  2712. nextProp = true;
  2713. }
  2714. if (typeof nextProp === "undefined") {
  2715. nextProp = null;
  2716. }
  2717. if (typeof attributeConfig !== "object") {
  2718. // case: !Object is the default case
  2719. updatePayload[propKey] = nextProp;
  2720. } else if (
  2721. typeof attributeConfig.diff === "function" ||
  2722. typeof attributeConfig.process === "function"
  2723. ) {
  2724. // case: CustomAttributeConfiguration
  2725. var nextValue =
  2726. typeof attributeConfig.process === "function"
  2727. ? attributeConfig.process(nextProp)
  2728. : nextProp;
  2729. updatePayload[propKey] = nextValue;
  2730. }
  2731. removedKeys[propKey] = false;
  2732. removedKeyCount--;
  2733. }
  2734. }
  2735. }
  2736. function diffNestedArrayProperty(
  2737. updatePayload,
  2738. prevArray,
  2739. nextArray,
  2740. validAttributes
  2741. ) {
  2742. var minLength =
  2743. prevArray.length < nextArray.length ? prevArray.length : nextArray.length;
  2744. var i;
  2745. for (i = 0; i < minLength; i++) {
  2746. // Diff any items in the array in the forward direction. Repeated keys
  2747. // will be overwritten by later values.
  2748. updatePayload = diffNestedProperty(
  2749. updatePayload,
  2750. prevArray[i],
  2751. nextArray[i],
  2752. validAttributes
  2753. );
  2754. }
  2755. for (; i < prevArray.length; i++) {
  2756. // Clear out all remaining properties.
  2757. updatePayload = clearNestedProperty(
  2758. updatePayload,
  2759. prevArray[i],
  2760. validAttributes
  2761. );
  2762. }
  2763. for (; i < nextArray.length; i++) {
  2764. // Add all remaining properties.
  2765. updatePayload = addNestedProperty(
  2766. updatePayload,
  2767. nextArray[i],
  2768. validAttributes
  2769. );
  2770. }
  2771. return updatePayload;
  2772. }
  2773. function diffNestedProperty(
  2774. updatePayload,
  2775. prevProp,
  2776. nextProp,
  2777. validAttributes
  2778. ) {
  2779. if (!updatePayload && prevProp === nextProp) {
  2780. // If no properties have been added, then we can bail out quickly on object
  2781. // equality.
  2782. return updatePayload;
  2783. }
  2784. if (!prevProp || !nextProp) {
  2785. if (nextProp) {
  2786. return addNestedProperty(updatePayload, nextProp, validAttributes);
  2787. }
  2788. if (prevProp) {
  2789. return clearNestedProperty(updatePayload, prevProp, validAttributes);
  2790. }
  2791. return updatePayload;
  2792. }
  2793. if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) {
  2794. // Both are leaves, we can diff the leaves.
  2795. return diffProperties(updatePayload, prevProp, nextProp, validAttributes);
  2796. }
  2797. if (Array.isArray(prevProp) && Array.isArray(nextProp)) {
  2798. // Both are arrays, we can diff the arrays.
  2799. return diffNestedArrayProperty(
  2800. updatePayload,
  2801. prevProp,
  2802. nextProp,
  2803. validAttributes
  2804. );
  2805. }
  2806. if (Array.isArray(prevProp)) {
  2807. return diffProperties(
  2808. updatePayload, // $FlowFixMe - We know that this is always an object when the input is.
  2809. ReactNativePrivateInterface.flattenStyle(prevProp), // $FlowFixMe - We know that this isn't an array because of above flow.
  2810. nextProp,
  2811. validAttributes
  2812. );
  2813. }
  2814. return diffProperties(
  2815. updatePayload,
  2816. prevProp, // $FlowFixMe - We know that this is always an object when the input is.
  2817. ReactNativePrivateInterface.flattenStyle(nextProp),
  2818. validAttributes
  2819. );
  2820. }
  2821. /**
  2822. * addNestedProperty takes a single set of props and valid attribute
  2823. * attribute configurations. It processes each prop and adds it to the
  2824. * updatePayload.
  2825. */
  2826. function addNestedProperty(updatePayload, nextProp, validAttributes) {
  2827. if (!nextProp) {
  2828. return updatePayload;
  2829. }
  2830. if (!Array.isArray(nextProp)) {
  2831. // Add each property of the leaf.
  2832. return addProperties(updatePayload, nextProp, validAttributes);
  2833. }
  2834. for (var i = 0; i < nextProp.length; i++) {
  2835. // Add all the properties of the array.
  2836. updatePayload = addNestedProperty(
  2837. updatePayload,
  2838. nextProp[i],
  2839. validAttributes
  2840. );
  2841. }
  2842. return updatePayload;
  2843. }
  2844. /**
  2845. * clearNestedProperty takes a single set of props and valid attributes. It
  2846. * adds a null sentinel to the updatePayload, for each prop key.
  2847. */
  2848. function clearNestedProperty(updatePayload, prevProp, validAttributes) {
  2849. if (!prevProp) {
  2850. return updatePayload;
  2851. }
  2852. if (!Array.isArray(prevProp)) {
  2853. // Add each property of the leaf.
  2854. return clearProperties(updatePayload, prevProp, validAttributes);
  2855. }
  2856. for (var i = 0; i < prevProp.length; i++) {
  2857. // Add all the properties of the array.
  2858. updatePayload = clearNestedProperty(
  2859. updatePayload,
  2860. prevProp[i],
  2861. validAttributes
  2862. );
  2863. }
  2864. return updatePayload;
  2865. }
  2866. /**
  2867. * diffProperties takes two sets of props and a set of valid attributes
  2868. * and write to updatePayload the values that changed or were deleted.
  2869. * If no updatePayload is provided, a new one is created and returned if
  2870. * anything changed.
  2871. */
  2872. function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
  2873. var attributeConfig;
  2874. var nextProp;
  2875. var prevProp;
  2876. for (var propKey in nextProps) {
  2877. attributeConfig = validAttributes[propKey];
  2878. if (!attributeConfig) {
  2879. continue; // not a valid native prop
  2880. }
  2881. prevProp = prevProps[propKey];
  2882. nextProp = nextProps[propKey]; // functions are converted to booleans as markers that the associated
  2883. // events should be sent from native.
  2884. if (typeof nextProp === "function") {
  2885. nextProp = true; // If nextProp is not a function, then don't bother changing prevProp
  2886. // since nextProp will win and go into the updatePayload regardless.
  2887. if (typeof prevProp === "function") {
  2888. prevProp = true;
  2889. }
  2890. } // An explicit value of undefined is treated as a null because it overrides
  2891. // any other preceding value.
  2892. if (typeof nextProp === "undefined") {
  2893. nextProp = null;
  2894. if (typeof prevProp === "undefined") {
  2895. prevProp = null;
  2896. }
  2897. }
  2898. if (removedKeys) {
  2899. removedKeys[propKey] = false;
  2900. }
  2901. if (updatePayload && updatePayload[propKey] !== undefined) {
  2902. // Something else already triggered an update to this key because another
  2903. // value diffed. Since we're now later in the nested arrays our value is
  2904. // more important so we need to calculate it and override the existing
  2905. // value. It doesn't matter if nothing changed, we'll set it anyway.
  2906. // Pattern match on: attributeConfig
  2907. if (typeof attributeConfig !== "object") {
  2908. // case: !Object is the default case
  2909. updatePayload[propKey] = nextProp;
  2910. } else if (
  2911. typeof attributeConfig.diff === "function" ||
  2912. typeof attributeConfig.process === "function"
  2913. ) {
  2914. // case: CustomAttributeConfiguration
  2915. var nextValue =
  2916. typeof attributeConfig.process === "function"
  2917. ? attributeConfig.process(nextProp)
  2918. : nextProp;
  2919. updatePayload[propKey] = nextValue;
  2920. }
  2921. continue;
  2922. }
  2923. if (prevProp === nextProp) {
  2924. continue; // nothing changed
  2925. } // Pattern match on: attributeConfig
  2926. if (typeof attributeConfig !== "object") {
  2927. // case: !Object is the default case
  2928. if (defaultDiffer(prevProp, nextProp)) {
  2929. // a normal leaf has changed
  2930. (updatePayload || (updatePayload = {}))[propKey] = nextProp;
  2931. }
  2932. } else if (
  2933. typeof attributeConfig.diff === "function" ||
  2934. typeof attributeConfig.process === "function"
  2935. ) {
  2936. // case: CustomAttributeConfiguration
  2937. var shouldUpdate =
  2938. prevProp === undefined ||
  2939. (typeof attributeConfig.diff === "function"
  2940. ? attributeConfig.diff(prevProp, nextProp)
  2941. : defaultDiffer(prevProp, nextProp));
  2942. if (shouldUpdate) {
  2943. var _nextValue =
  2944. typeof attributeConfig.process === "function"
  2945. ? attributeConfig.process(nextProp)
  2946. : nextProp;
  2947. (updatePayload || (updatePayload = {}))[propKey] = _nextValue;
  2948. }
  2949. } else {
  2950. // default: fallthrough case when nested properties are defined
  2951. removedKeys = null;
  2952. removedKeyCount = 0; // We think that attributeConfig is not CustomAttributeConfiguration at
  2953. // this point so we assume it must be AttributeConfiguration.
  2954. updatePayload = diffNestedProperty(
  2955. updatePayload,
  2956. prevProp,
  2957. nextProp,
  2958. attributeConfig
  2959. );
  2960. if (removedKeyCount > 0 && updatePayload) {
  2961. restoreDeletedValuesInNestedArray(
  2962. updatePayload,
  2963. nextProp,
  2964. attributeConfig
  2965. );
  2966. removedKeys = null;
  2967. }
  2968. }
  2969. } // Also iterate through all the previous props to catch any that have been
  2970. // removed and make sure native gets the signal so it can reset them to the
  2971. // default.
  2972. for (var _propKey in prevProps) {
  2973. if (nextProps[_propKey] !== undefined) {
  2974. continue; // we've already covered this key in the previous pass
  2975. }
  2976. attributeConfig = validAttributes[_propKey];
  2977. if (!attributeConfig) {
  2978. continue; // not a valid native prop
  2979. }
  2980. if (updatePayload && updatePayload[_propKey] !== undefined) {
  2981. // This was already updated to a diff result earlier.
  2982. continue;
  2983. }
  2984. prevProp = prevProps[_propKey];
  2985. if (prevProp === undefined) {
  2986. continue; // was already empty anyway
  2987. } // Pattern match on: attributeConfig
  2988. if (
  2989. typeof attributeConfig !== "object" ||
  2990. typeof attributeConfig.diff === "function" ||
  2991. typeof attributeConfig.process === "function"
  2992. ) {
  2993. // case: CustomAttributeConfiguration | !Object
  2994. // Flag the leaf property for removal by sending a sentinel.
  2995. (updatePayload || (updatePayload = {}))[_propKey] = null;
  2996. if (!removedKeys) {
  2997. removedKeys = {};
  2998. }
  2999. if (!removedKeys[_propKey]) {
  3000. removedKeys[_propKey] = true;
  3001. removedKeyCount++;
  3002. }
  3003. } else {
  3004. // default:
  3005. // This is a nested attribute configuration where all the properties
  3006. // were removed so we need to go through and clear out all of them.
  3007. updatePayload = clearNestedProperty(
  3008. updatePayload,
  3009. prevProp,
  3010. attributeConfig
  3011. );
  3012. }
  3013. }
  3014. return updatePayload;
  3015. }
  3016. /**
  3017. * addProperties adds all the valid props to the payload after being processed.
  3018. */
  3019. function addProperties(updatePayload, props, validAttributes) {
  3020. // TODO: Fast path
  3021. return diffProperties(updatePayload, emptyObject, props, validAttributes);
  3022. }
  3023. /**
  3024. * clearProperties clears all the previous props by adding a null sentinel
  3025. * to the payload for each valid key.
  3026. */
  3027. function clearProperties(updatePayload, prevProps, validAttributes) {
  3028. // TODO: Fast path
  3029. return diffProperties(updatePayload, prevProps, emptyObject, validAttributes);
  3030. }
  3031. function create(props, validAttributes) {
  3032. return addProperties(
  3033. null, // updatePayload
  3034. props,
  3035. validAttributes
  3036. );
  3037. }
  3038. function diff(prevProps, nextProps, validAttributes) {
  3039. return diffProperties(
  3040. null, // updatePayload
  3041. prevProps,
  3042. nextProps,
  3043. validAttributes
  3044. );
  3045. }
  3046. var PLUGIN_EVENT_SYSTEM = 1;
  3047. // the renderer. Such as when we're dispatching events or if third party
  3048. // libraries need to call batchedUpdates. Eventually, this API will go away when
  3049. // everything is batched by default. We'll then have a similar API to opt-out of
  3050. // scheduled work and instead do synchronous work.
  3051. // Defaults
  3052. var batchedUpdatesImpl = function(fn, bookkeeping) {
  3053. return fn(bookkeeping);
  3054. };
  3055. var isInsideEventHandler = false;
  3056. function batchedUpdates(fn, bookkeeping) {
  3057. if (isInsideEventHandler) {
  3058. // If we are currently inside another batch, we need to wait until it
  3059. // fully completes before restoring state.
  3060. return fn(bookkeeping);
  3061. }
  3062. isInsideEventHandler = true;
  3063. try {
  3064. return batchedUpdatesImpl(fn, bookkeeping);
  3065. } finally {
  3066. isInsideEventHandler = false;
  3067. }
  3068. }
  3069. function setBatchingImplementation(
  3070. _batchedUpdatesImpl,
  3071. _discreteUpdatesImpl,
  3072. _flushDiscreteUpdatesImpl,
  3073. _batchedEventUpdatesImpl
  3074. ) {
  3075. batchedUpdatesImpl = _batchedUpdatesImpl;
  3076. }
  3077. /**
  3078. * Internal queue of events that have accumulated their dispatches and are
  3079. * waiting to have their dispatches executed.
  3080. */
  3081. var eventQueue = null;
  3082. /**
  3083. * Dispatches an event and releases it back into the pool, unless persistent.
  3084. *
  3085. * @param {?object} event Synthetic event to be dispatched.
  3086. * @private
  3087. */
  3088. var executeDispatchesAndRelease = function(event) {
  3089. if (event) {
  3090. executeDispatchesInOrder(event);
  3091. if (!event.isPersistent()) {
  3092. event.constructor.release(event);
  3093. }
  3094. }
  3095. };
  3096. var executeDispatchesAndReleaseTopLevel = function(e) {
  3097. return executeDispatchesAndRelease(e);
  3098. };
  3099. function runEventsInBatch(events) {
  3100. if (events !== null) {
  3101. eventQueue = accumulateInto(eventQueue, events);
  3102. } // Set `eventQueue` to null before processing it so that we can tell if more
  3103. // events get enqueued while processing.
  3104. var processingEventQueue = eventQueue;
  3105. eventQueue = null;
  3106. if (!processingEventQueue) {
  3107. return;
  3108. }
  3109. forEachAccumulated(processingEventQueue, executeDispatchesAndReleaseTopLevel);
  3110. if (!!eventQueue) {
  3111. throw Error(
  3112. "processEventQueue(): Additional events were enqueued while processing an event queue. Support for this has not yet been implemented."
  3113. );
  3114. } // This would be a good time to rethrow if any of the event handlers threw.
  3115. rethrowCaughtError();
  3116. }
  3117. /**
  3118. * Allows registered plugins an opportunity to extract events from top-level
  3119. * native browser events.
  3120. *
  3121. * @return {*} An accumulation of synthetic events.
  3122. * @internal
  3123. */
  3124. function extractPluginEvents(
  3125. topLevelType,
  3126. targetInst,
  3127. nativeEvent,
  3128. nativeEventTarget,
  3129. eventSystemFlags
  3130. ) {
  3131. var events = null;
  3132. for (var i = 0; i < plugins.length; i++) {
  3133. // Not every plugin in the ordering may be loaded at runtime.
  3134. var possiblePlugin = plugins[i];
  3135. if (possiblePlugin) {
  3136. var extractedEvents = possiblePlugin.extractEvents(
  3137. topLevelType,
  3138. targetInst,
  3139. nativeEvent,
  3140. nativeEventTarget,
  3141. eventSystemFlags
  3142. );
  3143. if (extractedEvents) {
  3144. events = accumulateInto(events, extractedEvents);
  3145. }
  3146. }
  3147. }
  3148. return events;
  3149. }
  3150. function runExtractedPluginEventsInBatch(
  3151. topLevelType,
  3152. targetInst,
  3153. nativeEvent,
  3154. nativeEventTarget,
  3155. eventSystemFlags
  3156. ) {
  3157. var events = extractPluginEvents(
  3158. topLevelType,
  3159. targetInst,
  3160. nativeEvent,
  3161. nativeEventTarget,
  3162. eventSystemFlags
  3163. );
  3164. runEventsInBatch(events);
  3165. }
  3166. function dispatchEvent(target, topLevelType, nativeEvent) {
  3167. var targetFiber = target;
  3168. var eventTarget = null;
  3169. if (targetFiber != null) {
  3170. var stateNode = targetFiber.stateNode; // Guard against Fiber being unmounted
  3171. if (stateNode != null) {
  3172. eventTarget = stateNode.canonical;
  3173. }
  3174. }
  3175. batchedUpdates(function() {
  3176. // Heritage plugin event system
  3177. runExtractedPluginEventsInBatch(
  3178. topLevelType,
  3179. targetFiber,
  3180. nativeEvent,
  3181. eventTarget,
  3182. PLUGIN_EVENT_SYSTEM
  3183. );
  3184. }); // React Native doesn't use ReactControlledComponent but if it did, here's
  3185. // where it would do it.
  3186. }
  3187. // can re-export everything from this module.
  3188. function shim() {
  3189. {
  3190. throw Error(
  3191. "The current renderer does not support mutation. This error is likely caused by a bug in React. Please file an issue."
  3192. );
  3193. }
  3194. } // Mutation (when unsupported)
  3195. var supportsMutation = false;
  3196. var commitMount = shim;
  3197. // can re-export everything from this module.
  3198. function shim$1() {
  3199. {
  3200. throw Error(
  3201. "The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue."
  3202. );
  3203. }
  3204. } // Hydration (when unsupported)
  3205. var isSuspenseInstancePending = shim$1;
  3206. var isSuspenseInstanceFallback = shim$1;
  3207. var hydrateTextInstance = shim$1;
  3208. var _nativeFabricUIManage = nativeFabricUIManager,
  3209. createNode = _nativeFabricUIManage.createNode,
  3210. cloneNode = _nativeFabricUIManage.cloneNode,
  3211. cloneNodeWithNewChildren = _nativeFabricUIManage.cloneNodeWithNewChildren,
  3212. cloneNodeWithNewChildrenAndProps =
  3213. _nativeFabricUIManage.cloneNodeWithNewChildrenAndProps,
  3214. cloneNodeWithNewProps = _nativeFabricUIManage.cloneNodeWithNewProps,
  3215. createChildNodeSet = _nativeFabricUIManage.createChildSet,
  3216. appendChildNode = _nativeFabricUIManage.appendChild,
  3217. appendChildNodeToSet = _nativeFabricUIManage.appendChildToSet,
  3218. completeRoot = _nativeFabricUIManage.completeRoot,
  3219. registerEventHandler = _nativeFabricUIManage.registerEventHandler,
  3220. fabricMeasure = _nativeFabricUIManage.measure,
  3221. fabricMeasureInWindow = _nativeFabricUIManage.measureInWindow,
  3222. fabricMeasureLayout = _nativeFabricUIManage.measureLayout;
  3223. var getViewConfigForType =
  3224. ReactNativePrivateInterface.ReactNativeViewConfigRegistry.get; // Counter for uniquely identifying views.
  3225. // % 10 === 1 means it is a rootTag.
  3226. // % 2 === 0 means it is a Fabric tag.
  3227. // This means that they never overlap.
  3228. var nextReactTag = 2;
  3229. // TODO: Remove this conditional once all changes have propagated.
  3230. if (registerEventHandler) {
  3231. /**
  3232. * Register the event emitter with the native bridge
  3233. */
  3234. registerEventHandler(dispatchEvent);
  3235. }
  3236. /**
  3237. * This is used for refs on host components.
  3238. */
  3239. var ReactFabricHostComponent =
  3240. /*#__PURE__*/
  3241. (function() {
  3242. function ReactFabricHostComponent(
  3243. tag,
  3244. viewConfig,
  3245. props,
  3246. internalInstanceHandle
  3247. ) {
  3248. this._nativeTag = tag;
  3249. this.viewConfig = viewConfig;
  3250. this.currentProps = props;
  3251. this._internalInstanceHandle = internalInstanceHandle;
  3252. }
  3253. var _proto = ReactFabricHostComponent.prototype;
  3254. _proto.blur = function blur() {
  3255. ReactNativePrivateInterface.TextInputState.blurTextInput(this);
  3256. };
  3257. _proto.focus = function focus() {
  3258. ReactNativePrivateInterface.TextInputState.focusTextInput(this);
  3259. };
  3260. _proto.measure = function measure(callback) {
  3261. fabricMeasure(
  3262. this._internalInstanceHandle.stateNode.node,
  3263. mountSafeCallback_NOT_REALLY_SAFE(this, callback)
  3264. );
  3265. };
  3266. _proto.measureInWindow = function measureInWindow(callback) {
  3267. fabricMeasureInWindow(
  3268. this._internalInstanceHandle.stateNode.node,
  3269. mountSafeCallback_NOT_REALLY_SAFE(this, callback)
  3270. );
  3271. };
  3272. _proto.measureLayout = function measureLayout(
  3273. relativeToNativeNode,
  3274. onSuccess,
  3275. onFail
  3276. ) /* currently unused */
  3277. {
  3278. if (
  3279. typeof relativeToNativeNode === "number" ||
  3280. !(relativeToNativeNode instanceof ReactFabricHostComponent)
  3281. ) {
  3282. {
  3283. error(
  3284. "Warning: ref.measureLayout must be called with a ref to a native component."
  3285. );
  3286. }
  3287. return;
  3288. }
  3289. fabricMeasureLayout(
  3290. this._internalInstanceHandle.stateNode.node,
  3291. relativeToNativeNode._internalInstanceHandle.stateNode.node,
  3292. mountSafeCallback_NOT_REALLY_SAFE(this, onFail),
  3293. mountSafeCallback_NOT_REALLY_SAFE(this, onSuccess)
  3294. );
  3295. };
  3296. _proto.setNativeProps = function setNativeProps(nativeProps) {
  3297. {
  3298. error("Warning: setNativeProps is not currently supported in Fabric");
  3299. }
  3300. return;
  3301. };
  3302. return ReactFabricHostComponent;
  3303. })(); // eslint-disable-next-line no-unused-expressions
  3304. function appendInitialChild(parentInstance, child) {
  3305. appendChildNode(parentInstance.node, child.node);
  3306. }
  3307. function createInstance(
  3308. type,
  3309. props,
  3310. rootContainerInstance,
  3311. hostContext,
  3312. internalInstanceHandle
  3313. ) {
  3314. var tag = nextReactTag;
  3315. nextReactTag += 2;
  3316. var viewConfig = getViewConfigForType(type);
  3317. {
  3318. for (var key in viewConfig.validAttributes) {
  3319. if (props.hasOwnProperty(key)) {
  3320. ReactNativePrivateInterface.deepFreezeAndThrowOnMutationInDev(
  3321. props[key]
  3322. );
  3323. }
  3324. }
  3325. }
  3326. var updatePayload = create(props, viewConfig.validAttributes);
  3327. var node = createNode(
  3328. tag, // reactTag
  3329. viewConfig.uiViewClassName, // viewName
  3330. rootContainerInstance, // rootTag
  3331. updatePayload, // props
  3332. internalInstanceHandle // internalInstanceHandle
  3333. );
  3334. var component = new ReactFabricHostComponent(
  3335. tag,
  3336. viewConfig,
  3337. props,
  3338. internalInstanceHandle
  3339. );
  3340. return {
  3341. node: node,
  3342. canonical: component
  3343. };
  3344. }
  3345. function createTextInstance(
  3346. text,
  3347. rootContainerInstance,
  3348. hostContext,
  3349. internalInstanceHandle
  3350. ) {
  3351. if (!hostContext.isInAParentText) {
  3352. throw Error("Text strings must be rendered within a <Text> component.");
  3353. }
  3354. var tag = nextReactTag;
  3355. nextReactTag += 2;
  3356. var node = createNode(
  3357. tag, // reactTag
  3358. "RCTRawText", // viewName
  3359. rootContainerInstance, // rootTag
  3360. {
  3361. text: text
  3362. }, // props
  3363. internalInstanceHandle // instance handle
  3364. );
  3365. return {
  3366. node: node
  3367. };
  3368. }
  3369. function getRootHostContext(rootContainerInstance) {
  3370. return {
  3371. isInAParentText: false
  3372. };
  3373. }
  3374. function getChildHostContext(parentHostContext, type, rootContainerInstance) {
  3375. var prevIsInAParentText = parentHostContext.isInAParentText;
  3376. var isInAParentText =
  3377. type === "AndroidTextInput" || // Android
  3378. type === "RCTMultilineTextInputView" || // iOS
  3379. type === "RCTSinglelineTextInputView" || // iOS
  3380. type === "RCTText" ||
  3381. type === "RCTVirtualText";
  3382. if (prevIsInAParentText !== isInAParentText) {
  3383. return {
  3384. isInAParentText: isInAParentText
  3385. };
  3386. } else {
  3387. return parentHostContext;
  3388. }
  3389. }
  3390. function getPublicInstance(instance) {
  3391. return instance.canonical;
  3392. }
  3393. function prepareForCommit(containerInfo) {
  3394. // Noop
  3395. }
  3396. function prepareUpdate(
  3397. instance,
  3398. type,
  3399. oldProps,
  3400. newProps,
  3401. rootContainerInstance,
  3402. hostContext
  3403. ) {
  3404. var viewConfig = instance.canonical.viewConfig;
  3405. var updatePayload = diff(oldProps, newProps, viewConfig.validAttributes); // TODO: If the event handlers have changed, we need to update the current props
  3406. // in the commit phase but there is no host config hook to do it yet.
  3407. // So instead we hack it by updating it in the render phase.
  3408. instance.canonical.currentProps = newProps;
  3409. return updatePayload;
  3410. }
  3411. function resetAfterCommit(containerInfo) {
  3412. // Noop
  3413. }
  3414. function shouldDeprioritizeSubtree(type, props) {
  3415. return false;
  3416. }
  3417. function shouldSetTextContent(type, props) {
  3418. // TODO (bvaughn) Revisit this decision.
  3419. // Always returning false simplifies the createInstance() implementation,
  3420. // But creates an additional child Fiber for raw text children.
  3421. // No additional native views are created though.
  3422. // It's not clear to me which is better so I'm deferring for now.
  3423. // More context @ github.com/facebook/react/pull/8560#discussion_r92111303
  3424. return false;
  3425. } // The Fabric renderer is secondary to the existing React Native renderer.
  3426. var scheduleTimeout = setTimeout;
  3427. var cancelTimeout = clearTimeout;
  3428. var noTimeout = -1; // -------------------
  3429. function cloneInstance(
  3430. instance,
  3431. updatePayload,
  3432. type,
  3433. oldProps,
  3434. newProps,
  3435. internalInstanceHandle,
  3436. keepChildren,
  3437. recyclableInstance
  3438. ) {
  3439. var node = instance.node;
  3440. var clone;
  3441. if (keepChildren) {
  3442. if (updatePayload !== null) {
  3443. clone = cloneNodeWithNewProps(node, updatePayload);
  3444. } else {
  3445. clone = cloneNode(node);
  3446. }
  3447. } else {
  3448. if (updatePayload !== null) {
  3449. clone = cloneNodeWithNewChildrenAndProps(node, updatePayload);
  3450. } else {
  3451. clone = cloneNodeWithNewChildren(node);
  3452. }
  3453. }
  3454. return {
  3455. node: clone,
  3456. canonical: instance.canonical
  3457. };
  3458. }
  3459. function cloneHiddenInstance(instance, type, props, internalInstanceHandle) {
  3460. var viewConfig = instance.canonical.viewConfig;
  3461. var node = instance.node;
  3462. var updatePayload = create(
  3463. {
  3464. style: {
  3465. display: "none"
  3466. }
  3467. },
  3468. viewConfig.validAttributes
  3469. );
  3470. return {
  3471. node: cloneNodeWithNewProps(node, updatePayload),
  3472. canonical: instance.canonical
  3473. };
  3474. }
  3475. function cloneHiddenTextInstance(instance, text, internalInstanceHandle) {
  3476. throw new Error("Not yet implemented.");
  3477. }
  3478. function createContainerChildSet(container) {
  3479. return createChildNodeSet(container);
  3480. }
  3481. function appendChildToContainerChildSet(childSet, child) {
  3482. appendChildNodeToSet(childSet, child.node);
  3483. }
  3484. function finalizeContainerChildren(container, newChildren) {
  3485. completeRoot(container, newChildren);
  3486. }
  3487. var loggedTypeFailures = {};
  3488. function checkPropTypes(typeSpecs, values, location, componentName) {
  3489. {
  3490. // $FlowFixMe This is okay but Flow doesn't know it.
  3491. var has = Function.call.bind(Object.prototype.hasOwnProperty);
  3492. for (var typeSpecName in typeSpecs) {
  3493. if (has(typeSpecs, typeSpecName)) {
  3494. var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
  3495. // fail the render phase where it didn't fail before. So we log it.
  3496. // After these have been cleaned up, we'll let them throw.
  3497. try {
  3498. // This is intentionally an invariant that gets caught. It's the same
  3499. // behavior as without this statement except with a better message.
  3500. if (typeof typeSpecs[typeSpecName] !== "function") {
  3501. var err = Error(
  3502. (componentName || "React class") +
  3503. ": " +
  3504. location +
  3505. " type `" +
  3506. typeSpecName +
  3507. "` is invalid; " +
  3508. "it must be a function, usually from the `prop-types` package, but received `" +
  3509. typeof typeSpecs[typeSpecName] +
  3510. "`." +
  3511. "This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."
  3512. );
  3513. err.name = "Invariant Violation";
  3514. throw err;
  3515. }
  3516. error$1 = typeSpecs[typeSpecName](
  3517. values,
  3518. typeSpecName,
  3519. componentName,
  3520. location,
  3521. null,
  3522. "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"
  3523. );
  3524. } catch (ex) {
  3525. error$1 = ex;
  3526. }
  3527. if (error$1 && !(error$1 instanceof Error)) {
  3528. error(
  3529. "%s: type specification of %s" +
  3530. " `%s` is invalid; the type checker " +
  3531. "function must return `null` or an `Error` but returned a %s. " +
  3532. "You may have forgotten to pass an argument to the type checker " +
  3533. "creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and " +
  3534. "shape all require an argument).",
  3535. componentName || "React class",
  3536. location,
  3537. typeSpecName,
  3538. typeof error$1
  3539. );
  3540. }
  3541. if (
  3542. error$1 instanceof Error &&
  3543. !(error$1.message in loggedTypeFailures)
  3544. ) {
  3545. // Only monitor this failure once because there tends to be a lot of the
  3546. // same error.
  3547. loggedTypeFailures[error$1.message] = true;
  3548. error("Failed %s type: %s", location, error$1.message);
  3549. }
  3550. }
  3551. }
  3552. }
  3553. }
  3554. // Prefix measurements so that it's possible to filter them.
  3555. // Longer prefixes are hard to read in DevTools.
  3556. var reactEmoji = "\u269B";
  3557. var warningEmoji = "\u26D4";
  3558. var supportsUserTiming =
  3559. typeof performance !== "undefined" &&
  3560. typeof performance.mark === "function" &&
  3561. typeof performance.clearMarks === "function" &&
  3562. typeof performance.measure === "function" &&
  3563. typeof performance.clearMeasures === "function"; // Keep track of current fiber so that we know the path to unwind on pause.
  3564. // TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
  3565. var currentFiber = null; // If we're in the middle of user code, which fiber and method is it?
  3566. // Reusing `currentFiber` would be confusing for this because user code fiber
  3567. // can change during commit phase too, but we don't need to unwind it (since
  3568. // lifecycles in the commit phase don't resemble a tree).
  3569. var currentPhase = null;
  3570. var currentPhaseFiber = null; // Did lifecycle hook schedule an update? This is often a performance problem,
  3571. // so we will keep track of it, and include it in the report.
  3572. // Track commits caused by cascading updates.
  3573. var isCommitting = false;
  3574. var hasScheduledUpdateInCurrentCommit = false;
  3575. var hasScheduledUpdateInCurrentPhase = false;
  3576. var commitCountInCurrentWorkLoop = 0;
  3577. var effectCountInCurrentCommit = 0;
  3578. // to avoid stretch the commit phase with measurement overhead.
  3579. var labelsInCurrentCommit = new Set();
  3580. var formatMarkName = function(markName) {
  3581. return reactEmoji + " " + markName;
  3582. };
  3583. var formatLabel = function(label, warning) {
  3584. var prefix = warning ? warningEmoji + " " : reactEmoji + " ";
  3585. var suffix = warning ? " Warning: " + warning : "";
  3586. return "" + prefix + label + suffix;
  3587. };
  3588. var beginMark = function(markName) {
  3589. performance.mark(formatMarkName(markName));
  3590. };
  3591. var clearMark = function(markName) {
  3592. performance.clearMarks(formatMarkName(markName));
  3593. };
  3594. var endMark = function(label, markName, warning) {
  3595. var formattedMarkName = formatMarkName(markName);
  3596. var formattedLabel = formatLabel(label, warning);
  3597. try {
  3598. performance.measure(formattedLabel, formattedMarkName);
  3599. } catch (err) {} // If previous mark was missing for some reason, this will throw.
  3600. // This could only happen if React crashed in an unexpected place earlier.
  3601. // Don't pile on with more errors.
  3602. // Clear marks immediately to avoid growing buffer.
  3603. performance.clearMarks(formattedMarkName);
  3604. performance.clearMeasures(formattedLabel);
  3605. };
  3606. var getFiberMarkName = function(label, debugID) {
  3607. return label + " (#" + debugID + ")";
  3608. };
  3609. var getFiberLabel = function(componentName, isMounted, phase) {
  3610. if (phase === null) {
  3611. // These are composite component total time measurements.
  3612. return componentName + " [" + (isMounted ? "update" : "mount") + "]";
  3613. } else {
  3614. // Composite component methods.
  3615. return componentName + "." + phase;
  3616. }
  3617. };
  3618. var beginFiberMark = function(fiber, phase) {
  3619. var componentName = getComponentName(fiber.type) || "Unknown";
  3620. var debugID = fiber._debugID;
  3621. var isMounted = fiber.alternate !== null;
  3622. var label = getFiberLabel(componentName, isMounted, phase);
  3623. if (isCommitting && labelsInCurrentCommit.has(label)) {
  3624. // During the commit phase, we don't show duplicate labels because
  3625. // there is a fixed overhead for every measurement, and we don't
  3626. // want to stretch the commit phase beyond necessary.
  3627. return false;
  3628. }
  3629. labelsInCurrentCommit.add(label);
  3630. var markName = getFiberMarkName(label, debugID);
  3631. beginMark(markName);
  3632. return true;
  3633. };
  3634. var clearFiberMark = function(fiber, phase) {
  3635. var componentName = getComponentName(fiber.type) || "Unknown";
  3636. var debugID = fiber._debugID;
  3637. var isMounted = fiber.alternate !== null;
  3638. var label = getFiberLabel(componentName, isMounted, phase);
  3639. var markName = getFiberMarkName(label, debugID);
  3640. clearMark(markName);
  3641. };
  3642. var endFiberMark = function(fiber, phase, warning) {
  3643. var componentName = getComponentName(fiber.type) || "Unknown";
  3644. var debugID = fiber._debugID;
  3645. var isMounted = fiber.alternate !== null;
  3646. var label = getFiberLabel(componentName, isMounted, phase);
  3647. var markName = getFiberMarkName(label, debugID);
  3648. endMark(label, markName, warning);
  3649. };
  3650. var shouldIgnoreFiber = function(fiber) {
  3651. // Host components should be skipped in the timeline.
  3652. // We could check typeof fiber.type, but does this work with RN?
  3653. switch (fiber.tag) {
  3654. case HostRoot:
  3655. case HostComponent:
  3656. case HostText:
  3657. case HostPortal:
  3658. case Fragment:
  3659. case ContextProvider:
  3660. case ContextConsumer:
  3661. case Mode:
  3662. return true;
  3663. default:
  3664. return false;
  3665. }
  3666. };
  3667. var clearPendingPhaseMeasurement = function() {
  3668. if (currentPhase !== null && currentPhaseFiber !== null) {
  3669. clearFiberMark(currentPhaseFiber, currentPhase);
  3670. }
  3671. currentPhaseFiber = null;
  3672. currentPhase = null;
  3673. hasScheduledUpdateInCurrentPhase = false;
  3674. };
  3675. var pauseTimers = function() {
  3676. // Stops all currently active measurements so that they can be resumed
  3677. // if we continue in a later deferred loop from the same unit of work.
  3678. var fiber = currentFiber;
  3679. while (fiber) {
  3680. if (fiber._debugIsCurrentlyTiming) {
  3681. endFiberMark(fiber, null, null);
  3682. }
  3683. fiber = fiber.return;
  3684. }
  3685. };
  3686. var resumeTimersRecursively = function(fiber) {
  3687. if (fiber.return !== null) {
  3688. resumeTimersRecursively(fiber.return);
  3689. }
  3690. if (fiber._debugIsCurrentlyTiming) {
  3691. beginFiberMark(fiber, null);
  3692. }
  3693. };
  3694. var resumeTimers = function() {
  3695. // Resumes all measurements that were active during the last deferred loop.
  3696. if (currentFiber !== null) {
  3697. resumeTimersRecursively(currentFiber);
  3698. }
  3699. };
  3700. function recordEffect() {
  3701. {
  3702. effectCountInCurrentCommit++;
  3703. }
  3704. }
  3705. function recordScheduleUpdate() {
  3706. {
  3707. if (isCommitting) {
  3708. hasScheduledUpdateInCurrentCommit = true;
  3709. }
  3710. if (
  3711. currentPhase !== null &&
  3712. currentPhase !== "componentWillMount" &&
  3713. currentPhase !== "componentWillReceiveProps"
  3714. ) {
  3715. hasScheduledUpdateInCurrentPhase = true;
  3716. }
  3717. }
  3718. }
  3719. function startWorkTimer(fiber) {
  3720. {
  3721. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  3722. return;
  3723. } // If we pause, this is the fiber to unwind from.
  3724. currentFiber = fiber;
  3725. if (!beginFiberMark(fiber, null)) {
  3726. return;
  3727. }
  3728. fiber._debugIsCurrentlyTiming = true;
  3729. }
  3730. }
  3731. function cancelWorkTimer(fiber) {
  3732. {
  3733. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  3734. return;
  3735. } // Remember we shouldn't complete measurement for this fiber.
  3736. // Otherwise flamechart will be deep even for small updates.
  3737. fiber._debugIsCurrentlyTiming = false;
  3738. clearFiberMark(fiber, null);
  3739. }
  3740. }
  3741. function stopWorkTimer(fiber) {
  3742. {
  3743. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  3744. return;
  3745. } // If we pause, its parent is the fiber to unwind from.
  3746. currentFiber = fiber.return;
  3747. if (!fiber._debugIsCurrentlyTiming) {
  3748. return;
  3749. }
  3750. fiber._debugIsCurrentlyTiming = false;
  3751. endFiberMark(fiber, null, null);
  3752. }
  3753. }
  3754. function stopFailedWorkTimer(fiber) {
  3755. {
  3756. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  3757. return;
  3758. } // If we pause, its parent is the fiber to unwind from.
  3759. currentFiber = fiber.return;
  3760. if (!fiber._debugIsCurrentlyTiming) {
  3761. return;
  3762. }
  3763. fiber._debugIsCurrentlyTiming = false;
  3764. var warning =
  3765. fiber.tag === SuspenseComponent
  3766. ? "Rendering was suspended"
  3767. : "An error was thrown inside this error boundary";
  3768. endFiberMark(fiber, null, warning);
  3769. }
  3770. }
  3771. function startPhaseTimer(fiber, phase) {
  3772. {
  3773. if (!supportsUserTiming) {
  3774. return;
  3775. }
  3776. clearPendingPhaseMeasurement();
  3777. if (!beginFiberMark(fiber, phase)) {
  3778. return;
  3779. }
  3780. currentPhaseFiber = fiber;
  3781. currentPhase = phase;
  3782. }
  3783. }
  3784. function stopPhaseTimer() {
  3785. {
  3786. if (!supportsUserTiming) {
  3787. return;
  3788. }
  3789. if (currentPhase !== null && currentPhaseFiber !== null) {
  3790. var warning = hasScheduledUpdateInCurrentPhase
  3791. ? "Scheduled a cascading update"
  3792. : null;
  3793. endFiberMark(currentPhaseFiber, currentPhase, warning);
  3794. }
  3795. currentPhase = null;
  3796. currentPhaseFiber = null;
  3797. }
  3798. }
  3799. function startWorkLoopTimer(nextUnitOfWork) {
  3800. {
  3801. currentFiber = nextUnitOfWork;
  3802. if (!supportsUserTiming) {
  3803. return;
  3804. }
  3805. commitCountInCurrentWorkLoop = 0; // This is top level call.
  3806. // Any other measurements are performed within.
  3807. beginMark("(React Tree Reconciliation)"); // Resume any measurements that were in progress during the last loop.
  3808. resumeTimers();
  3809. }
  3810. }
  3811. function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
  3812. {
  3813. if (!supportsUserTiming) {
  3814. return;
  3815. }
  3816. var warning = null;
  3817. if (interruptedBy !== null) {
  3818. if (interruptedBy.tag === HostRoot) {
  3819. warning = "A top-level update interrupted the previous render";
  3820. } else {
  3821. var componentName = getComponentName(interruptedBy.type) || "Unknown";
  3822. warning =
  3823. "An update to " + componentName + " interrupted the previous render";
  3824. }
  3825. } else if (commitCountInCurrentWorkLoop > 1) {
  3826. warning = "There were cascading updates";
  3827. }
  3828. commitCountInCurrentWorkLoop = 0;
  3829. var label = didCompleteRoot
  3830. ? "(React Tree Reconciliation: Completed Root)"
  3831. : "(React Tree Reconciliation: Yielded)"; // Pause any measurements until the next loop.
  3832. pauseTimers();
  3833. endMark(label, "(React Tree Reconciliation)", warning);
  3834. }
  3835. }
  3836. function startCommitTimer() {
  3837. {
  3838. if (!supportsUserTiming) {
  3839. return;
  3840. }
  3841. isCommitting = true;
  3842. hasScheduledUpdateInCurrentCommit = false;
  3843. labelsInCurrentCommit.clear();
  3844. beginMark("(Committing Changes)");
  3845. }
  3846. }
  3847. function stopCommitTimer() {
  3848. {
  3849. if (!supportsUserTiming) {
  3850. return;
  3851. }
  3852. var warning = null;
  3853. if (hasScheduledUpdateInCurrentCommit) {
  3854. warning = "Lifecycle hook scheduled a cascading update";
  3855. } else if (commitCountInCurrentWorkLoop > 0) {
  3856. warning = "Caused by a cascading update in earlier commit";
  3857. }
  3858. hasScheduledUpdateInCurrentCommit = false;
  3859. commitCountInCurrentWorkLoop++;
  3860. isCommitting = false;
  3861. labelsInCurrentCommit.clear();
  3862. endMark("(Committing Changes)", "(Committing Changes)", warning);
  3863. }
  3864. }
  3865. function startCommitSnapshotEffectsTimer() {
  3866. {
  3867. if (!supportsUserTiming) {
  3868. return;
  3869. }
  3870. effectCountInCurrentCommit = 0;
  3871. beginMark("(Committing Snapshot Effects)");
  3872. }
  3873. }
  3874. function stopCommitSnapshotEffectsTimer() {
  3875. {
  3876. if (!supportsUserTiming) {
  3877. return;
  3878. }
  3879. var count = effectCountInCurrentCommit;
  3880. effectCountInCurrentCommit = 0;
  3881. endMark(
  3882. "(Committing Snapshot Effects: " + count + " Total)",
  3883. "(Committing Snapshot Effects)",
  3884. null
  3885. );
  3886. }
  3887. }
  3888. function startCommitHostEffectsTimer() {
  3889. {
  3890. if (!supportsUserTiming) {
  3891. return;
  3892. }
  3893. effectCountInCurrentCommit = 0;
  3894. beginMark("(Committing Host Effects)");
  3895. }
  3896. }
  3897. function stopCommitHostEffectsTimer() {
  3898. {
  3899. if (!supportsUserTiming) {
  3900. return;
  3901. }
  3902. var count = effectCountInCurrentCommit;
  3903. effectCountInCurrentCommit = 0;
  3904. endMark(
  3905. "(Committing Host Effects: " + count + " Total)",
  3906. "(Committing Host Effects)",
  3907. null
  3908. );
  3909. }
  3910. }
  3911. function startCommitLifeCyclesTimer() {
  3912. {
  3913. if (!supportsUserTiming) {
  3914. return;
  3915. }
  3916. effectCountInCurrentCommit = 0;
  3917. beginMark("(Calling Lifecycle Methods)");
  3918. }
  3919. }
  3920. function stopCommitLifeCyclesTimer() {
  3921. {
  3922. if (!supportsUserTiming) {
  3923. return;
  3924. }
  3925. var count = effectCountInCurrentCommit;
  3926. effectCountInCurrentCommit = 0;
  3927. endMark(
  3928. "(Calling Lifecycle Methods: " + count + " Total)",
  3929. "(Calling Lifecycle Methods)",
  3930. null
  3931. );
  3932. }
  3933. }
  3934. var valueStack = [];
  3935. var fiberStack;
  3936. {
  3937. fiberStack = [];
  3938. }
  3939. var index = -1;
  3940. function createCursor(defaultValue) {
  3941. return {
  3942. current: defaultValue
  3943. };
  3944. }
  3945. function pop(cursor, fiber) {
  3946. if (index < 0) {
  3947. {
  3948. error("Unexpected pop.");
  3949. }
  3950. return;
  3951. }
  3952. {
  3953. if (fiber !== fiberStack[index]) {
  3954. error("Unexpected Fiber popped.");
  3955. }
  3956. }
  3957. cursor.current = valueStack[index];
  3958. valueStack[index] = null;
  3959. {
  3960. fiberStack[index] = null;
  3961. }
  3962. index--;
  3963. }
  3964. function push(cursor, value, fiber) {
  3965. index++;
  3966. valueStack[index] = cursor.current;
  3967. {
  3968. fiberStack[index] = fiber;
  3969. }
  3970. cursor.current = value;
  3971. }
  3972. var warnedAboutMissingGetChildContext;
  3973. {
  3974. warnedAboutMissingGetChildContext = {};
  3975. }
  3976. var emptyContextObject = {};
  3977. {
  3978. Object.freeze(emptyContextObject);
  3979. } // A cursor to the current merged context object on the stack.
  3980. var contextStackCursor = createCursor(emptyContextObject); // A cursor to a boolean indicating whether the context has changed.
  3981. var didPerformWorkStackCursor = createCursor(false); // Keep track of the previous context object that was on the stack.
  3982. // We use this to get access to the parent context after we have already
  3983. // pushed the next context provider, and now need to merge their contexts.
  3984. var previousContext = emptyContextObject;
  3985. function getUnmaskedContext(
  3986. workInProgress,
  3987. Component,
  3988. didPushOwnContextIfProvider
  3989. ) {
  3990. {
  3991. if (didPushOwnContextIfProvider && isContextProvider(Component)) {
  3992. // If the fiber is a context provider itself, when we read its context
  3993. // we may have already pushed its own child context on the stack. A context
  3994. // provider should not "see" its own child context. Therefore we read the
  3995. // previous (parent) context instead for a context provider.
  3996. return previousContext;
  3997. }
  3998. return contextStackCursor.current;
  3999. }
  4000. }
  4001. function cacheContext(workInProgress, unmaskedContext, maskedContext) {
  4002. {
  4003. var instance = workInProgress.stateNode;
  4004. instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
  4005. instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
  4006. }
  4007. }
  4008. function getMaskedContext(workInProgress, unmaskedContext) {
  4009. {
  4010. var type = workInProgress.type;
  4011. var contextTypes = type.contextTypes;
  4012. if (!contextTypes) {
  4013. return emptyContextObject;
  4014. } // Avoid recreating masked context unless unmasked context has changed.
  4015. // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
  4016. // This may trigger infinite loops if componentWillReceiveProps calls setState.
  4017. var instance = workInProgress.stateNode;
  4018. if (
  4019. instance &&
  4020. instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext
  4021. ) {
  4022. return instance.__reactInternalMemoizedMaskedChildContext;
  4023. }
  4024. var context = {};
  4025. for (var key in contextTypes) {
  4026. context[key] = unmaskedContext[key];
  4027. }
  4028. {
  4029. var name = getComponentName(type) || "Unknown";
  4030. checkPropTypes(contextTypes, context, "context", name);
  4031. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  4032. // Context is created before the class component is instantiated so check for instance.
  4033. if (instance) {
  4034. cacheContext(workInProgress, unmaskedContext, context);
  4035. }
  4036. return context;
  4037. }
  4038. }
  4039. function hasContextChanged() {
  4040. {
  4041. return didPerformWorkStackCursor.current;
  4042. }
  4043. }
  4044. function isContextProvider(type) {
  4045. {
  4046. var childContextTypes = type.childContextTypes;
  4047. return childContextTypes !== null && childContextTypes !== undefined;
  4048. }
  4049. }
  4050. function popContext(fiber) {
  4051. {
  4052. pop(didPerformWorkStackCursor, fiber);
  4053. pop(contextStackCursor, fiber);
  4054. }
  4055. }
  4056. function popTopLevelContextObject(fiber) {
  4057. {
  4058. pop(didPerformWorkStackCursor, fiber);
  4059. pop(contextStackCursor, fiber);
  4060. }
  4061. }
  4062. function pushTopLevelContextObject(fiber, context, didChange) {
  4063. {
  4064. if (!(contextStackCursor.current === emptyContextObject)) {
  4065. throw Error(
  4066. "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue."
  4067. );
  4068. }
  4069. push(contextStackCursor, context, fiber);
  4070. push(didPerformWorkStackCursor, didChange, fiber);
  4071. }
  4072. }
  4073. function processChildContext(fiber, type, parentContext) {
  4074. {
  4075. var instance = fiber.stateNode;
  4076. var childContextTypes = type.childContextTypes; // TODO (bvaughn) Replace this behavior with an invariant() in the future.
  4077. // It has only been added in Fiber to match the (unintentional) behavior in Stack.
  4078. if (typeof instance.getChildContext !== "function") {
  4079. {
  4080. var componentName = getComponentName(type) || "Unknown";
  4081. if (!warnedAboutMissingGetChildContext[componentName]) {
  4082. warnedAboutMissingGetChildContext[componentName] = true;
  4083. error(
  4084. "%s.childContextTypes is specified but there is no getChildContext() method " +
  4085. "on the instance. You can either define getChildContext() on %s or remove " +
  4086. "childContextTypes from it.",
  4087. componentName,
  4088. componentName
  4089. );
  4090. }
  4091. }
  4092. return parentContext;
  4093. }
  4094. var childContext;
  4095. startPhaseTimer(fiber, "getChildContext");
  4096. childContext = instance.getChildContext();
  4097. stopPhaseTimer();
  4098. for (var contextKey in childContext) {
  4099. if (!(contextKey in childContextTypes)) {
  4100. throw Error(
  4101. (getComponentName(type) || "Unknown") +
  4102. '.getChildContext(): key "' +
  4103. contextKey +
  4104. '" is not defined in childContextTypes.'
  4105. );
  4106. }
  4107. }
  4108. {
  4109. var name = getComponentName(type) || "Unknown";
  4110. checkPropTypes(childContextTypes, childContext, "child context", name);
  4111. }
  4112. return Object.assign({}, parentContext, {}, childContext);
  4113. }
  4114. }
  4115. function pushContextProvider(workInProgress) {
  4116. {
  4117. var instance = workInProgress.stateNode; // We push the context as early as possible to ensure stack integrity.
  4118. // If the instance does not exist yet, we will push null at first,
  4119. // and replace it on the stack later when invalidating the context.
  4120. var memoizedMergedChildContext =
  4121. (instance && instance.__reactInternalMemoizedMergedChildContext) ||
  4122. emptyContextObject; // Remember the parent context so we can merge with it later.
  4123. // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
  4124. previousContext = contextStackCursor.current;
  4125. push(contextStackCursor, memoizedMergedChildContext, workInProgress);
  4126. push(
  4127. didPerformWorkStackCursor,
  4128. didPerformWorkStackCursor.current,
  4129. workInProgress
  4130. );
  4131. return true;
  4132. }
  4133. }
  4134. function invalidateContextProvider(workInProgress, type, didChange) {
  4135. {
  4136. var instance = workInProgress.stateNode;
  4137. if (!instance) {
  4138. throw Error(
  4139. "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue."
  4140. );
  4141. }
  4142. if (didChange) {
  4143. // Merge parent and own context.
  4144. // Skip this if we're not updating due to sCU.
  4145. // This avoids unnecessarily recomputing memoized values.
  4146. var mergedContext = processChildContext(
  4147. workInProgress,
  4148. type,
  4149. previousContext
  4150. );
  4151. instance.__reactInternalMemoizedMergedChildContext = mergedContext; // Replace the old (or empty) context with the new one.
  4152. // It is important to unwind the context in the reverse order.
  4153. pop(didPerformWorkStackCursor, workInProgress);
  4154. pop(contextStackCursor, workInProgress); // Now push the new context and mark that it has changed.
  4155. push(contextStackCursor, mergedContext, workInProgress);
  4156. push(didPerformWorkStackCursor, didChange, workInProgress);
  4157. } else {
  4158. pop(didPerformWorkStackCursor, workInProgress);
  4159. push(didPerformWorkStackCursor, didChange, workInProgress);
  4160. }
  4161. }
  4162. }
  4163. function findCurrentUnmaskedContext(fiber) {
  4164. {
  4165. // Currently this is only used with renderSubtreeIntoContainer; not sure if it
  4166. // makes sense elsewhere
  4167. if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) {
  4168. throw Error(
  4169. "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue."
  4170. );
  4171. }
  4172. var node = fiber;
  4173. do {
  4174. switch (node.tag) {
  4175. case HostRoot:
  4176. return node.stateNode.context;
  4177. case ClassComponent: {
  4178. var Component = node.type;
  4179. if (isContextProvider(Component)) {
  4180. return node.stateNode.__reactInternalMemoizedMergedChildContext;
  4181. }
  4182. break;
  4183. }
  4184. }
  4185. node = node.return;
  4186. } while (node !== null);
  4187. {
  4188. throw Error(
  4189. "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue."
  4190. );
  4191. }
  4192. }
  4193. }
  4194. var LegacyRoot = 0;
  4195. var BlockingRoot = 1;
  4196. var ConcurrentRoot = 2;
  4197. // Intentionally not named imports because Rollup would use dynamic dispatch for
  4198. var Scheduler_runWithPriority = Scheduler.unstable_runWithPriority,
  4199. Scheduler_scheduleCallback = Scheduler.unstable_scheduleCallback,
  4200. Scheduler_cancelCallback = Scheduler.unstable_cancelCallback,
  4201. Scheduler_shouldYield = Scheduler.unstable_shouldYield,
  4202. Scheduler_requestPaint = Scheduler.unstable_requestPaint,
  4203. Scheduler_now = Scheduler.unstable_now,
  4204. Scheduler_getCurrentPriorityLevel =
  4205. Scheduler.unstable_getCurrentPriorityLevel,
  4206. Scheduler_ImmediatePriority = Scheduler.unstable_ImmediatePriority,
  4207. Scheduler_UserBlockingPriority = Scheduler.unstable_UserBlockingPriority,
  4208. Scheduler_NormalPriority = Scheduler.unstable_NormalPriority,
  4209. Scheduler_LowPriority = Scheduler.unstable_LowPriority,
  4210. Scheduler_IdlePriority = Scheduler.unstable_IdlePriority;
  4211. {
  4212. // Provide explicit error message when production+profiling bundle of e.g.
  4213. // react-dom is used with production (non-profiling) bundle of
  4214. // scheduler/tracing
  4215. if (
  4216. !(
  4217. tracing.__interactionsRef != null &&
  4218. tracing.__interactionsRef.current != null
  4219. )
  4220. ) {
  4221. throw Error(
  4222. "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"
  4223. );
  4224. }
  4225. }
  4226. var fakeCallbackNode = {}; // Except for NoPriority, these correspond to Scheduler priorities. We use
  4227. // ascending numbers so we can compare them like numbers. They start at 90 to
  4228. // avoid clashing with Scheduler's priorities.
  4229. var ImmediatePriority = 99;
  4230. var UserBlockingPriority = 98;
  4231. var NormalPriority = 97;
  4232. var LowPriority = 96;
  4233. var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only.
  4234. var NoPriority = 90;
  4235. var shouldYield = Scheduler_shouldYield;
  4236. var requestPaint = // Fall back gracefully if we're running an older version of Scheduler.
  4237. Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : function() {};
  4238. var syncQueue = null;
  4239. var immediateQueueCallbackNode = null;
  4240. var isFlushingSyncQueue = false;
  4241. var initialTimeMs = Scheduler_now(); // If the initial timestamp is reasonably small, use Scheduler's `now` directly.
  4242. // This will be the case for modern browsers that support `performance.now`. In
  4243. // older browsers, Scheduler falls back to `Date.now`, which returns a Unix
  4244. // timestamp. In that case, subtract the module initialization time to simulate
  4245. // the behavior of performance.now and keep our times small enough to fit
  4246. // within 32 bits.
  4247. // TODO: Consider lifting this into Scheduler.
  4248. var now =
  4249. initialTimeMs < 10000
  4250. ? Scheduler_now
  4251. : function() {
  4252. return Scheduler_now() - initialTimeMs;
  4253. };
  4254. function getCurrentPriorityLevel() {
  4255. switch (Scheduler_getCurrentPriorityLevel()) {
  4256. case Scheduler_ImmediatePriority:
  4257. return ImmediatePriority;
  4258. case Scheduler_UserBlockingPriority:
  4259. return UserBlockingPriority;
  4260. case Scheduler_NormalPriority:
  4261. return NormalPriority;
  4262. case Scheduler_LowPriority:
  4263. return LowPriority;
  4264. case Scheduler_IdlePriority:
  4265. return IdlePriority;
  4266. default: {
  4267. throw Error("Unknown priority level.");
  4268. }
  4269. }
  4270. }
  4271. function reactPriorityToSchedulerPriority(reactPriorityLevel) {
  4272. switch (reactPriorityLevel) {
  4273. case ImmediatePriority:
  4274. return Scheduler_ImmediatePriority;
  4275. case UserBlockingPriority:
  4276. return Scheduler_UserBlockingPriority;
  4277. case NormalPriority:
  4278. return Scheduler_NormalPriority;
  4279. case LowPriority:
  4280. return Scheduler_LowPriority;
  4281. case IdlePriority:
  4282. return Scheduler_IdlePriority;
  4283. default: {
  4284. throw Error("Unknown priority level.");
  4285. }
  4286. }
  4287. }
  4288. function runWithPriority(reactPriorityLevel, fn) {
  4289. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  4290. return Scheduler_runWithPriority(priorityLevel, fn);
  4291. }
  4292. function scheduleCallback(reactPriorityLevel, callback, options) {
  4293. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  4294. return Scheduler_scheduleCallback(priorityLevel, callback, options);
  4295. }
  4296. function scheduleSyncCallback(callback) {
  4297. // Push this callback into an internal queue. We'll flush these either in
  4298. // the next tick, or earlier if something calls `flushSyncCallbackQueue`.
  4299. if (syncQueue === null) {
  4300. syncQueue = [callback]; // Flush the queue in the next tick, at the earliest.
  4301. immediateQueueCallbackNode = Scheduler_scheduleCallback(
  4302. Scheduler_ImmediatePriority,
  4303. flushSyncCallbackQueueImpl
  4304. );
  4305. } else {
  4306. // Push onto existing queue. Don't need to schedule a callback because
  4307. // we already scheduled one when we created the queue.
  4308. syncQueue.push(callback);
  4309. }
  4310. return fakeCallbackNode;
  4311. }
  4312. function cancelCallback(callbackNode) {
  4313. if (callbackNode !== fakeCallbackNode) {
  4314. Scheduler_cancelCallback(callbackNode);
  4315. }
  4316. }
  4317. function flushSyncCallbackQueue() {
  4318. if (immediateQueueCallbackNode !== null) {
  4319. var node = immediateQueueCallbackNode;
  4320. immediateQueueCallbackNode = null;
  4321. Scheduler_cancelCallback(node);
  4322. }
  4323. flushSyncCallbackQueueImpl();
  4324. }
  4325. function flushSyncCallbackQueueImpl() {
  4326. if (!isFlushingSyncQueue && syncQueue !== null) {
  4327. // Prevent re-entrancy.
  4328. isFlushingSyncQueue = true;
  4329. var i = 0;
  4330. try {
  4331. var _isSync = true;
  4332. var queue = syncQueue;
  4333. runWithPriority(ImmediatePriority, function() {
  4334. for (; i < queue.length; i++) {
  4335. var callback = queue[i];
  4336. do {
  4337. callback = callback(_isSync);
  4338. } while (callback !== null);
  4339. }
  4340. });
  4341. syncQueue = null;
  4342. } catch (error) {
  4343. // If something throws, leave the remaining callbacks on the queue.
  4344. if (syncQueue !== null) {
  4345. syncQueue = syncQueue.slice(i + 1);
  4346. } // Resume flushing in the next tick
  4347. Scheduler_scheduleCallback(
  4348. Scheduler_ImmediatePriority,
  4349. flushSyncCallbackQueue
  4350. );
  4351. throw error;
  4352. } finally {
  4353. isFlushingSyncQueue = false;
  4354. }
  4355. }
  4356. }
  4357. var NoMode = 0;
  4358. var StrictMode = 1; // TODO: Remove BlockingMode and ConcurrentMode by reading from the root
  4359. // tag instead
  4360. var BlockingMode = 2;
  4361. var ConcurrentMode = 4;
  4362. var ProfileMode = 8;
  4363. // Max 31 bit integer. The max integer size in V8 for 32-bit systems.
  4364. // Math.pow(2, 30) - 1
  4365. // 0b111111111111111111111111111111
  4366. var MAX_SIGNED_31_BIT_INT = 1073741823;
  4367. var NoWork = 0; // TODO: Think of a better name for Never. The key difference with Idle is that
  4368. // Never work can be committed in an inconsistent state without tearing the UI.
  4369. // The main example is offscreen content, like a hidden subtree. So one possible
  4370. // name is Offscreen. However, it also includes dehydrated Suspense boundaries,
  4371. // which are inconsistent in the sense that they haven't finished yet, but
  4372. // aren't visibly inconsistent because the server rendered HTML matches what the
  4373. // hydrated tree would look like.
  4374. var Never = 1; // Idle is slightly higher priority than Never. It must completely finish in
  4375. // order to be consistent.
  4376. var Idle = 2; // Continuous Hydration is slightly higher than Idle and is used to increase
  4377. var Sync = MAX_SIGNED_31_BIT_INT;
  4378. var Batched = Sync - 1;
  4379. var UNIT_SIZE = 10;
  4380. var MAGIC_NUMBER_OFFSET = Batched - 1; // 1 unit of expiration time represents 10ms.
  4381. function msToExpirationTime(ms) {
  4382. // Always subtract from the offset so that we don't clash with the magic number for NoWork.
  4383. return MAGIC_NUMBER_OFFSET - ((ms / UNIT_SIZE) | 0);
  4384. }
  4385. function expirationTimeToMs(expirationTime) {
  4386. return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
  4387. }
  4388. function ceiling(num, precision) {
  4389. return (((num / precision) | 0) + 1) * precision;
  4390. }
  4391. function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
  4392. return (
  4393. MAGIC_NUMBER_OFFSET -
  4394. ceiling(
  4395. MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE,
  4396. bucketSizeMs / UNIT_SIZE
  4397. )
  4398. );
  4399. } // TODO: This corresponds to Scheduler's NormalPriority, not LowPriority. Update
  4400. // the names to reflect.
  4401. var LOW_PRIORITY_EXPIRATION = 5000;
  4402. var LOW_PRIORITY_BATCH_SIZE = 250;
  4403. function computeAsyncExpiration(currentTime) {
  4404. return computeExpirationBucket(
  4405. currentTime,
  4406. LOW_PRIORITY_EXPIRATION,
  4407. LOW_PRIORITY_BATCH_SIZE
  4408. );
  4409. }
  4410. function computeSuspenseExpiration(currentTime, timeoutMs) {
  4411. // TODO: Should we warn if timeoutMs is lower than the normal pri expiration time?
  4412. return computeExpirationBucket(
  4413. currentTime,
  4414. timeoutMs,
  4415. LOW_PRIORITY_BATCH_SIZE
  4416. );
  4417. } // We intentionally set a higher expiration time for interactive updates in
  4418. // dev than in production.
  4419. //
  4420. // If the main thread is being blocked so long that you hit the expiration,
  4421. // it's a problem that could be solved with better scheduling.
  4422. //
  4423. // People will be more likely to notice this and fix it with the long
  4424. // expiration time in development.
  4425. //
  4426. // In production we opt for better UX at the risk of masking scheduling
  4427. // problems, by expiring fast.
  4428. var HIGH_PRIORITY_EXPIRATION = 500;
  4429. var HIGH_PRIORITY_BATCH_SIZE = 100;
  4430. function computeInteractiveExpiration(currentTime) {
  4431. return computeExpirationBucket(
  4432. currentTime,
  4433. HIGH_PRIORITY_EXPIRATION,
  4434. HIGH_PRIORITY_BATCH_SIZE
  4435. );
  4436. }
  4437. function inferPriorityFromExpirationTime(currentTime, expirationTime) {
  4438. if (expirationTime === Sync) {
  4439. return ImmediatePriority;
  4440. }
  4441. if (expirationTime === Never || expirationTime === Idle) {
  4442. return IdlePriority;
  4443. }
  4444. var msUntil =
  4445. expirationTimeToMs(expirationTime) - expirationTimeToMs(currentTime);
  4446. if (msUntil <= 0) {
  4447. return ImmediatePriority;
  4448. }
  4449. if (msUntil <= HIGH_PRIORITY_EXPIRATION + HIGH_PRIORITY_BATCH_SIZE) {
  4450. return UserBlockingPriority;
  4451. }
  4452. if (msUntil <= LOW_PRIORITY_EXPIRATION + LOW_PRIORITY_BATCH_SIZE) {
  4453. return NormalPriority;
  4454. } // TODO: Handle LowPriority
  4455. // Assume anything lower has idle priority
  4456. return IdlePriority;
  4457. }
  4458. /**
  4459. * inlined Object.is polyfill to avoid requiring consumers ship their own
  4460. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  4461. */
  4462. function is(x, y) {
  4463. return (
  4464. (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare
  4465. );
  4466. }
  4467. var objectIs = typeof Object.is === "function" ? Object.is : is;
  4468. var hasOwnProperty = Object.prototype.hasOwnProperty;
  4469. /**
  4470. * Performs equality by iterating through keys on an object and returning false
  4471. * when any key has values which are not strictly equal between the arguments.
  4472. * Returns true when the values of all keys are strictly equal.
  4473. */
  4474. function shallowEqual(objA, objB) {
  4475. if (objectIs(objA, objB)) {
  4476. return true;
  4477. }
  4478. if (
  4479. typeof objA !== "object" ||
  4480. objA === null ||
  4481. typeof objB !== "object" ||
  4482. objB === null
  4483. ) {
  4484. return false;
  4485. }
  4486. var keysA = Object.keys(objA);
  4487. var keysB = Object.keys(objB);
  4488. if (keysA.length !== keysB.length) {
  4489. return false;
  4490. } // Test for A's keys different from B.
  4491. for (var i = 0; i < keysA.length; i++) {
  4492. if (
  4493. !hasOwnProperty.call(objB, keysA[i]) ||
  4494. !objectIs(objA[keysA[i]], objB[keysA[i]])
  4495. ) {
  4496. return false;
  4497. }
  4498. }
  4499. return true;
  4500. }
  4501. var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
  4502. function describeComponentFrame(name, source, ownerName) {
  4503. var sourceInfo = "";
  4504. if (source) {
  4505. var path = source.fileName;
  4506. var fileName = path.replace(BEFORE_SLASH_RE, "");
  4507. {
  4508. // In DEV, include code for a common special case:
  4509. // prefer "folder/index.js" instead of just "index.js".
  4510. if (/^index\./.test(fileName)) {
  4511. var match = path.match(BEFORE_SLASH_RE);
  4512. if (match) {
  4513. var pathBeforeSlash = match[1];
  4514. if (pathBeforeSlash) {
  4515. var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, "");
  4516. fileName = folderName + "/" + fileName;
  4517. }
  4518. }
  4519. }
  4520. }
  4521. sourceInfo = " (at " + fileName + ":" + source.lineNumber + ")";
  4522. } else if (ownerName) {
  4523. sourceInfo = " (created by " + ownerName + ")";
  4524. }
  4525. return "\n in " + (name || "Unknown") + sourceInfo;
  4526. }
  4527. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  4528. function describeFiber(fiber) {
  4529. switch (fiber.tag) {
  4530. case HostRoot:
  4531. case HostPortal:
  4532. case HostText:
  4533. case Fragment:
  4534. case ContextProvider:
  4535. case ContextConsumer:
  4536. return "";
  4537. default:
  4538. var owner = fiber._debugOwner;
  4539. var source = fiber._debugSource;
  4540. var name = getComponentName(fiber.type);
  4541. var ownerName = null;
  4542. if (owner) {
  4543. ownerName = getComponentName(owner.type);
  4544. }
  4545. return describeComponentFrame(name, source, ownerName);
  4546. }
  4547. }
  4548. function getStackByFiberInDevAndProd(workInProgress) {
  4549. var info = "";
  4550. var node = workInProgress;
  4551. do {
  4552. info += describeFiber(node);
  4553. node = node.return;
  4554. } while (node);
  4555. return info;
  4556. }
  4557. var current = null;
  4558. var isRendering = false;
  4559. function getCurrentFiberOwnerNameInDevOrNull() {
  4560. {
  4561. if (current === null) {
  4562. return null;
  4563. }
  4564. var owner = current._debugOwner;
  4565. if (owner !== null && typeof owner !== "undefined") {
  4566. return getComponentName(owner.type);
  4567. }
  4568. }
  4569. return null;
  4570. }
  4571. function getCurrentFiberStackInDev() {
  4572. {
  4573. if (current === null) {
  4574. return "";
  4575. } // Safe because if current fiber exists, we are reconciling,
  4576. // and it is guaranteed to be the work-in-progress version.
  4577. return getStackByFiberInDevAndProd(current);
  4578. }
  4579. }
  4580. function resetCurrentFiber() {
  4581. {
  4582. ReactDebugCurrentFrame.getCurrentStack = null;
  4583. current = null;
  4584. isRendering = false;
  4585. }
  4586. }
  4587. function setCurrentFiber(fiber) {
  4588. {
  4589. ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
  4590. current = fiber;
  4591. isRendering = false;
  4592. }
  4593. }
  4594. function setIsRendering(rendering) {
  4595. {
  4596. isRendering = rendering;
  4597. }
  4598. }
  4599. var ReactStrictModeWarnings = {
  4600. recordUnsafeLifecycleWarnings: function(fiber, instance) {},
  4601. flushPendingUnsafeLifecycleWarnings: function() {},
  4602. recordLegacyContextWarning: function(fiber, instance) {},
  4603. flushLegacyContextWarning: function() {},
  4604. discardPendingWarnings: function() {}
  4605. };
  4606. {
  4607. var findStrictRoot = function(fiber) {
  4608. var maybeStrictRoot = null;
  4609. var node = fiber;
  4610. while (node !== null) {
  4611. if (node.mode & StrictMode) {
  4612. maybeStrictRoot = node;
  4613. }
  4614. node = node.return;
  4615. }
  4616. return maybeStrictRoot;
  4617. };
  4618. var setToSortedString = function(set) {
  4619. var array = [];
  4620. set.forEach(function(value) {
  4621. array.push(value);
  4622. });
  4623. return array.sort().join(", ");
  4624. };
  4625. var pendingComponentWillMountWarnings = [];
  4626. var pendingUNSAFE_ComponentWillMountWarnings = [];
  4627. var pendingComponentWillReceivePropsWarnings = [];
  4628. var pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  4629. var pendingComponentWillUpdateWarnings = [];
  4630. var pendingUNSAFE_ComponentWillUpdateWarnings = []; // Tracks components we have already warned about.
  4631. var didWarnAboutUnsafeLifecycles = new Set();
  4632. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function(
  4633. fiber,
  4634. instance
  4635. ) {
  4636. // Dedup strategy: Warn once per component.
  4637. if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
  4638. return;
  4639. }
  4640. if (
  4641. typeof instance.componentWillMount === "function" && // Don't warn about react-lifecycles-compat polyfilled components.
  4642. instance.componentWillMount.__suppressDeprecationWarning !== true
  4643. ) {
  4644. pendingComponentWillMountWarnings.push(fiber);
  4645. }
  4646. if (
  4647. fiber.mode & StrictMode &&
  4648. typeof instance.UNSAFE_componentWillMount === "function"
  4649. ) {
  4650. pendingUNSAFE_ComponentWillMountWarnings.push(fiber);
  4651. }
  4652. if (
  4653. typeof instance.componentWillReceiveProps === "function" &&
  4654. instance.componentWillReceiveProps.__suppressDeprecationWarning !== true
  4655. ) {
  4656. pendingComponentWillReceivePropsWarnings.push(fiber);
  4657. }
  4658. if (
  4659. fiber.mode & StrictMode &&
  4660. typeof instance.UNSAFE_componentWillReceiveProps === "function"
  4661. ) {
  4662. pendingUNSAFE_ComponentWillReceivePropsWarnings.push(fiber);
  4663. }
  4664. if (
  4665. typeof instance.componentWillUpdate === "function" &&
  4666. instance.componentWillUpdate.__suppressDeprecationWarning !== true
  4667. ) {
  4668. pendingComponentWillUpdateWarnings.push(fiber);
  4669. }
  4670. if (
  4671. fiber.mode & StrictMode &&
  4672. typeof instance.UNSAFE_componentWillUpdate === "function"
  4673. ) {
  4674. pendingUNSAFE_ComponentWillUpdateWarnings.push(fiber);
  4675. }
  4676. };
  4677. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function() {
  4678. // We do an initial pass to gather component names
  4679. var componentWillMountUniqueNames = new Set();
  4680. if (pendingComponentWillMountWarnings.length > 0) {
  4681. pendingComponentWillMountWarnings.forEach(function(fiber) {
  4682. componentWillMountUniqueNames.add(
  4683. getComponentName(fiber.type) || "Component"
  4684. );
  4685. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4686. });
  4687. pendingComponentWillMountWarnings = [];
  4688. }
  4689. var UNSAFE_componentWillMountUniqueNames = new Set();
  4690. if (pendingUNSAFE_ComponentWillMountWarnings.length > 0) {
  4691. pendingUNSAFE_ComponentWillMountWarnings.forEach(function(fiber) {
  4692. UNSAFE_componentWillMountUniqueNames.add(
  4693. getComponentName(fiber.type) || "Component"
  4694. );
  4695. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4696. });
  4697. pendingUNSAFE_ComponentWillMountWarnings = [];
  4698. }
  4699. var componentWillReceivePropsUniqueNames = new Set();
  4700. if (pendingComponentWillReceivePropsWarnings.length > 0) {
  4701. pendingComponentWillReceivePropsWarnings.forEach(function(fiber) {
  4702. componentWillReceivePropsUniqueNames.add(
  4703. getComponentName(fiber.type) || "Component"
  4704. );
  4705. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4706. });
  4707. pendingComponentWillReceivePropsWarnings = [];
  4708. }
  4709. var UNSAFE_componentWillReceivePropsUniqueNames = new Set();
  4710. if (pendingUNSAFE_ComponentWillReceivePropsWarnings.length > 0) {
  4711. pendingUNSAFE_ComponentWillReceivePropsWarnings.forEach(function(fiber) {
  4712. UNSAFE_componentWillReceivePropsUniqueNames.add(
  4713. getComponentName(fiber.type) || "Component"
  4714. );
  4715. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4716. });
  4717. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  4718. }
  4719. var componentWillUpdateUniqueNames = new Set();
  4720. if (pendingComponentWillUpdateWarnings.length > 0) {
  4721. pendingComponentWillUpdateWarnings.forEach(function(fiber) {
  4722. componentWillUpdateUniqueNames.add(
  4723. getComponentName(fiber.type) || "Component"
  4724. );
  4725. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4726. });
  4727. pendingComponentWillUpdateWarnings = [];
  4728. }
  4729. var UNSAFE_componentWillUpdateUniqueNames = new Set();
  4730. if (pendingUNSAFE_ComponentWillUpdateWarnings.length > 0) {
  4731. pendingUNSAFE_ComponentWillUpdateWarnings.forEach(function(fiber) {
  4732. UNSAFE_componentWillUpdateUniqueNames.add(
  4733. getComponentName(fiber.type) || "Component"
  4734. );
  4735. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4736. });
  4737. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  4738. } // Finally, we flush all the warnings
  4739. // UNSAFE_ ones before the deprecated ones, since they'll be 'louder'
  4740. if (UNSAFE_componentWillMountUniqueNames.size > 0) {
  4741. var sortedNames = setToSortedString(UNSAFE_componentWillMountUniqueNames);
  4742. error(
  4743. "Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. " +
  4744. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  4745. "* Move code with side effects to componentDidMount, and set initial state in the constructor.\n" +
  4746. "\nPlease update the following components: %s",
  4747. sortedNames
  4748. );
  4749. }
  4750. if (UNSAFE_componentWillReceivePropsUniqueNames.size > 0) {
  4751. var _sortedNames = setToSortedString(
  4752. UNSAFE_componentWillReceivePropsUniqueNames
  4753. );
  4754. error(
  4755. "Using UNSAFE_componentWillReceiveProps in strict mode is not recommended " +
  4756. "and may indicate bugs in your code. " +
  4757. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  4758. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  4759. "* If you're updating state whenever props change, " +
  4760. "refactor your code to use memoization techniques or move it to " +
  4761. "static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state\n" +
  4762. "\nPlease update the following components: %s",
  4763. _sortedNames
  4764. );
  4765. }
  4766. if (UNSAFE_componentWillUpdateUniqueNames.size > 0) {
  4767. var _sortedNames2 = setToSortedString(
  4768. UNSAFE_componentWillUpdateUniqueNames
  4769. );
  4770. error(
  4771. "Using UNSAFE_componentWillUpdate in strict mode is not recommended " +
  4772. "and may indicate bugs in your code. " +
  4773. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  4774. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  4775. "\nPlease update the following components: %s",
  4776. _sortedNames2
  4777. );
  4778. }
  4779. if (componentWillMountUniqueNames.size > 0) {
  4780. var _sortedNames3 = setToSortedString(componentWillMountUniqueNames);
  4781. warn(
  4782. "componentWillMount has been renamed, and is not recommended for use. " +
  4783. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  4784. "* Move code with side effects to componentDidMount, and set initial state in the constructor.\n" +
  4785. "* Rename componentWillMount to UNSAFE_componentWillMount to suppress " +
  4786. "this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. " +
  4787. "To rename all deprecated lifecycles to their new names, you can run " +
  4788. "`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n" +
  4789. "\nPlease update the following components: %s",
  4790. _sortedNames3
  4791. );
  4792. }
  4793. if (componentWillReceivePropsUniqueNames.size > 0) {
  4794. var _sortedNames4 = setToSortedString(
  4795. componentWillReceivePropsUniqueNames
  4796. );
  4797. warn(
  4798. "componentWillReceiveProps has been renamed, and is not recommended for use. " +
  4799. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  4800. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  4801. "* If you're updating state whenever props change, refactor your " +
  4802. "code to use memoization techniques or move it to " +
  4803. "static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state\n" +
  4804. "* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress " +
  4805. "this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. " +
  4806. "To rename all deprecated lifecycles to their new names, you can run " +
  4807. "`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n" +
  4808. "\nPlease update the following components: %s",
  4809. _sortedNames4
  4810. );
  4811. }
  4812. if (componentWillUpdateUniqueNames.size > 0) {
  4813. var _sortedNames5 = setToSortedString(componentWillUpdateUniqueNames);
  4814. warn(
  4815. "componentWillUpdate has been renamed, and is not recommended for use. " +
  4816. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  4817. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  4818. "* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress " +
  4819. "this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. " +
  4820. "To rename all deprecated lifecycles to their new names, you can run " +
  4821. "`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n" +
  4822. "\nPlease update the following components: %s",
  4823. _sortedNames5
  4824. );
  4825. }
  4826. };
  4827. var pendingLegacyContextWarning = new Map(); // Tracks components we have already warned about.
  4828. var didWarnAboutLegacyContext = new Set();
  4829. ReactStrictModeWarnings.recordLegacyContextWarning = function(
  4830. fiber,
  4831. instance
  4832. ) {
  4833. var strictRoot = findStrictRoot(fiber);
  4834. if (strictRoot === null) {
  4835. error(
  4836. "Expected to find a StrictMode component in a strict mode tree. " +
  4837. "This error is likely caused by a bug in React. Please file an issue."
  4838. );
  4839. return;
  4840. } // Dedup strategy: Warn once per component.
  4841. if (didWarnAboutLegacyContext.has(fiber.type)) {
  4842. return;
  4843. }
  4844. var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
  4845. if (
  4846. fiber.type.contextTypes != null ||
  4847. fiber.type.childContextTypes != null ||
  4848. (instance !== null && typeof instance.getChildContext === "function")
  4849. ) {
  4850. if (warningsForRoot === undefined) {
  4851. warningsForRoot = [];
  4852. pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
  4853. }
  4854. warningsForRoot.push(fiber);
  4855. }
  4856. };
  4857. ReactStrictModeWarnings.flushLegacyContextWarning = function() {
  4858. pendingLegacyContextWarning.forEach(function(fiberArray, strictRoot) {
  4859. if (fiberArray.length === 0) {
  4860. return;
  4861. }
  4862. var firstFiber = fiberArray[0];
  4863. var uniqueNames = new Set();
  4864. fiberArray.forEach(function(fiber) {
  4865. uniqueNames.add(getComponentName(fiber.type) || "Component");
  4866. didWarnAboutLegacyContext.add(fiber.type);
  4867. });
  4868. var sortedNames = setToSortedString(uniqueNames);
  4869. var firstComponentStack = getStackByFiberInDevAndProd(firstFiber);
  4870. error(
  4871. "Legacy context API has been detected within a strict-mode tree." +
  4872. "\n\nThe old API will be supported in all 16.x releases, but applications " +
  4873. "using it should migrate to the new version." +
  4874. "\n\nPlease update the following components: %s" +
  4875. "\n\nLearn more about this warning here: https://fb.me/react-legacy-context" +
  4876. "%s",
  4877. sortedNames,
  4878. firstComponentStack
  4879. );
  4880. });
  4881. };
  4882. ReactStrictModeWarnings.discardPendingWarnings = function() {
  4883. pendingComponentWillMountWarnings = [];
  4884. pendingUNSAFE_ComponentWillMountWarnings = [];
  4885. pendingComponentWillReceivePropsWarnings = [];
  4886. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  4887. pendingComponentWillUpdateWarnings = [];
  4888. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  4889. pendingLegacyContextWarning = new Map();
  4890. };
  4891. }
  4892. var resolveFamily = null; // $FlowFixMe Flow gets confused by a WeakSet feature check below.
  4893. var failedBoundaries = null;
  4894. var setRefreshHandler = function(handler) {
  4895. {
  4896. resolveFamily = handler;
  4897. }
  4898. };
  4899. function resolveFunctionForHotReloading(type) {
  4900. {
  4901. if (resolveFamily === null) {
  4902. // Hot reloading is disabled.
  4903. return type;
  4904. }
  4905. var family = resolveFamily(type);
  4906. if (family === undefined) {
  4907. return type;
  4908. } // Use the latest known implementation.
  4909. return family.current;
  4910. }
  4911. }
  4912. function resolveClassForHotReloading(type) {
  4913. // No implementation differences.
  4914. return resolveFunctionForHotReloading(type);
  4915. }
  4916. function resolveForwardRefForHotReloading(type) {
  4917. {
  4918. if (resolveFamily === null) {
  4919. // Hot reloading is disabled.
  4920. return type;
  4921. }
  4922. var family = resolveFamily(type);
  4923. if (family === undefined) {
  4924. // Check if we're dealing with a real forwardRef. Don't want to crash early.
  4925. if (
  4926. type !== null &&
  4927. type !== undefined &&
  4928. typeof type.render === "function"
  4929. ) {
  4930. // ForwardRef is special because its resolved .type is an object,
  4931. // but it's possible that we only have its inner render function in the map.
  4932. // If that inner render function is different, we'll build a new forwardRef type.
  4933. var currentRender = resolveFunctionForHotReloading(type.render);
  4934. if (type.render !== currentRender) {
  4935. var syntheticType = {
  4936. $$typeof: REACT_FORWARD_REF_TYPE,
  4937. render: currentRender
  4938. };
  4939. if (type.displayName !== undefined) {
  4940. syntheticType.displayName = type.displayName;
  4941. }
  4942. return syntheticType;
  4943. }
  4944. }
  4945. return type;
  4946. } // Use the latest known implementation.
  4947. return family.current;
  4948. }
  4949. }
  4950. function isCompatibleFamilyForHotReloading(fiber, element) {
  4951. {
  4952. if (resolveFamily === null) {
  4953. // Hot reloading is disabled.
  4954. return false;
  4955. }
  4956. var prevType = fiber.elementType;
  4957. var nextType = element.type; // If we got here, we know types aren't === equal.
  4958. var needsCompareFamilies = false;
  4959. var $$typeofNextType =
  4960. typeof nextType === "object" && nextType !== null
  4961. ? nextType.$$typeof
  4962. : null;
  4963. switch (fiber.tag) {
  4964. case ClassComponent: {
  4965. if (typeof nextType === "function") {
  4966. needsCompareFamilies = true;
  4967. }
  4968. break;
  4969. }
  4970. case FunctionComponent: {
  4971. if (typeof nextType === "function") {
  4972. needsCompareFamilies = true;
  4973. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  4974. // We don't know the inner type yet.
  4975. // We're going to assume that the lazy inner type is stable,
  4976. // and so it is sufficient to avoid reconciling it away.
  4977. // We're not going to unwrap or actually use the new lazy type.
  4978. needsCompareFamilies = true;
  4979. }
  4980. break;
  4981. }
  4982. case ForwardRef: {
  4983. if ($$typeofNextType === REACT_FORWARD_REF_TYPE) {
  4984. needsCompareFamilies = true;
  4985. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  4986. needsCompareFamilies = true;
  4987. }
  4988. break;
  4989. }
  4990. case MemoComponent:
  4991. case SimpleMemoComponent: {
  4992. if ($$typeofNextType === REACT_MEMO_TYPE) {
  4993. // TODO: if it was but can no longer be simple,
  4994. // we shouldn't set this.
  4995. needsCompareFamilies = true;
  4996. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  4997. needsCompareFamilies = true;
  4998. }
  4999. break;
  5000. }
  5001. default:
  5002. return false;
  5003. } // Check if both types have a family and it's the same one.
  5004. if (needsCompareFamilies) {
  5005. // Note: memo() and forwardRef() we'll compare outer rather than inner type.
  5006. // This means both of them need to be registered to preserve state.
  5007. // If we unwrapped and compared the inner types for wrappers instead,
  5008. // then we would risk falsely saying two separate memo(Foo)
  5009. // calls are equivalent because they wrap the same Foo function.
  5010. var prevFamily = resolveFamily(prevType);
  5011. if (prevFamily !== undefined && prevFamily === resolveFamily(nextType)) {
  5012. return true;
  5013. }
  5014. }
  5015. return false;
  5016. }
  5017. }
  5018. function markFailedErrorBoundaryForHotReloading(fiber) {
  5019. {
  5020. if (resolveFamily === null) {
  5021. // Hot reloading is disabled.
  5022. return;
  5023. }
  5024. if (typeof WeakSet !== "function") {
  5025. return;
  5026. }
  5027. if (failedBoundaries === null) {
  5028. failedBoundaries = new WeakSet();
  5029. }
  5030. failedBoundaries.add(fiber);
  5031. }
  5032. }
  5033. var scheduleRefresh = function(root, update) {
  5034. {
  5035. if (resolveFamily === null) {
  5036. // Hot reloading is disabled.
  5037. return;
  5038. }
  5039. var staleFamilies = update.staleFamilies,
  5040. updatedFamilies = update.updatedFamilies;
  5041. flushPassiveEffects();
  5042. flushSync(function() {
  5043. scheduleFibersWithFamiliesRecursively(
  5044. root.current,
  5045. updatedFamilies,
  5046. staleFamilies
  5047. );
  5048. });
  5049. }
  5050. };
  5051. var scheduleRoot = function(root, element) {
  5052. {
  5053. if (root.context !== emptyContextObject) {
  5054. // Super edge case: root has a legacy _renderSubtree context
  5055. // but we don't know the parentComponent so we can't pass it.
  5056. // Just ignore. We'll delete this with _renderSubtree code path later.
  5057. return;
  5058. }
  5059. flushPassiveEffects();
  5060. syncUpdates(function() {
  5061. updateContainer(element, root, null, null);
  5062. });
  5063. }
  5064. };
  5065. function scheduleFibersWithFamiliesRecursively(
  5066. fiber,
  5067. updatedFamilies,
  5068. staleFamilies
  5069. ) {
  5070. {
  5071. var alternate = fiber.alternate,
  5072. child = fiber.child,
  5073. sibling = fiber.sibling,
  5074. tag = fiber.tag,
  5075. type = fiber.type;
  5076. var candidateType = null;
  5077. switch (tag) {
  5078. case FunctionComponent:
  5079. case SimpleMemoComponent:
  5080. case ClassComponent:
  5081. candidateType = type;
  5082. break;
  5083. case ForwardRef:
  5084. candidateType = type.render;
  5085. break;
  5086. }
  5087. if (resolveFamily === null) {
  5088. throw new Error("Expected resolveFamily to be set during hot reload.");
  5089. }
  5090. var needsRender = false;
  5091. var needsRemount = false;
  5092. if (candidateType !== null) {
  5093. var family = resolveFamily(candidateType);
  5094. if (family !== undefined) {
  5095. if (staleFamilies.has(family)) {
  5096. needsRemount = true;
  5097. } else if (updatedFamilies.has(family)) {
  5098. if (tag === ClassComponent) {
  5099. needsRemount = true;
  5100. } else {
  5101. needsRender = true;
  5102. }
  5103. }
  5104. }
  5105. }
  5106. if (failedBoundaries !== null) {
  5107. if (
  5108. failedBoundaries.has(fiber) ||
  5109. (alternate !== null && failedBoundaries.has(alternate))
  5110. ) {
  5111. needsRemount = true;
  5112. }
  5113. }
  5114. if (needsRemount) {
  5115. fiber._debugNeedsRemount = true;
  5116. }
  5117. if (needsRemount || needsRender) {
  5118. scheduleWork(fiber, Sync);
  5119. }
  5120. if (child !== null && !needsRemount) {
  5121. scheduleFibersWithFamiliesRecursively(
  5122. child,
  5123. updatedFamilies,
  5124. staleFamilies
  5125. );
  5126. }
  5127. if (sibling !== null) {
  5128. scheduleFibersWithFamiliesRecursively(
  5129. sibling,
  5130. updatedFamilies,
  5131. staleFamilies
  5132. );
  5133. }
  5134. }
  5135. }
  5136. var findHostInstancesForRefresh = function(root, families) {
  5137. {
  5138. var hostInstances = new Set();
  5139. var types = new Set(
  5140. families.map(function(family) {
  5141. return family.current;
  5142. })
  5143. );
  5144. findHostInstancesForMatchingFibersRecursively(
  5145. root.current,
  5146. types,
  5147. hostInstances
  5148. );
  5149. return hostInstances;
  5150. }
  5151. };
  5152. function findHostInstancesForMatchingFibersRecursively(
  5153. fiber,
  5154. types,
  5155. hostInstances
  5156. ) {
  5157. {
  5158. var child = fiber.child,
  5159. sibling = fiber.sibling,
  5160. tag = fiber.tag,
  5161. type = fiber.type;
  5162. var candidateType = null;
  5163. switch (tag) {
  5164. case FunctionComponent:
  5165. case SimpleMemoComponent:
  5166. case ClassComponent:
  5167. candidateType = type;
  5168. break;
  5169. case ForwardRef:
  5170. candidateType = type.render;
  5171. break;
  5172. }
  5173. var didMatch = false;
  5174. if (candidateType !== null) {
  5175. if (types.has(candidateType)) {
  5176. didMatch = true;
  5177. }
  5178. }
  5179. if (didMatch) {
  5180. // We have a match. This only drills down to the closest host components.
  5181. // There's no need to search deeper because for the purpose of giving
  5182. // visual feedback, "flashing" outermost parent rectangles is sufficient.
  5183. findHostInstancesForFiberShallowly(fiber, hostInstances);
  5184. } else {
  5185. // If there's no match, maybe there will be one further down in the child tree.
  5186. if (child !== null) {
  5187. findHostInstancesForMatchingFibersRecursively(
  5188. child,
  5189. types,
  5190. hostInstances
  5191. );
  5192. }
  5193. }
  5194. if (sibling !== null) {
  5195. findHostInstancesForMatchingFibersRecursively(
  5196. sibling,
  5197. types,
  5198. hostInstances
  5199. );
  5200. }
  5201. }
  5202. }
  5203. function findHostInstancesForFiberShallowly(fiber, hostInstances) {
  5204. {
  5205. var foundHostInstances = findChildHostInstancesForFiberShallowly(
  5206. fiber,
  5207. hostInstances
  5208. );
  5209. if (foundHostInstances) {
  5210. return;
  5211. } // If we didn't find any host children, fallback to closest host parent.
  5212. var node = fiber;
  5213. while (true) {
  5214. switch (node.tag) {
  5215. case HostComponent:
  5216. hostInstances.add(node.stateNode);
  5217. return;
  5218. case HostPortal:
  5219. hostInstances.add(node.stateNode.containerInfo);
  5220. return;
  5221. case HostRoot:
  5222. hostInstances.add(node.stateNode.containerInfo);
  5223. return;
  5224. }
  5225. if (node.return === null) {
  5226. throw new Error("Expected to reach root first.");
  5227. }
  5228. node = node.return;
  5229. }
  5230. }
  5231. }
  5232. function findChildHostInstancesForFiberShallowly(fiber, hostInstances) {
  5233. {
  5234. var node = fiber;
  5235. var foundHostInstances = false;
  5236. while (true) {
  5237. if (node.tag === HostComponent) {
  5238. // We got a match.
  5239. foundHostInstances = true;
  5240. hostInstances.add(node.stateNode); // There may still be more, so keep searching.
  5241. } else if (node.child !== null) {
  5242. node.child.return = node;
  5243. node = node.child;
  5244. continue;
  5245. }
  5246. if (node === fiber) {
  5247. return foundHostInstances;
  5248. }
  5249. while (node.sibling === null) {
  5250. if (node.return === null || node.return === fiber) {
  5251. return foundHostInstances;
  5252. }
  5253. node = node.return;
  5254. }
  5255. node.sibling.return = node.return;
  5256. node = node.sibling;
  5257. }
  5258. }
  5259. return false;
  5260. }
  5261. function resolveDefaultProps(Component, baseProps) {
  5262. if (Component && Component.defaultProps) {
  5263. // Resolve default props. Taken from ReactElement
  5264. var props = Object.assign({}, baseProps);
  5265. var defaultProps = Component.defaultProps;
  5266. for (var propName in defaultProps) {
  5267. if (props[propName] === undefined) {
  5268. props[propName] = defaultProps[propName];
  5269. }
  5270. }
  5271. return props;
  5272. }
  5273. return baseProps;
  5274. }
  5275. function readLazyComponentType(lazyComponent) {
  5276. initializeLazyComponentType(lazyComponent);
  5277. if (lazyComponent._status !== Resolved) {
  5278. throw lazyComponent._result;
  5279. }
  5280. return lazyComponent._result;
  5281. }
  5282. var valueCursor = createCursor(null);
  5283. var rendererSigil;
  5284. {
  5285. // Use this to detect multiple renderers using the same context
  5286. rendererSigil = {};
  5287. }
  5288. var currentlyRenderingFiber = null;
  5289. var lastContextDependency = null;
  5290. var lastContextWithAllBitsObserved = null;
  5291. var isDisallowedContextReadInDEV = false;
  5292. function resetContextDependencies() {
  5293. // This is called right before React yields execution, to ensure `readContext`
  5294. // cannot be called outside the render phase.
  5295. currentlyRenderingFiber = null;
  5296. lastContextDependency = null;
  5297. lastContextWithAllBitsObserved = null;
  5298. {
  5299. isDisallowedContextReadInDEV = false;
  5300. }
  5301. }
  5302. function enterDisallowedContextReadInDEV() {
  5303. {
  5304. isDisallowedContextReadInDEV = true;
  5305. }
  5306. }
  5307. function exitDisallowedContextReadInDEV() {
  5308. {
  5309. isDisallowedContextReadInDEV = false;
  5310. }
  5311. }
  5312. function pushProvider(providerFiber, nextValue) {
  5313. var context = providerFiber.type._context;
  5314. {
  5315. push(valueCursor, context._currentValue2, providerFiber);
  5316. context._currentValue2 = nextValue;
  5317. {
  5318. if (
  5319. context._currentRenderer2 !== undefined &&
  5320. context._currentRenderer2 !== null &&
  5321. context._currentRenderer2 !== rendererSigil
  5322. ) {
  5323. error(
  5324. "Detected multiple renderers concurrently rendering the " +
  5325. "same context provider. This is currently unsupported."
  5326. );
  5327. }
  5328. context._currentRenderer2 = rendererSigil;
  5329. }
  5330. }
  5331. }
  5332. function popProvider(providerFiber) {
  5333. var currentValue = valueCursor.current;
  5334. pop(valueCursor, providerFiber);
  5335. var context = providerFiber.type._context;
  5336. {
  5337. context._currentValue2 = currentValue;
  5338. }
  5339. }
  5340. function calculateChangedBits(context, newValue, oldValue) {
  5341. if (objectIs(oldValue, newValue)) {
  5342. // No change
  5343. return 0;
  5344. } else {
  5345. var changedBits =
  5346. typeof context._calculateChangedBits === "function"
  5347. ? context._calculateChangedBits(oldValue, newValue)
  5348. : MAX_SIGNED_31_BIT_INT;
  5349. {
  5350. if ((changedBits & MAX_SIGNED_31_BIT_INT) !== changedBits) {
  5351. error(
  5352. "calculateChangedBits: Expected the return value to be a " +
  5353. "31-bit integer. Instead received: %s",
  5354. changedBits
  5355. );
  5356. }
  5357. }
  5358. return changedBits | 0;
  5359. }
  5360. }
  5361. function scheduleWorkOnParentPath(parent, renderExpirationTime) {
  5362. // Update the child expiration time of all the ancestors, including
  5363. // the alternates.
  5364. var node = parent;
  5365. while (node !== null) {
  5366. var alternate = node.alternate;
  5367. if (node.childExpirationTime < renderExpirationTime) {
  5368. node.childExpirationTime = renderExpirationTime;
  5369. if (
  5370. alternate !== null &&
  5371. alternate.childExpirationTime < renderExpirationTime
  5372. ) {
  5373. alternate.childExpirationTime = renderExpirationTime;
  5374. }
  5375. } else if (
  5376. alternate !== null &&
  5377. alternate.childExpirationTime < renderExpirationTime
  5378. ) {
  5379. alternate.childExpirationTime = renderExpirationTime;
  5380. } else {
  5381. // Neither alternate was updated, which means the rest of the
  5382. // ancestor path already has sufficient priority.
  5383. break;
  5384. }
  5385. node = node.return;
  5386. }
  5387. }
  5388. function propagateContextChange(
  5389. workInProgress,
  5390. context,
  5391. changedBits,
  5392. renderExpirationTime
  5393. ) {
  5394. var fiber = workInProgress.child;
  5395. if (fiber !== null) {
  5396. // Set the return pointer of the child to the work-in-progress fiber.
  5397. fiber.return = workInProgress;
  5398. }
  5399. while (fiber !== null) {
  5400. var nextFiber = void 0; // Visit this fiber.
  5401. var list = fiber.dependencies;
  5402. if (list !== null) {
  5403. nextFiber = fiber.child;
  5404. var dependency = list.firstContext;
  5405. while (dependency !== null) {
  5406. // Check if the context matches.
  5407. if (
  5408. dependency.context === context &&
  5409. (dependency.observedBits & changedBits) !== 0
  5410. ) {
  5411. // Match! Schedule an update on this fiber.
  5412. if (fiber.tag === ClassComponent) {
  5413. // Schedule a force update on the work-in-progress.
  5414. var update = createUpdate(renderExpirationTime, null);
  5415. update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
  5416. // update to the current fiber, too, which means it will persist even if
  5417. // this render is thrown away. Since it's a race condition, not sure it's
  5418. // worth fixing.
  5419. enqueueUpdate(fiber, update);
  5420. }
  5421. if (fiber.expirationTime < renderExpirationTime) {
  5422. fiber.expirationTime = renderExpirationTime;
  5423. }
  5424. var alternate = fiber.alternate;
  5425. if (
  5426. alternate !== null &&
  5427. alternate.expirationTime < renderExpirationTime
  5428. ) {
  5429. alternate.expirationTime = renderExpirationTime;
  5430. }
  5431. scheduleWorkOnParentPath(fiber.return, renderExpirationTime); // Mark the expiration time on the list, too.
  5432. if (list.expirationTime < renderExpirationTime) {
  5433. list.expirationTime = renderExpirationTime;
  5434. } // Since we already found a match, we can stop traversing the
  5435. // dependency list.
  5436. break;
  5437. }
  5438. dependency = dependency.next;
  5439. }
  5440. } else if (fiber.tag === ContextProvider) {
  5441. // Don't scan deeper if this is a matching provider
  5442. nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
  5443. } else {
  5444. // Traverse down.
  5445. nextFiber = fiber.child;
  5446. }
  5447. if (nextFiber !== null) {
  5448. // Set the return pointer of the child to the work-in-progress fiber.
  5449. nextFiber.return = fiber;
  5450. } else {
  5451. // No child. Traverse to next sibling.
  5452. nextFiber = fiber;
  5453. while (nextFiber !== null) {
  5454. if (nextFiber === workInProgress) {
  5455. // We're back to the root of this subtree. Exit.
  5456. nextFiber = null;
  5457. break;
  5458. }
  5459. var sibling = nextFiber.sibling;
  5460. if (sibling !== null) {
  5461. // Set the return pointer of the sibling to the work-in-progress fiber.
  5462. sibling.return = nextFiber.return;
  5463. nextFiber = sibling;
  5464. break;
  5465. } // No more siblings. Traverse up.
  5466. nextFiber = nextFiber.return;
  5467. }
  5468. }
  5469. fiber = nextFiber;
  5470. }
  5471. }
  5472. function prepareToReadContext(workInProgress, renderExpirationTime) {
  5473. currentlyRenderingFiber = workInProgress;
  5474. lastContextDependency = null;
  5475. lastContextWithAllBitsObserved = null;
  5476. var dependencies = workInProgress.dependencies;
  5477. if (dependencies !== null) {
  5478. var firstContext = dependencies.firstContext;
  5479. if (firstContext !== null) {
  5480. if (dependencies.expirationTime >= renderExpirationTime) {
  5481. // Context list has a pending update. Mark that this fiber performed work.
  5482. markWorkInProgressReceivedUpdate();
  5483. } // Reset the work-in-progress list
  5484. dependencies.firstContext = null;
  5485. }
  5486. }
  5487. }
  5488. function readContext(context, observedBits) {
  5489. {
  5490. // This warning would fire if you read context inside a Hook like useMemo.
  5491. // Unlike the class check below, it's not enforced in production for perf.
  5492. if (isDisallowedContextReadInDEV) {
  5493. error(
  5494. "Context can only be read while React is rendering. " +
  5495. "In classes, you can read it in the render method or getDerivedStateFromProps. " +
  5496. "In function components, you can read it directly in the function body, but not " +
  5497. "inside Hooks like useReducer() or useMemo()."
  5498. );
  5499. }
  5500. }
  5501. if (lastContextWithAllBitsObserved === context);
  5502. else if (observedBits === false || observedBits === 0);
  5503. else {
  5504. var resolvedObservedBits; // Avoid deopting on observable arguments or heterogeneous types.
  5505. if (
  5506. typeof observedBits !== "number" ||
  5507. observedBits === MAX_SIGNED_31_BIT_INT
  5508. ) {
  5509. // Observe all updates.
  5510. lastContextWithAllBitsObserved = context;
  5511. resolvedObservedBits = MAX_SIGNED_31_BIT_INT;
  5512. } else {
  5513. resolvedObservedBits = observedBits;
  5514. }
  5515. var contextItem = {
  5516. context: context,
  5517. observedBits: resolvedObservedBits,
  5518. next: null
  5519. };
  5520. if (lastContextDependency === null) {
  5521. if (!(currentlyRenderingFiber !== null)) {
  5522. throw Error(
  5523. "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()."
  5524. );
  5525. } // This is the first dependency for this component. Create a new list.
  5526. lastContextDependency = contextItem;
  5527. currentlyRenderingFiber.dependencies = {
  5528. expirationTime: NoWork,
  5529. firstContext: contextItem,
  5530. responders: null
  5531. };
  5532. } else {
  5533. // Append a new context item.
  5534. lastContextDependency = lastContextDependency.next = contextItem;
  5535. }
  5536. }
  5537. return context._currentValue2;
  5538. }
  5539. var UpdateState = 0;
  5540. var ReplaceState = 1;
  5541. var ForceUpdate = 2;
  5542. var CaptureUpdate = 3; // Global state that is reset at the beginning of calling `processUpdateQueue`.
  5543. // It should only be read right after calling `processUpdateQueue`, via
  5544. // `checkHasForceUpdateAfterProcessing`.
  5545. var hasForceUpdate = false;
  5546. var didWarnUpdateInsideUpdate;
  5547. var currentlyProcessingQueue;
  5548. {
  5549. didWarnUpdateInsideUpdate = false;
  5550. currentlyProcessingQueue = null;
  5551. }
  5552. function initializeUpdateQueue(fiber) {
  5553. var queue = {
  5554. baseState: fiber.memoizedState,
  5555. baseQueue: null,
  5556. shared: {
  5557. pending: null
  5558. },
  5559. effects: null
  5560. };
  5561. fiber.updateQueue = queue;
  5562. }
  5563. function cloneUpdateQueue(current, workInProgress) {
  5564. // Clone the update queue from current. Unless it's already a clone.
  5565. var queue = workInProgress.updateQueue;
  5566. var currentQueue = current.updateQueue;
  5567. if (queue === currentQueue) {
  5568. var clone = {
  5569. baseState: currentQueue.baseState,
  5570. baseQueue: currentQueue.baseQueue,
  5571. shared: currentQueue.shared,
  5572. effects: currentQueue.effects
  5573. };
  5574. workInProgress.updateQueue = clone;
  5575. }
  5576. }
  5577. function createUpdate(expirationTime, suspenseConfig) {
  5578. var update = {
  5579. expirationTime: expirationTime,
  5580. suspenseConfig: suspenseConfig,
  5581. tag: UpdateState,
  5582. payload: null,
  5583. callback: null,
  5584. next: null
  5585. };
  5586. update.next = update;
  5587. {
  5588. update.priority = getCurrentPriorityLevel();
  5589. }
  5590. return update;
  5591. }
  5592. function enqueueUpdate(fiber, update) {
  5593. var updateQueue = fiber.updateQueue;
  5594. if (updateQueue === null) {
  5595. // Only occurs if the fiber has been unmounted.
  5596. return;
  5597. }
  5598. var sharedQueue = updateQueue.shared;
  5599. var pending = sharedQueue.pending;
  5600. if (pending === null) {
  5601. // This is the first update. Create a circular list.
  5602. update.next = update;
  5603. } else {
  5604. update.next = pending.next;
  5605. pending.next = update;
  5606. }
  5607. sharedQueue.pending = update;
  5608. {
  5609. if (
  5610. currentlyProcessingQueue === sharedQueue &&
  5611. !didWarnUpdateInsideUpdate
  5612. ) {
  5613. error(
  5614. "An update (setState, replaceState, or forceUpdate) was scheduled " +
  5615. "from inside an update function. Update functions should be pure, " +
  5616. "with zero side-effects. Consider using componentDidUpdate or a " +
  5617. "callback."
  5618. );
  5619. didWarnUpdateInsideUpdate = true;
  5620. }
  5621. }
  5622. }
  5623. function enqueueCapturedUpdate(workInProgress, update) {
  5624. var current = workInProgress.alternate;
  5625. if (current !== null) {
  5626. // Ensure the work-in-progress queue is a clone
  5627. cloneUpdateQueue(current, workInProgress);
  5628. } // Captured updates go only on the work-in-progress queue.
  5629. var queue = workInProgress.updateQueue; // Append the update to the end of the list.
  5630. var last = queue.baseQueue;
  5631. if (last === null) {
  5632. queue.baseQueue = update.next = update;
  5633. update.next = update;
  5634. } else {
  5635. update.next = last.next;
  5636. last.next = update;
  5637. }
  5638. }
  5639. function getStateFromUpdate(
  5640. workInProgress,
  5641. queue,
  5642. update,
  5643. prevState,
  5644. nextProps,
  5645. instance
  5646. ) {
  5647. switch (update.tag) {
  5648. case ReplaceState: {
  5649. var payload = update.payload;
  5650. if (typeof payload === "function") {
  5651. // Updater function
  5652. {
  5653. enterDisallowedContextReadInDEV();
  5654. if (workInProgress.mode & StrictMode) {
  5655. payload.call(instance, prevState, nextProps);
  5656. }
  5657. }
  5658. var nextState = payload.call(instance, prevState, nextProps);
  5659. {
  5660. exitDisallowedContextReadInDEV();
  5661. }
  5662. return nextState;
  5663. } // State object
  5664. return payload;
  5665. }
  5666. case CaptureUpdate: {
  5667. workInProgress.effectTag =
  5668. (workInProgress.effectTag & ~ShouldCapture) | DidCapture;
  5669. }
  5670. // Intentional fallthrough
  5671. case UpdateState: {
  5672. var _payload = update.payload;
  5673. var partialState;
  5674. if (typeof _payload === "function") {
  5675. // Updater function
  5676. {
  5677. enterDisallowedContextReadInDEV();
  5678. if (workInProgress.mode & StrictMode) {
  5679. _payload.call(instance, prevState, nextProps);
  5680. }
  5681. }
  5682. partialState = _payload.call(instance, prevState, nextProps);
  5683. {
  5684. exitDisallowedContextReadInDEV();
  5685. }
  5686. } else {
  5687. // Partial state object
  5688. partialState = _payload;
  5689. }
  5690. if (partialState === null || partialState === undefined) {
  5691. // Null and undefined are treated as no-ops.
  5692. return prevState;
  5693. } // Merge the partial state and the previous state.
  5694. return Object.assign({}, prevState, partialState);
  5695. }
  5696. case ForceUpdate: {
  5697. hasForceUpdate = true;
  5698. return prevState;
  5699. }
  5700. }
  5701. return prevState;
  5702. }
  5703. function processUpdateQueue(
  5704. workInProgress,
  5705. props,
  5706. instance,
  5707. renderExpirationTime
  5708. ) {
  5709. // This is always non-null on a ClassComponent or HostRoot
  5710. var queue = workInProgress.updateQueue;
  5711. hasForceUpdate = false;
  5712. {
  5713. currentlyProcessingQueue = queue.shared;
  5714. } // The last rebase update that is NOT part of the base state.
  5715. var baseQueue = queue.baseQueue; // The last pending update that hasn't been processed yet.
  5716. var pendingQueue = queue.shared.pending;
  5717. if (pendingQueue !== null) {
  5718. // We have new updates that haven't been processed yet.
  5719. // We'll add them to the base queue.
  5720. if (baseQueue !== null) {
  5721. // Merge the pending queue and the base queue.
  5722. var baseFirst = baseQueue.next;
  5723. var pendingFirst = pendingQueue.next;
  5724. baseQueue.next = pendingFirst;
  5725. pendingQueue.next = baseFirst;
  5726. }
  5727. baseQueue = pendingQueue;
  5728. queue.shared.pending = null; // TODO: Pass `current` as argument
  5729. var current = workInProgress.alternate;
  5730. if (current !== null) {
  5731. var currentQueue = current.updateQueue;
  5732. if (currentQueue !== null) {
  5733. currentQueue.baseQueue = pendingQueue;
  5734. }
  5735. }
  5736. } // These values may change as we process the queue.
  5737. if (baseQueue !== null) {
  5738. var first = baseQueue.next; // Iterate through the list of updates to compute the result.
  5739. var newState = queue.baseState;
  5740. var newExpirationTime = NoWork;
  5741. var newBaseState = null;
  5742. var newBaseQueueFirst = null;
  5743. var newBaseQueueLast = null;
  5744. if (first !== null) {
  5745. var update = first;
  5746. do {
  5747. var updateExpirationTime = update.expirationTime;
  5748. if (updateExpirationTime < renderExpirationTime) {
  5749. // Priority is insufficient. Skip this update. If this is the first
  5750. // skipped update, the previous update/state is the new base
  5751. // update/state.
  5752. var clone = {
  5753. expirationTime: update.expirationTime,
  5754. suspenseConfig: update.suspenseConfig,
  5755. tag: update.tag,
  5756. payload: update.payload,
  5757. callback: update.callback,
  5758. next: null
  5759. };
  5760. if (newBaseQueueLast === null) {
  5761. newBaseQueueFirst = newBaseQueueLast = clone;
  5762. newBaseState = newState;
  5763. } else {
  5764. newBaseQueueLast = newBaseQueueLast.next = clone;
  5765. } // Update the remaining priority in the queue.
  5766. if (updateExpirationTime > newExpirationTime) {
  5767. newExpirationTime = updateExpirationTime;
  5768. }
  5769. } else {
  5770. // This update does have sufficient priority.
  5771. if (newBaseQueueLast !== null) {
  5772. var _clone = {
  5773. expirationTime: Sync,
  5774. // This update is going to be committed so we never want uncommit it.
  5775. suspenseConfig: update.suspenseConfig,
  5776. tag: update.tag,
  5777. payload: update.payload,
  5778. callback: update.callback,
  5779. next: null
  5780. };
  5781. newBaseQueueLast = newBaseQueueLast.next = _clone;
  5782. } // Mark the event time of this update as relevant to this render pass.
  5783. // TODO: This should ideally use the true event time of this update rather than
  5784. // its priority which is a derived and not reverseable value.
  5785. // TODO: We should skip this update if it was already committed but currently
  5786. // we have no way of detecting the difference between a committed and suspended
  5787. // update here.
  5788. markRenderEventTimeAndConfig(
  5789. updateExpirationTime,
  5790. update.suspenseConfig
  5791. ); // Process this update.
  5792. newState = getStateFromUpdate(
  5793. workInProgress,
  5794. queue,
  5795. update,
  5796. newState,
  5797. props,
  5798. instance
  5799. );
  5800. var callback = update.callback;
  5801. if (callback !== null) {
  5802. workInProgress.effectTag |= Callback;
  5803. var effects = queue.effects;
  5804. if (effects === null) {
  5805. queue.effects = [update];
  5806. } else {
  5807. effects.push(update);
  5808. }
  5809. }
  5810. }
  5811. update = update.next;
  5812. if (update === null || update === first) {
  5813. pendingQueue = queue.shared.pending;
  5814. if (pendingQueue === null) {
  5815. break;
  5816. } else {
  5817. // An update was scheduled from inside a reducer. Add the new
  5818. // pending updates to the end of the list and keep processing.
  5819. update = baseQueue.next = pendingQueue.next;
  5820. pendingQueue.next = first;
  5821. queue.baseQueue = baseQueue = pendingQueue;
  5822. queue.shared.pending = null;
  5823. }
  5824. }
  5825. } while (true);
  5826. }
  5827. if (newBaseQueueLast === null) {
  5828. newBaseState = newState;
  5829. } else {
  5830. newBaseQueueLast.next = newBaseQueueFirst;
  5831. }
  5832. queue.baseState = newBaseState;
  5833. queue.baseQueue = newBaseQueueLast; // Set the remaining expiration time to be whatever is remaining in the queue.
  5834. // This should be fine because the only two other things that contribute to
  5835. // expiration time are props and context. We're already in the middle of the
  5836. // begin phase by the time we start processing the queue, so we've already
  5837. // dealt with the props. Context in components that specify
  5838. // shouldComponentUpdate is tricky; but we'll have to account for
  5839. // that regardless.
  5840. markUnprocessedUpdateTime(newExpirationTime);
  5841. workInProgress.expirationTime = newExpirationTime;
  5842. workInProgress.memoizedState = newState;
  5843. }
  5844. {
  5845. currentlyProcessingQueue = null;
  5846. }
  5847. }
  5848. function callCallback(callback, context) {
  5849. if (!(typeof callback === "function")) {
  5850. throw Error(
  5851. "Invalid argument passed as callback. Expected a function. Instead received: " +
  5852. callback
  5853. );
  5854. }
  5855. callback.call(context);
  5856. }
  5857. function resetHasForceUpdateBeforeProcessing() {
  5858. hasForceUpdate = false;
  5859. }
  5860. function checkHasForceUpdateAfterProcessing() {
  5861. return hasForceUpdate;
  5862. }
  5863. function commitUpdateQueue(finishedWork, finishedQueue, instance) {
  5864. // Commit the effects
  5865. var effects = finishedQueue.effects;
  5866. finishedQueue.effects = null;
  5867. if (effects !== null) {
  5868. for (var i = 0; i < effects.length; i++) {
  5869. var effect = effects[i];
  5870. var callback = effect.callback;
  5871. if (callback !== null) {
  5872. effect.callback = null;
  5873. callCallback(callback, instance);
  5874. }
  5875. }
  5876. }
  5877. }
  5878. var ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig;
  5879. function requestCurrentSuspenseConfig() {
  5880. return ReactCurrentBatchConfig.suspense;
  5881. }
  5882. var fakeInternalInstance = {};
  5883. var isArray = Array.isArray; // React.Component uses a shared frozen object by default.
  5884. // We'll use it to determine whether we need to initialize legacy refs.
  5885. var emptyRefsObject = new React.Component().refs;
  5886. var didWarnAboutStateAssignmentForComponent;
  5887. var didWarnAboutUninitializedState;
  5888. var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
  5889. var didWarnAboutLegacyLifecyclesAndDerivedState;
  5890. var didWarnAboutUndefinedDerivedState;
  5891. var warnOnUndefinedDerivedState;
  5892. var warnOnInvalidCallback;
  5893. var didWarnAboutDirectlyAssigningPropsToState;
  5894. var didWarnAboutContextTypeAndContextTypes;
  5895. var didWarnAboutInvalidateContextType;
  5896. {
  5897. didWarnAboutStateAssignmentForComponent = new Set();
  5898. didWarnAboutUninitializedState = new Set();
  5899. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
  5900. didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
  5901. didWarnAboutDirectlyAssigningPropsToState = new Set();
  5902. didWarnAboutUndefinedDerivedState = new Set();
  5903. didWarnAboutContextTypeAndContextTypes = new Set();
  5904. didWarnAboutInvalidateContextType = new Set();
  5905. var didWarnOnInvalidCallback = new Set();
  5906. warnOnInvalidCallback = function(callback, callerName) {
  5907. if (callback === null || typeof callback === "function") {
  5908. return;
  5909. }
  5910. var key = callerName + "_" + callback;
  5911. if (!didWarnOnInvalidCallback.has(key)) {
  5912. didWarnOnInvalidCallback.add(key);
  5913. error(
  5914. "%s(...): Expected the last optional `callback` argument to be a " +
  5915. "function. Instead received: %s.",
  5916. callerName,
  5917. callback
  5918. );
  5919. }
  5920. };
  5921. warnOnUndefinedDerivedState = function(type, partialState) {
  5922. if (partialState === undefined) {
  5923. var componentName = getComponentName(type) || "Component";
  5924. if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
  5925. didWarnAboutUndefinedDerivedState.add(componentName);
  5926. error(
  5927. "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " +
  5928. "You have returned undefined.",
  5929. componentName
  5930. );
  5931. }
  5932. }
  5933. }; // This is so gross but it's at least non-critical and can be removed if
  5934. // it causes problems. This is meant to give a nicer error message for
  5935. // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
  5936. // ...)) which otherwise throws a "_processChildContext is not a function"
  5937. // exception.
  5938. Object.defineProperty(fakeInternalInstance, "_processChildContext", {
  5939. enumerable: false,
  5940. value: function() {
  5941. {
  5942. throw Error(
  5943. "_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)."
  5944. );
  5945. }
  5946. }
  5947. });
  5948. Object.freeze(fakeInternalInstance);
  5949. }
  5950. function applyDerivedStateFromProps(
  5951. workInProgress,
  5952. ctor,
  5953. getDerivedStateFromProps,
  5954. nextProps
  5955. ) {
  5956. var prevState = workInProgress.memoizedState;
  5957. {
  5958. if (workInProgress.mode & StrictMode) {
  5959. // Invoke the function an extra time to help detect side-effects.
  5960. getDerivedStateFromProps(nextProps, prevState);
  5961. }
  5962. }
  5963. var partialState = getDerivedStateFromProps(nextProps, prevState);
  5964. {
  5965. warnOnUndefinedDerivedState(ctor, partialState);
  5966. } // Merge the partial state and the previous state.
  5967. var memoizedState =
  5968. partialState === null || partialState === undefined
  5969. ? prevState
  5970. : Object.assign({}, prevState, partialState);
  5971. workInProgress.memoizedState = memoizedState; // Once the update queue is empty, persist the derived state onto the
  5972. // base state.
  5973. if (workInProgress.expirationTime === NoWork) {
  5974. // Queue is always non-null for classes
  5975. var updateQueue = workInProgress.updateQueue;
  5976. updateQueue.baseState = memoizedState;
  5977. }
  5978. }
  5979. var classComponentUpdater = {
  5980. isMounted: isMounted,
  5981. enqueueSetState: function(inst, payload, callback) {
  5982. var fiber = get(inst);
  5983. var currentTime = requestCurrentTimeForUpdate();
  5984. var suspenseConfig = requestCurrentSuspenseConfig();
  5985. var expirationTime = computeExpirationForFiber(
  5986. currentTime,
  5987. fiber,
  5988. suspenseConfig
  5989. );
  5990. var update = createUpdate(expirationTime, suspenseConfig);
  5991. update.payload = payload;
  5992. if (callback !== undefined && callback !== null) {
  5993. {
  5994. warnOnInvalidCallback(callback, "setState");
  5995. }
  5996. update.callback = callback;
  5997. }
  5998. enqueueUpdate(fiber, update);
  5999. scheduleWork(fiber, expirationTime);
  6000. },
  6001. enqueueReplaceState: function(inst, payload, callback) {
  6002. var fiber = get(inst);
  6003. var currentTime = requestCurrentTimeForUpdate();
  6004. var suspenseConfig = requestCurrentSuspenseConfig();
  6005. var expirationTime = computeExpirationForFiber(
  6006. currentTime,
  6007. fiber,
  6008. suspenseConfig
  6009. );
  6010. var update = createUpdate(expirationTime, suspenseConfig);
  6011. update.tag = ReplaceState;
  6012. update.payload = payload;
  6013. if (callback !== undefined && callback !== null) {
  6014. {
  6015. warnOnInvalidCallback(callback, "replaceState");
  6016. }
  6017. update.callback = callback;
  6018. }
  6019. enqueueUpdate(fiber, update);
  6020. scheduleWork(fiber, expirationTime);
  6021. },
  6022. enqueueForceUpdate: function(inst, callback) {
  6023. var fiber = get(inst);
  6024. var currentTime = requestCurrentTimeForUpdate();
  6025. var suspenseConfig = requestCurrentSuspenseConfig();
  6026. var expirationTime = computeExpirationForFiber(
  6027. currentTime,
  6028. fiber,
  6029. suspenseConfig
  6030. );
  6031. var update = createUpdate(expirationTime, suspenseConfig);
  6032. update.tag = ForceUpdate;
  6033. if (callback !== undefined && callback !== null) {
  6034. {
  6035. warnOnInvalidCallback(callback, "forceUpdate");
  6036. }
  6037. update.callback = callback;
  6038. }
  6039. enqueueUpdate(fiber, update);
  6040. scheduleWork(fiber, expirationTime);
  6041. }
  6042. };
  6043. function checkShouldComponentUpdate(
  6044. workInProgress,
  6045. ctor,
  6046. oldProps,
  6047. newProps,
  6048. oldState,
  6049. newState,
  6050. nextContext
  6051. ) {
  6052. var instance = workInProgress.stateNode;
  6053. if (typeof instance.shouldComponentUpdate === "function") {
  6054. {
  6055. if (workInProgress.mode & StrictMode) {
  6056. // Invoke the function an extra time to help detect side-effects.
  6057. instance.shouldComponentUpdate(newProps, newState, nextContext);
  6058. }
  6059. }
  6060. startPhaseTimer(workInProgress, "shouldComponentUpdate");
  6061. var shouldUpdate = instance.shouldComponentUpdate(
  6062. newProps,
  6063. newState,
  6064. nextContext
  6065. );
  6066. stopPhaseTimer();
  6067. {
  6068. if (shouldUpdate === undefined) {
  6069. error(
  6070. "%s.shouldComponentUpdate(): Returned undefined instead of a " +
  6071. "boolean value. Make sure to return true or false.",
  6072. getComponentName(ctor) || "Component"
  6073. );
  6074. }
  6075. }
  6076. return shouldUpdate;
  6077. }
  6078. if (ctor.prototype && ctor.prototype.isPureReactComponent) {
  6079. return (
  6080. !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState)
  6081. );
  6082. }
  6083. return true;
  6084. }
  6085. function checkClassInstance(workInProgress, ctor, newProps) {
  6086. var instance = workInProgress.stateNode;
  6087. {
  6088. var name = getComponentName(ctor) || "Component";
  6089. var renderPresent = instance.render;
  6090. if (!renderPresent) {
  6091. if (ctor.prototype && typeof ctor.prototype.render === "function") {
  6092. error(
  6093. "%s(...): No `render` method found on the returned component " +
  6094. "instance: did you accidentally return an object from the constructor?",
  6095. name
  6096. );
  6097. } else {
  6098. error(
  6099. "%s(...): No `render` method found on the returned component " +
  6100. "instance: you may have forgotten to define `render`.",
  6101. name
  6102. );
  6103. }
  6104. }
  6105. if (
  6106. instance.getInitialState &&
  6107. !instance.getInitialState.isReactClassApproved &&
  6108. !instance.state
  6109. ) {
  6110. error(
  6111. "getInitialState was defined on %s, a plain JavaScript class. " +
  6112. "This is only supported for classes created using React.createClass. " +
  6113. "Did you mean to define a state property instead?",
  6114. name
  6115. );
  6116. }
  6117. if (
  6118. instance.getDefaultProps &&
  6119. !instance.getDefaultProps.isReactClassApproved
  6120. ) {
  6121. error(
  6122. "getDefaultProps was defined on %s, a plain JavaScript class. " +
  6123. "This is only supported for classes created using React.createClass. " +
  6124. "Use a static property to define defaultProps instead.",
  6125. name
  6126. );
  6127. }
  6128. if (instance.propTypes) {
  6129. error(
  6130. "propTypes was defined as an instance property on %s. Use a static " +
  6131. "property to define propTypes instead.",
  6132. name
  6133. );
  6134. }
  6135. if (instance.contextType) {
  6136. error(
  6137. "contextType was defined as an instance property on %s. Use a static " +
  6138. "property to define contextType instead.",
  6139. name
  6140. );
  6141. }
  6142. {
  6143. if (instance.contextTypes) {
  6144. error(
  6145. "contextTypes was defined as an instance property on %s. Use a static " +
  6146. "property to define contextTypes instead.",
  6147. name
  6148. );
  6149. }
  6150. if (
  6151. ctor.contextType &&
  6152. ctor.contextTypes &&
  6153. !didWarnAboutContextTypeAndContextTypes.has(ctor)
  6154. ) {
  6155. didWarnAboutContextTypeAndContextTypes.add(ctor);
  6156. error(
  6157. "%s declares both contextTypes and contextType static properties. " +
  6158. "The legacy contextTypes property will be ignored.",
  6159. name
  6160. );
  6161. }
  6162. }
  6163. if (typeof instance.componentShouldUpdate === "function") {
  6164. error(
  6165. "%s has a method called " +
  6166. "componentShouldUpdate(). Did you mean shouldComponentUpdate()? " +
  6167. "The name is phrased as a question because the function is " +
  6168. "expected to return a value.",
  6169. name
  6170. );
  6171. }
  6172. if (
  6173. ctor.prototype &&
  6174. ctor.prototype.isPureReactComponent &&
  6175. typeof instance.shouldComponentUpdate !== "undefined"
  6176. ) {
  6177. error(
  6178. "%s has a method called shouldComponentUpdate(). " +
  6179. "shouldComponentUpdate should not be used when extending React.PureComponent. " +
  6180. "Please extend React.Component if shouldComponentUpdate is used.",
  6181. getComponentName(ctor) || "A pure component"
  6182. );
  6183. }
  6184. if (typeof instance.componentDidUnmount === "function") {
  6185. error(
  6186. "%s has a method called " +
  6187. "componentDidUnmount(). But there is no such lifecycle method. " +
  6188. "Did you mean componentWillUnmount()?",
  6189. name
  6190. );
  6191. }
  6192. if (typeof instance.componentDidReceiveProps === "function") {
  6193. error(
  6194. "%s has a method called " +
  6195. "componentDidReceiveProps(). But there is no such lifecycle method. " +
  6196. "If you meant to update the state in response to changing props, " +
  6197. "use componentWillReceiveProps(). If you meant to fetch data or " +
  6198. "run side-effects or mutations after React has updated the UI, use componentDidUpdate().",
  6199. name
  6200. );
  6201. }
  6202. if (typeof instance.componentWillRecieveProps === "function") {
  6203. error(
  6204. "%s has a method called " +
  6205. "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?",
  6206. name
  6207. );
  6208. }
  6209. if (typeof instance.UNSAFE_componentWillRecieveProps === "function") {
  6210. error(
  6211. "%s has a method called " +
  6212. "UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?",
  6213. name
  6214. );
  6215. }
  6216. var hasMutatedProps = instance.props !== newProps;
  6217. if (instance.props !== undefined && hasMutatedProps) {
  6218. error(
  6219. "%s(...): When calling super() in `%s`, make sure to pass " +
  6220. "up the same props that your component's constructor was passed.",
  6221. name,
  6222. name
  6223. );
  6224. }
  6225. if (instance.defaultProps) {
  6226. error(
  6227. "Setting defaultProps as an instance property on %s is not supported and will be ignored." +
  6228. " Instead, define defaultProps as a static property on %s.",
  6229. name,
  6230. name
  6231. );
  6232. }
  6233. if (
  6234. typeof instance.getSnapshotBeforeUpdate === "function" &&
  6235. typeof instance.componentDidUpdate !== "function" &&
  6236. !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)
  6237. ) {
  6238. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
  6239. error(
  6240. "%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). " +
  6241. "This component defines getSnapshotBeforeUpdate() only.",
  6242. getComponentName(ctor)
  6243. );
  6244. }
  6245. if (typeof instance.getDerivedStateFromProps === "function") {
  6246. error(
  6247. "%s: getDerivedStateFromProps() is defined as an instance method " +
  6248. "and will be ignored. Instead, declare it as a static method.",
  6249. name
  6250. );
  6251. }
  6252. if (typeof instance.getDerivedStateFromError === "function") {
  6253. error(
  6254. "%s: getDerivedStateFromError() is defined as an instance method " +
  6255. "and will be ignored. Instead, declare it as a static method.",
  6256. name
  6257. );
  6258. }
  6259. if (typeof ctor.getSnapshotBeforeUpdate === "function") {
  6260. error(
  6261. "%s: getSnapshotBeforeUpdate() is defined as a static method " +
  6262. "and will be ignored. Instead, declare it as an instance method.",
  6263. name
  6264. );
  6265. }
  6266. var _state = instance.state;
  6267. if (_state && (typeof _state !== "object" || isArray(_state))) {
  6268. error("%s.state: must be set to an object or null", name);
  6269. }
  6270. if (
  6271. typeof instance.getChildContext === "function" &&
  6272. typeof ctor.childContextTypes !== "object"
  6273. ) {
  6274. error(
  6275. "%s.getChildContext(): childContextTypes must be defined in order to " +
  6276. "use getChildContext().",
  6277. name
  6278. );
  6279. }
  6280. }
  6281. }
  6282. function adoptClassInstance(workInProgress, instance) {
  6283. instance.updater = classComponentUpdater;
  6284. workInProgress.stateNode = instance; // The instance needs access to the fiber so that it can schedule updates
  6285. set(instance, workInProgress);
  6286. {
  6287. instance._reactInternalInstance = fakeInternalInstance;
  6288. }
  6289. }
  6290. function constructClassInstance(workInProgress, ctor, props) {
  6291. var isLegacyContextConsumer = false;
  6292. var unmaskedContext = emptyContextObject;
  6293. var context = emptyContextObject;
  6294. var contextType = ctor.contextType;
  6295. {
  6296. if ("contextType" in ctor) {
  6297. var isValid = // Allow null for conditional declaration
  6298. contextType === null ||
  6299. (contextType !== undefined &&
  6300. contextType.$$typeof === REACT_CONTEXT_TYPE &&
  6301. contextType._context === undefined); // Not a <Context.Consumer>
  6302. if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
  6303. didWarnAboutInvalidateContextType.add(ctor);
  6304. var addendum = "";
  6305. if (contextType === undefined) {
  6306. addendum =
  6307. " However, it is set to undefined. " +
  6308. "This can be caused by a typo or by mixing up named and default imports. " +
  6309. "This can also happen due to a circular dependency, so " +
  6310. "try moving the createContext() call to a separate file.";
  6311. } else if (typeof contextType !== "object") {
  6312. addendum = " However, it is set to a " + typeof contextType + ".";
  6313. } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
  6314. addendum = " Did you accidentally pass the Context.Provider instead?";
  6315. } else if (contextType._context !== undefined) {
  6316. // <Context.Consumer>
  6317. addendum = " Did you accidentally pass the Context.Consumer instead?";
  6318. } else {
  6319. addendum =
  6320. " However, it is set to an object with keys {" +
  6321. Object.keys(contextType).join(", ") +
  6322. "}.";
  6323. }
  6324. error(
  6325. "%s defines an invalid contextType. " +
  6326. "contextType should point to the Context object returned by React.createContext().%s",
  6327. getComponentName(ctor) || "Component",
  6328. addendum
  6329. );
  6330. }
  6331. }
  6332. }
  6333. if (typeof contextType === "object" && contextType !== null) {
  6334. context = readContext(contextType);
  6335. } else {
  6336. unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  6337. var contextTypes = ctor.contextTypes;
  6338. isLegacyContextConsumer =
  6339. contextTypes !== null && contextTypes !== undefined;
  6340. context = isLegacyContextConsumer
  6341. ? getMaskedContext(workInProgress, unmaskedContext)
  6342. : emptyContextObject;
  6343. } // Instantiate twice to help detect side-effects.
  6344. {
  6345. if (workInProgress.mode & StrictMode) {
  6346. new ctor(props, context); // eslint-disable-line no-new
  6347. }
  6348. }
  6349. var instance = new ctor(props, context);
  6350. var state = (workInProgress.memoizedState =
  6351. instance.state !== null && instance.state !== undefined
  6352. ? instance.state
  6353. : null);
  6354. adoptClassInstance(workInProgress, instance);
  6355. {
  6356. if (typeof ctor.getDerivedStateFromProps === "function" && state === null) {
  6357. var componentName = getComponentName(ctor) || "Component";
  6358. if (!didWarnAboutUninitializedState.has(componentName)) {
  6359. didWarnAboutUninitializedState.add(componentName);
  6360. error(
  6361. "`%s` uses `getDerivedStateFromProps` but its initial state is " +
  6362. "%s. This is not recommended. Instead, define the initial state by " +
  6363. "assigning an object to `this.state` in the constructor of `%s`. " +
  6364. "This ensures that `getDerivedStateFromProps` arguments have a consistent shape.",
  6365. componentName,
  6366. instance.state === null ? "null" : "undefined",
  6367. componentName
  6368. );
  6369. }
  6370. } // If new component APIs are defined, "unsafe" lifecycles won't be called.
  6371. // Warn about these lifecycles if they are present.
  6372. // Don't warn about react-lifecycles-compat polyfilled methods though.
  6373. if (
  6374. typeof ctor.getDerivedStateFromProps === "function" ||
  6375. typeof instance.getSnapshotBeforeUpdate === "function"
  6376. ) {
  6377. var foundWillMountName = null;
  6378. var foundWillReceivePropsName = null;
  6379. var foundWillUpdateName = null;
  6380. if (
  6381. typeof instance.componentWillMount === "function" &&
  6382. instance.componentWillMount.__suppressDeprecationWarning !== true
  6383. ) {
  6384. foundWillMountName = "componentWillMount";
  6385. } else if (typeof instance.UNSAFE_componentWillMount === "function") {
  6386. foundWillMountName = "UNSAFE_componentWillMount";
  6387. }
  6388. if (
  6389. typeof instance.componentWillReceiveProps === "function" &&
  6390. instance.componentWillReceiveProps.__suppressDeprecationWarning !== true
  6391. ) {
  6392. foundWillReceivePropsName = "componentWillReceiveProps";
  6393. } else if (
  6394. typeof instance.UNSAFE_componentWillReceiveProps === "function"
  6395. ) {
  6396. foundWillReceivePropsName = "UNSAFE_componentWillReceiveProps";
  6397. }
  6398. if (
  6399. typeof instance.componentWillUpdate === "function" &&
  6400. instance.componentWillUpdate.__suppressDeprecationWarning !== true
  6401. ) {
  6402. foundWillUpdateName = "componentWillUpdate";
  6403. } else if (typeof instance.UNSAFE_componentWillUpdate === "function") {
  6404. foundWillUpdateName = "UNSAFE_componentWillUpdate";
  6405. }
  6406. if (
  6407. foundWillMountName !== null ||
  6408. foundWillReceivePropsName !== null ||
  6409. foundWillUpdateName !== null
  6410. ) {
  6411. var _componentName = getComponentName(ctor) || "Component";
  6412. var newApiName =
  6413. typeof ctor.getDerivedStateFromProps === "function"
  6414. ? "getDerivedStateFromProps()"
  6415. : "getSnapshotBeforeUpdate()";
  6416. if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
  6417. didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
  6418. error(
  6419. "Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n" +
  6420. "%s uses %s but also contains the following legacy lifecycles:%s%s%s\n\n" +
  6421. "The above lifecycles should be removed. Learn more about this warning here:\n" +
  6422. "https://fb.me/react-unsafe-component-lifecycles",
  6423. _componentName,
  6424. newApiName,
  6425. foundWillMountName !== null ? "\n " + foundWillMountName : "",
  6426. foundWillReceivePropsName !== null
  6427. ? "\n " + foundWillReceivePropsName
  6428. : "",
  6429. foundWillUpdateName !== null ? "\n " + foundWillUpdateName : ""
  6430. );
  6431. }
  6432. }
  6433. }
  6434. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  6435. // ReactFiberContext usually updates this cache but can't for newly-created instances.
  6436. if (isLegacyContextConsumer) {
  6437. cacheContext(workInProgress, unmaskedContext, context);
  6438. }
  6439. return instance;
  6440. }
  6441. function callComponentWillMount(workInProgress, instance) {
  6442. startPhaseTimer(workInProgress, "componentWillMount");
  6443. var oldState = instance.state;
  6444. if (typeof instance.componentWillMount === "function") {
  6445. instance.componentWillMount();
  6446. }
  6447. if (typeof instance.UNSAFE_componentWillMount === "function") {
  6448. instance.UNSAFE_componentWillMount();
  6449. }
  6450. stopPhaseTimer();
  6451. if (oldState !== instance.state) {
  6452. {
  6453. error(
  6454. "%s.componentWillMount(): Assigning directly to this.state is " +
  6455. "deprecated (except inside a component's " +
  6456. "constructor). Use setState instead.",
  6457. getComponentName(workInProgress.type) || "Component"
  6458. );
  6459. }
  6460. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  6461. }
  6462. }
  6463. function callComponentWillReceiveProps(
  6464. workInProgress,
  6465. instance,
  6466. newProps,
  6467. nextContext
  6468. ) {
  6469. var oldState = instance.state;
  6470. startPhaseTimer(workInProgress, "componentWillReceiveProps");
  6471. if (typeof instance.componentWillReceiveProps === "function") {
  6472. instance.componentWillReceiveProps(newProps, nextContext);
  6473. }
  6474. if (typeof instance.UNSAFE_componentWillReceiveProps === "function") {
  6475. instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
  6476. }
  6477. stopPhaseTimer();
  6478. if (instance.state !== oldState) {
  6479. {
  6480. var componentName = getComponentName(workInProgress.type) || "Component";
  6481. if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
  6482. didWarnAboutStateAssignmentForComponent.add(componentName);
  6483. error(
  6484. "%s.componentWillReceiveProps(): Assigning directly to " +
  6485. "this.state is deprecated (except inside a component's " +
  6486. "constructor). Use setState instead.",
  6487. componentName
  6488. );
  6489. }
  6490. }
  6491. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  6492. }
  6493. } // Invokes the mount life-cycles on a previously never rendered instance.
  6494. function mountClassInstance(
  6495. workInProgress,
  6496. ctor,
  6497. newProps,
  6498. renderExpirationTime
  6499. ) {
  6500. {
  6501. checkClassInstance(workInProgress, ctor, newProps);
  6502. }
  6503. var instance = workInProgress.stateNode;
  6504. instance.props = newProps;
  6505. instance.state = workInProgress.memoizedState;
  6506. instance.refs = emptyRefsObject;
  6507. initializeUpdateQueue(workInProgress);
  6508. var contextType = ctor.contextType;
  6509. if (typeof contextType === "object" && contextType !== null) {
  6510. instance.context = readContext(contextType);
  6511. } else {
  6512. var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  6513. instance.context = getMaskedContext(workInProgress, unmaskedContext);
  6514. }
  6515. {
  6516. if (instance.state === newProps) {
  6517. var componentName = getComponentName(ctor) || "Component";
  6518. if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
  6519. didWarnAboutDirectlyAssigningPropsToState.add(componentName);
  6520. error(
  6521. "%s: It is not recommended to assign props directly to state " +
  6522. "because updates to props won't be reflected in state. " +
  6523. "In most cases, it is better to use props directly.",
  6524. componentName
  6525. );
  6526. }
  6527. }
  6528. if (workInProgress.mode & StrictMode) {
  6529. ReactStrictModeWarnings.recordLegacyContextWarning(
  6530. workInProgress,
  6531. instance
  6532. );
  6533. }
  6534. {
  6535. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(
  6536. workInProgress,
  6537. instance
  6538. );
  6539. }
  6540. }
  6541. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  6542. instance.state = workInProgress.memoizedState;
  6543. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  6544. if (typeof getDerivedStateFromProps === "function") {
  6545. applyDerivedStateFromProps(
  6546. workInProgress,
  6547. ctor,
  6548. getDerivedStateFromProps,
  6549. newProps
  6550. );
  6551. instance.state = workInProgress.memoizedState;
  6552. } // In order to support react-lifecycles-compat polyfilled components,
  6553. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6554. if (
  6555. typeof ctor.getDerivedStateFromProps !== "function" &&
  6556. typeof instance.getSnapshotBeforeUpdate !== "function" &&
  6557. (typeof instance.UNSAFE_componentWillMount === "function" ||
  6558. typeof instance.componentWillMount === "function")
  6559. ) {
  6560. callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's
  6561. // process them now.
  6562. processUpdateQueue(
  6563. workInProgress,
  6564. newProps,
  6565. instance,
  6566. renderExpirationTime
  6567. );
  6568. instance.state = workInProgress.memoizedState;
  6569. }
  6570. if (typeof instance.componentDidMount === "function") {
  6571. workInProgress.effectTag |= Update;
  6572. }
  6573. }
  6574. function resumeMountClassInstance(
  6575. workInProgress,
  6576. ctor,
  6577. newProps,
  6578. renderExpirationTime
  6579. ) {
  6580. var instance = workInProgress.stateNode;
  6581. var oldProps = workInProgress.memoizedProps;
  6582. instance.props = oldProps;
  6583. var oldContext = instance.context;
  6584. var contextType = ctor.contextType;
  6585. var nextContext = emptyContextObject;
  6586. if (typeof contextType === "object" && contextType !== null) {
  6587. nextContext = readContext(contextType);
  6588. } else {
  6589. var nextLegacyUnmaskedContext = getUnmaskedContext(
  6590. workInProgress,
  6591. ctor,
  6592. true
  6593. );
  6594. nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
  6595. }
  6596. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  6597. var hasNewLifecycles =
  6598. typeof getDerivedStateFromProps === "function" ||
  6599. typeof instance.getSnapshotBeforeUpdate === "function"; // Note: During these life-cycles, instance.props/instance.state are what
  6600. // ever the previously attempted to render - not the "current". However,
  6601. // during componentDidUpdate we pass the "current" props.
  6602. // In order to support react-lifecycles-compat polyfilled components,
  6603. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6604. if (
  6605. !hasNewLifecycles &&
  6606. (typeof instance.UNSAFE_componentWillReceiveProps === "function" ||
  6607. typeof instance.componentWillReceiveProps === "function")
  6608. ) {
  6609. if (oldProps !== newProps || oldContext !== nextContext) {
  6610. callComponentWillReceiveProps(
  6611. workInProgress,
  6612. instance,
  6613. newProps,
  6614. nextContext
  6615. );
  6616. }
  6617. }
  6618. resetHasForceUpdateBeforeProcessing();
  6619. var oldState = workInProgress.memoizedState;
  6620. var newState = (instance.state = oldState);
  6621. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  6622. newState = workInProgress.memoizedState;
  6623. if (
  6624. oldProps === newProps &&
  6625. oldState === newState &&
  6626. !hasContextChanged() &&
  6627. !checkHasForceUpdateAfterProcessing()
  6628. ) {
  6629. // If an update was already in progress, we should schedule an Update
  6630. // effect even though we're bailing out, so that cWU/cDU are called.
  6631. if (typeof instance.componentDidMount === "function") {
  6632. workInProgress.effectTag |= Update;
  6633. }
  6634. return false;
  6635. }
  6636. if (typeof getDerivedStateFromProps === "function") {
  6637. applyDerivedStateFromProps(
  6638. workInProgress,
  6639. ctor,
  6640. getDerivedStateFromProps,
  6641. newProps
  6642. );
  6643. newState = workInProgress.memoizedState;
  6644. }
  6645. var shouldUpdate =
  6646. checkHasForceUpdateAfterProcessing() ||
  6647. checkShouldComponentUpdate(
  6648. workInProgress,
  6649. ctor,
  6650. oldProps,
  6651. newProps,
  6652. oldState,
  6653. newState,
  6654. nextContext
  6655. );
  6656. if (shouldUpdate) {
  6657. // In order to support react-lifecycles-compat polyfilled components,
  6658. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6659. if (
  6660. !hasNewLifecycles &&
  6661. (typeof instance.UNSAFE_componentWillMount === "function" ||
  6662. typeof instance.componentWillMount === "function")
  6663. ) {
  6664. startPhaseTimer(workInProgress, "componentWillMount");
  6665. if (typeof instance.componentWillMount === "function") {
  6666. instance.componentWillMount();
  6667. }
  6668. if (typeof instance.UNSAFE_componentWillMount === "function") {
  6669. instance.UNSAFE_componentWillMount();
  6670. }
  6671. stopPhaseTimer();
  6672. }
  6673. if (typeof instance.componentDidMount === "function") {
  6674. workInProgress.effectTag |= Update;
  6675. }
  6676. } else {
  6677. // If an update was already in progress, we should schedule an Update
  6678. // effect even though we're bailing out, so that cWU/cDU are called.
  6679. if (typeof instance.componentDidMount === "function") {
  6680. workInProgress.effectTag |= Update;
  6681. } // If shouldComponentUpdate returned false, we should still update the
  6682. // memoized state to indicate that this work can be reused.
  6683. workInProgress.memoizedProps = newProps;
  6684. workInProgress.memoizedState = newState;
  6685. } // Update the existing instance's state, props, and context pointers even
  6686. // if shouldComponentUpdate returns false.
  6687. instance.props = newProps;
  6688. instance.state = newState;
  6689. instance.context = nextContext;
  6690. return shouldUpdate;
  6691. } // Invokes the update life-cycles and returns false if it shouldn't rerender.
  6692. function updateClassInstance(
  6693. current,
  6694. workInProgress,
  6695. ctor,
  6696. newProps,
  6697. renderExpirationTime
  6698. ) {
  6699. var instance = workInProgress.stateNode;
  6700. cloneUpdateQueue(current, workInProgress);
  6701. var oldProps = workInProgress.memoizedProps;
  6702. instance.props =
  6703. workInProgress.type === workInProgress.elementType
  6704. ? oldProps
  6705. : resolveDefaultProps(workInProgress.type, oldProps);
  6706. var oldContext = instance.context;
  6707. var contextType = ctor.contextType;
  6708. var nextContext = emptyContextObject;
  6709. if (typeof contextType === "object" && contextType !== null) {
  6710. nextContext = readContext(contextType);
  6711. } else {
  6712. var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  6713. nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
  6714. }
  6715. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  6716. var hasNewLifecycles =
  6717. typeof getDerivedStateFromProps === "function" ||
  6718. typeof instance.getSnapshotBeforeUpdate === "function"; // Note: During these life-cycles, instance.props/instance.state are what
  6719. // ever the previously attempted to render - not the "current". However,
  6720. // during componentDidUpdate we pass the "current" props.
  6721. // In order to support react-lifecycles-compat polyfilled components,
  6722. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6723. if (
  6724. !hasNewLifecycles &&
  6725. (typeof instance.UNSAFE_componentWillReceiveProps === "function" ||
  6726. typeof instance.componentWillReceiveProps === "function")
  6727. ) {
  6728. if (oldProps !== newProps || oldContext !== nextContext) {
  6729. callComponentWillReceiveProps(
  6730. workInProgress,
  6731. instance,
  6732. newProps,
  6733. nextContext
  6734. );
  6735. }
  6736. }
  6737. resetHasForceUpdateBeforeProcessing();
  6738. var oldState = workInProgress.memoizedState;
  6739. var newState = (instance.state = oldState);
  6740. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  6741. newState = workInProgress.memoizedState;
  6742. if (
  6743. oldProps === newProps &&
  6744. oldState === newState &&
  6745. !hasContextChanged() &&
  6746. !checkHasForceUpdateAfterProcessing()
  6747. ) {
  6748. // If an update was already in progress, we should schedule an Update
  6749. // effect even though we're bailing out, so that cWU/cDU are called.
  6750. if (typeof instance.componentDidUpdate === "function") {
  6751. if (
  6752. oldProps !== current.memoizedProps ||
  6753. oldState !== current.memoizedState
  6754. ) {
  6755. workInProgress.effectTag |= Update;
  6756. }
  6757. }
  6758. if (typeof instance.getSnapshotBeforeUpdate === "function") {
  6759. if (
  6760. oldProps !== current.memoizedProps ||
  6761. oldState !== current.memoizedState
  6762. ) {
  6763. workInProgress.effectTag |= Snapshot;
  6764. }
  6765. }
  6766. return false;
  6767. }
  6768. if (typeof getDerivedStateFromProps === "function") {
  6769. applyDerivedStateFromProps(
  6770. workInProgress,
  6771. ctor,
  6772. getDerivedStateFromProps,
  6773. newProps
  6774. );
  6775. newState = workInProgress.memoizedState;
  6776. }
  6777. var shouldUpdate =
  6778. checkHasForceUpdateAfterProcessing() ||
  6779. checkShouldComponentUpdate(
  6780. workInProgress,
  6781. ctor,
  6782. oldProps,
  6783. newProps,
  6784. oldState,
  6785. newState,
  6786. nextContext
  6787. );
  6788. if (shouldUpdate) {
  6789. // In order to support react-lifecycles-compat polyfilled components,
  6790. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6791. if (
  6792. !hasNewLifecycles &&
  6793. (typeof instance.UNSAFE_componentWillUpdate === "function" ||
  6794. typeof instance.componentWillUpdate === "function")
  6795. ) {
  6796. startPhaseTimer(workInProgress, "componentWillUpdate");
  6797. if (typeof instance.componentWillUpdate === "function") {
  6798. instance.componentWillUpdate(newProps, newState, nextContext);
  6799. }
  6800. if (typeof instance.UNSAFE_componentWillUpdate === "function") {
  6801. instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
  6802. }
  6803. stopPhaseTimer();
  6804. }
  6805. if (typeof instance.componentDidUpdate === "function") {
  6806. workInProgress.effectTag |= Update;
  6807. }
  6808. if (typeof instance.getSnapshotBeforeUpdate === "function") {
  6809. workInProgress.effectTag |= Snapshot;
  6810. }
  6811. } else {
  6812. // If an update was already in progress, we should schedule an Update
  6813. // effect even though we're bailing out, so that cWU/cDU are called.
  6814. if (typeof instance.componentDidUpdate === "function") {
  6815. if (
  6816. oldProps !== current.memoizedProps ||
  6817. oldState !== current.memoizedState
  6818. ) {
  6819. workInProgress.effectTag |= Update;
  6820. }
  6821. }
  6822. if (typeof instance.getSnapshotBeforeUpdate === "function") {
  6823. if (
  6824. oldProps !== current.memoizedProps ||
  6825. oldState !== current.memoizedState
  6826. ) {
  6827. workInProgress.effectTag |= Snapshot;
  6828. }
  6829. } // If shouldComponentUpdate returned false, we should still update the
  6830. // memoized props/state to indicate that this work can be reused.
  6831. workInProgress.memoizedProps = newProps;
  6832. workInProgress.memoizedState = newState;
  6833. } // Update the existing instance's state, props, and context pointers even
  6834. // if shouldComponentUpdate returns false.
  6835. instance.props = newProps;
  6836. instance.state = newState;
  6837. instance.context = nextContext;
  6838. return shouldUpdate;
  6839. }
  6840. var didWarnAboutMaps;
  6841. var didWarnAboutGenerators;
  6842. var didWarnAboutStringRefs;
  6843. var ownerHasKeyUseWarning;
  6844. var ownerHasFunctionTypeWarning;
  6845. var warnForMissingKey = function(child) {};
  6846. {
  6847. didWarnAboutMaps = false;
  6848. didWarnAboutGenerators = false;
  6849. didWarnAboutStringRefs = {};
  6850. /**
  6851. * Warn if there's no key explicitly set on dynamic arrays of children or
  6852. * object keys are not valid. This allows us to keep track of children between
  6853. * updates.
  6854. */
  6855. ownerHasKeyUseWarning = {};
  6856. ownerHasFunctionTypeWarning = {};
  6857. warnForMissingKey = function(child) {
  6858. if (child === null || typeof child !== "object") {
  6859. return;
  6860. }
  6861. if (!child._store || child._store.validated || child.key != null) {
  6862. return;
  6863. }
  6864. if (!(typeof child._store === "object")) {
  6865. throw Error(
  6866. "React Component in warnForMissingKey should have a _store. This error is likely caused by a bug in React. Please file an issue."
  6867. );
  6868. }
  6869. child._store.validated = true;
  6870. var currentComponentErrorInfo =
  6871. "Each child in a list should have a unique " +
  6872. '"key" prop. See https://fb.me/react-warning-keys for ' +
  6873. "more information." +
  6874. getCurrentFiberStackInDev();
  6875. if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
  6876. return;
  6877. }
  6878. ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
  6879. error(
  6880. "Each child in a list should have a unique " +
  6881. '"key" prop. See https://fb.me/react-warning-keys for ' +
  6882. "more information."
  6883. );
  6884. };
  6885. }
  6886. var isArray$1 = Array.isArray;
  6887. function coerceRef(returnFiber, current, element) {
  6888. var mixedRef = element.ref;
  6889. if (
  6890. mixedRef !== null &&
  6891. typeof mixedRef !== "function" &&
  6892. typeof mixedRef !== "object"
  6893. ) {
  6894. {
  6895. // TODO: Clean this up once we turn on the string ref warning for
  6896. // everyone, because the strict mode case will no longer be relevant
  6897. if (
  6898. (returnFiber.mode & StrictMode || warnAboutStringRefs) && // We warn in ReactElement.js if owner and self are equal for string refs
  6899. // because these cannot be automatically converted to an arrow function
  6900. // using a codemod. Therefore, we don't have to warn about string refs again.
  6901. !(
  6902. element._owner &&
  6903. element._self &&
  6904. element._owner.stateNode !== element._self
  6905. )
  6906. ) {
  6907. var componentName = getComponentName(returnFiber.type) || "Component";
  6908. if (!didWarnAboutStringRefs[componentName]) {
  6909. {
  6910. error(
  6911. 'A string ref, "%s", has been found within a strict mode tree. ' +
  6912. "String refs are a source of potential bugs and should be avoided. " +
  6913. "We recommend using useRef() or createRef() instead. " +
  6914. "Learn more about using refs safely here: " +
  6915. "https://fb.me/react-strict-mode-string-ref%s",
  6916. mixedRef,
  6917. getStackByFiberInDevAndProd(returnFiber)
  6918. );
  6919. }
  6920. didWarnAboutStringRefs[componentName] = true;
  6921. }
  6922. }
  6923. }
  6924. if (element._owner) {
  6925. var owner = element._owner;
  6926. var inst;
  6927. if (owner) {
  6928. var ownerFiber = owner;
  6929. if (!(ownerFiber.tag === ClassComponent)) {
  6930. throw Error(
  6931. "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"
  6932. );
  6933. }
  6934. inst = ownerFiber.stateNode;
  6935. }
  6936. if (!inst) {
  6937. throw Error(
  6938. "Missing owner for string ref " +
  6939. mixedRef +
  6940. ". This error is likely caused by a bug in React. Please file an issue."
  6941. );
  6942. }
  6943. var stringRef = "" + mixedRef; // Check if previous string ref matches new string ref
  6944. if (
  6945. current !== null &&
  6946. current.ref !== null &&
  6947. typeof current.ref === "function" &&
  6948. current.ref._stringRef === stringRef
  6949. ) {
  6950. return current.ref;
  6951. }
  6952. var ref = function(value) {
  6953. var refs = inst.refs;
  6954. if (refs === emptyRefsObject) {
  6955. // This is a lazy pooled frozen object, so we need to initialize.
  6956. refs = inst.refs = {};
  6957. }
  6958. if (value === null) {
  6959. delete refs[stringRef];
  6960. } else {
  6961. refs[stringRef] = value;
  6962. }
  6963. };
  6964. ref._stringRef = stringRef;
  6965. return ref;
  6966. } else {
  6967. if (!(typeof mixedRef === "string")) {
  6968. throw Error(
  6969. "Expected ref to be a function, a string, an object returned by React.createRef(), or null."
  6970. );
  6971. }
  6972. if (!element._owner) {
  6973. throw Error(
  6974. "Element ref was specified as a string (" +
  6975. mixedRef +
  6976. ") 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."
  6977. );
  6978. }
  6979. }
  6980. }
  6981. return mixedRef;
  6982. }
  6983. function throwOnInvalidObjectType(returnFiber, newChild) {
  6984. if (returnFiber.type !== "textarea") {
  6985. var addendum = "";
  6986. {
  6987. addendum =
  6988. " If you meant to render a collection of children, use an array " +
  6989. "instead." +
  6990. getCurrentFiberStackInDev();
  6991. }
  6992. {
  6993. throw Error(
  6994. "Objects are not valid as a React child (found: " +
  6995. (Object.prototype.toString.call(newChild) === "[object Object]"
  6996. ? "object with keys {" + Object.keys(newChild).join(", ") + "}"
  6997. : newChild) +
  6998. ")." +
  6999. addendum
  7000. );
  7001. }
  7002. }
  7003. }
  7004. function warnOnFunctionType() {
  7005. {
  7006. var currentComponentErrorInfo =
  7007. "Functions are not valid as a React child. This may happen if " +
  7008. "you return a Component instead of <Component /> from render. " +
  7009. "Or maybe you meant to call this function rather than return it." +
  7010. getCurrentFiberStackInDev();
  7011. if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
  7012. return;
  7013. }
  7014. ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
  7015. error(
  7016. "Functions are not valid as a React child. This may happen if " +
  7017. "you return a Component instead of <Component /> from render. " +
  7018. "Or maybe you meant to call this function rather than return it."
  7019. );
  7020. }
  7021. } // This wrapper function exists because I expect to clone the code in each path
  7022. // to be able to optimize each path individually by branching early. This needs
  7023. // a compiler or we can do it manually. Helpers that don't need this branching
  7024. // live outside of this function.
  7025. function ChildReconciler(shouldTrackSideEffects) {
  7026. function deleteChild(returnFiber, childToDelete) {
  7027. if (!shouldTrackSideEffects) {
  7028. // Noop.
  7029. return;
  7030. } // Deletions are added in reversed order so we add it to the front.
  7031. // At this point, the return fiber's effect list is empty except for
  7032. // deletions, so we can just append the deletion to the list. The remaining
  7033. // effects aren't added until the complete phase. Once we implement
  7034. // resuming, this may not be true.
  7035. var last = returnFiber.lastEffect;
  7036. if (last !== null) {
  7037. last.nextEffect = childToDelete;
  7038. returnFiber.lastEffect = childToDelete;
  7039. } else {
  7040. returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
  7041. }
  7042. childToDelete.nextEffect = null;
  7043. childToDelete.effectTag = Deletion;
  7044. }
  7045. function deleteRemainingChildren(returnFiber, currentFirstChild) {
  7046. if (!shouldTrackSideEffects) {
  7047. // Noop.
  7048. return null;
  7049. } // TODO: For the shouldClone case, this could be micro-optimized a bit by
  7050. // assuming that after the first child we've already added everything.
  7051. var childToDelete = currentFirstChild;
  7052. while (childToDelete !== null) {
  7053. deleteChild(returnFiber, childToDelete);
  7054. childToDelete = childToDelete.sibling;
  7055. }
  7056. return null;
  7057. }
  7058. function mapRemainingChildren(returnFiber, currentFirstChild) {
  7059. // Add the remaining children to a temporary map so that we can find them by
  7060. // keys quickly. Implicit (null) keys get added to this set with their index
  7061. // instead.
  7062. var existingChildren = new Map();
  7063. var existingChild = currentFirstChild;
  7064. while (existingChild !== null) {
  7065. if (existingChild.key !== null) {
  7066. existingChildren.set(existingChild.key, existingChild);
  7067. } else {
  7068. existingChildren.set(existingChild.index, existingChild);
  7069. }
  7070. existingChild = existingChild.sibling;
  7071. }
  7072. return existingChildren;
  7073. }
  7074. function useFiber(fiber, pendingProps) {
  7075. // We currently set sibling to null and index to 0 here because it is easy
  7076. // to forget to do before returning it. E.g. for the single child case.
  7077. var clone = createWorkInProgress(fiber, pendingProps);
  7078. clone.index = 0;
  7079. clone.sibling = null;
  7080. return clone;
  7081. }
  7082. function placeChild(newFiber, lastPlacedIndex, newIndex) {
  7083. newFiber.index = newIndex;
  7084. if (!shouldTrackSideEffects) {
  7085. // Noop.
  7086. return lastPlacedIndex;
  7087. }
  7088. var current = newFiber.alternate;
  7089. if (current !== null) {
  7090. var oldIndex = current.index;
  7091. if (oldIndex < lastPlacedIndex) {
  7092. // This is a move.
  7093. newFiber.effectTag = Placement;
  7094. return lastPlacedIndex;
  7095. } else {
  7096. // This item can stay in place.
  7097. return oldIndex;
  7098. }
  7099. } else {
  7100. // This is an insertion.
  7101. newFiber.effectTag = Placement;
  7102. return lastPlacedIndex;
  7103. }
  7104. }
  7105. function placeSingleChild(newFiber) {
  7106. // This is simpler for the single child case. We only need to do a
  7107. // placement for inserting new children.
  7108. if (shouldTrackSideEffects && newFiber.alternate === null) {
  7109. newFiber.effectTag = Placement;
  7110. }
  7111. return newFiber;
  7112. }
  7113. function updateTextNode(returnFiber, current, textContent, expirationTime) {
  7114. if (current === null || current.tag !== HostText) {
  7115. // Insert
  7116. var created = createFiberFromText(
  7117. textContent,
  7118. returnFiber.mode,
  7119. expirationTime
  7120. );
  7121. created.return = returnFiber;
  7122. return created;
  7123. } else {
  7124. // Update
  7125. var existing = useFiber(current, textContent);
  7126. existing.return = returnFiber;
  7127. return existing;
  7128. }
  7129. }
  7130. function updateElement(returnFiber, current, element, expirationTime) {
  7131. if (current !== null) {
  7132. if (
  7133. current.elementType === element.type || // Keep this check inline so it only runs on the false path:
  7134. isCompatibleFamilyForHotReloading(current, element)
  7135. ) {
  7136. // Move based on index
  7137. var existing = useFiber(current, element.props);
  7138. existing.ref = coerceRef(returnFiber, current, element);
  7139. existing.return = returnFiber;
  7140. {
  7141. existing._debugSource = element._source;
  7142. existing._debugOwner = element._owner;
  7143. }
  7144. return existing;
  7145. }
  7146. } // Insert
  7147. var created = createFiberFromElement(
  7148. element,
  7149. returnFiber.mode,
  7150. expirationTime
  7151. );
  7152. created.ref = coerceRef(returnFiber, current, element);
  7153. created.return = returnFiber;
  7154. return created;
  7155. }
  7156. function updatePortal(returnFiber, current, portal, expirationTime) {
  7157. if (
  7158. current === null ||
  7159. current.tag !== HostPortal ||
  7160. current.stateNode.containerInfo !== portal.containerInfo ||
  7161. current.stateNode.implementation !== portal.implementation
  7162. ) {
  7163. // Insert
  7164. var created = createFiberFromPortal(
  7165. portal,
  7166. returnFiber.mode,
  7167. expirationTime
  7168. );
  7169. created.return = returnFiber;
  7170. return created;
  7171. } else {
  7172. // Update
  7173. var existing = useFiber(current, portal.children || []);
  7174. existing.return = returnFiber;
  7175. return existing;
  7176. }
  7177. }
  7178. function updateFragment(returnFiber, current, fragment, expirationTime, key) {
  7179. if (current === null || current.tag !== Fragment) {
  7180. // Insert
  7181. var created = createFiberFromFragment(
  7182. fragment,
  7183. returnFiber.mode,
  7184. expirationTime,
  7185. key
  7186. );
  7187. created.return = returnFiber;
  7188. return created;
  7189. } else {
  7190. // Update
  7191. var existing = useFiber(current, fragment);
  7192. existing.return = returnFiber;
  7193. return existing;
  7194. }
  7195. }
  7196. function createChild(returnFiber, newChild, expirationTime) {
  7197. if (typeof newChild === "string" || typeof newChild === "number") {
  7198. // Text nodes don't have keys. If the previous node is implicitly keyed
  7199. // we can continue to replace it without aborting even if it is not a text
  7200. // node.
  7201. var created = createFiberFromText(
  7202. "" + newChild,
  7203. returnFiber.mode,
  7204. expirationTime
  7205. );
  7206. created.return = returnFiber;
  7207. return created;
  7208. }
  7209. if (typeof newChild === "object" && newChild !== null) {
  7210. switch (newChild.$$typeof) {
  7211. case REACT_ELEMENT_TYPE: {
  7212. var _created = createFiberFromElement(
  7213. newChild,
  7214. returnFiber.mode,
  7215. expirationTime
  7216. );
  7217. _created.ref = coerceRef(returnFiber, null, newChild);
  7218. _created.return = returnFiber;
  7219. return _created;
  7220. }
  7221. case REACT_PORTAL_TYPE: {
  7222. var _created2 = createFiberFromPortal(
  7223. newChild,
  7224. returnFiber.mode,
  7225. expirationTime
  7226. );
  7227. _created2.return = returnFiber;
  7228. return _created2;
  7229. }
  7230. }
  7231. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  7232. var _created3 = createFiberFromFragment(
  7233. newChild,
  7234. returnFiber.mode,
  7235. expirationTime,
  7236. null
  7237. );
  7238. _created3.return = returnFiber;
  7239. return _created3;
  7240. }
  7241. throwOnInvalidObjectType(returnFiber, newChild);
  7242. }
  7243. {
  7244. if (typeof newChild === "function") {
  7245. warnOnFunctionType();
  7246. }
  7247. }
  7248. return null;
  7249. }
  7250. function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
  7251. // Update the fiber if the keys match, otherwise return null.
  7252. var key = oldFiber !== null ? oldFiber.key : null;
  7253. if (typeof newChild === "string" || typeof newChild === "number") {
  7254. // Text nodes don't have keys. If the previous node is implicitly keyed
  7255. // we can continue to replace it without aborting even if it is not a text
  7256. // node.
  7257. if (key !== null) {
  7258. return null;
  7259. }
  7260. return updateTextNode(
  7261. returnFiber,
  7262. oldFiber,
  7263. "" + newChild,
  7264. expirationTime
  7265. );
  7266. }
  7267. if (typeof newChild === "object" && newChild !== null) {
  7268. switch (newChild.$$typeof) {
  7269. case REACT_ELEMENT_TYPE: {
  7270. if (newChild.key === key) {
  7271. if (newChild.type === REACT_FRAGMENT_TYPE) {
  7272. return updateFragment(
  7273. returnFiber,
  7274. oldFiber,
  7275. newChild.props.children,
  7276. expirationTime,
  7277. key
  7278. );
  7279. }
  7280. return updateElement(
  7281. returnFiber,
  7282. oldFiber,
  7283. newChild,
  7284. expirationTime
  7285. );
  7286. } else {
  7287. return null;
  7288. }
  7289. }
  7290. case REACT_PORTAL_TYPE: {
  7291. if (newChild.key === key) {
  7292. return updatePortal(
  7293. returnFiber,
  7294. oldFiber,
  7295. newChild,
  7296. expirationTime
  7297. );
  7298. } else {
  7299. return null;
  7300. }
  7301. }
  7302. }
  7303. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  7304. if (key !== null) {
  7305. return null;
  7306. }
  7307. return updateFragment(
  7308. returnFiber,
  7309. oldFiber,
  7310. newChild,
  7311. expirationTime,
  7312. null
  7313. );
  7314. }
  7315. throwOnInvalidObjectType(returnFiber, newChild);
  7316. }
  7317. {
  7318. if (typeof newChild === "function") {
  7319. warnOnFunctionType();
  7320. }
  7321. }
  7322. return null;
  7323. }
  7324. function updateFromMap(
  7325. existingChildren,
  7326. returnFiber,
  7327. newIdx,
  7328. newChild,
  7329. expirationTime
  7330. ) {
  7331. if (typeof newChild === "string" || typeof newChild === "number") {
  7332. // Text nodes don't have keys, so we neither have to check the old nor
  7333. // new node for the key. If both are text nodes, they match.
  7334. var matchedFiber = existingChildren.get(newIdx) || null;
  7335. return updateTextNode(
  7336. returnFiber,
  7337. matchedFiber,
  7338. "" + newChild,
  7339. expirationTime
  7340. );
  7341. }
  7342. if (typeof newChild === "object" && newChild !== null) {
  7343. switch (newChild.$$typeof) {
  7344. case REACT_ELEMENT_TYPE: {
  7345. var _matchedFiber =
  7346. existingChildren.get(
  7347. newChild.key === null ? newIdx : newChild.key
  7348. ) || null;
  7349. if (newChild.type === REACT_FRAGMENT_TYPE) {
  7350. return updateFragment(
  7351. returnFiber,
  7352. _matchedFiber,
  7353. newChild.props.children,
  7354. expirationTime,
  7355. newChild.key
  7356. );
  7357. }
  7358. return updateElement(
  7359. returnFiber,
  7360. _matchedFiber,
  7361. newChild,
  7362. expirationTime
  7363. );
  7364. }
  7365. case REACT_PORTAL_TYPE: {
  7366. var _matchedFiber2 =
  7367. existingChildren.get(
  7368. newChild.key === null ? newIdx : newChild.key
  7369. ) || null;
  7370. return updatePortal(
  7371. returnFiber,
  7372. _matchedFiber2,
  7373. newChild,
  7374. expirationTime
  7375. );
  7376. }
  7377. }
  7378. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  7379. var _matchedFiber3 = existingChildren.get(newIdx) || null;
  7380. return updateFragment(
  7381. returnFiber,
  7382. _matchedFiber3,
  7383. newChild,
  7384. expirationTime,
  7385. null
  7386. );
  7387. }
  7388. throwOnInvalidObjectType(returnFiber, newChild);
  7389. }
  7390. {
  7391. if (typeof newChild === "function") {
  7392. warnOnFunctionType();
  7393. }
  7394. }
  7395. return null;
  7396. }
  7397. /**
  7398. * Warns if there is a duplicate or missing key
  7399. */
  7400. function warnOnInvalidKey(child, knownKeys) {
  7401. {
  7402. if (typeof child !== "object" || child === null) {
  7403. return knownKeys;
  7404. }
  7405. switch (child.$$typeof) {
  7406. case REACT_ELEMENT_TYPE:
  7407. case REACT_PORTAL_TYPE:
  7408. warnForMissingKey(child);
  7409. var key = child.key;
  7410. if (typeof key !== "string") {
  7411. break;
  7412. }
  7413. if (knownKeys === null) {
  7414. knownKeys = new Set();
  7415. knownKeys.add(key);
  7416. break;
  7417. }
  7418. if (!knownKeys.has(key)) {
  7419. knownKeys.add(key);
  7420. break;
  7421. }
  7422. error(
  7423. "Encountered two children with the same key, `%s`. " +
  7424. "Keys should be unique so that components maintain their identity " +
  7425. "across updates. Non-unique keys may cause children to be " +
  7426. "duplicated and/or omitted — the behavior is unsupported and " +
  7427. "could change in a future version.",
  7428. key
  7429. );
  7430. break;
  7431. }
  7432. }
  7433. return knownKeys;
  7434. }
  7435. function reconcileChildrenArray(
  7436. returnFiber,
  7437. currentFirstChild,
  7438. newChildren,
  7439. expirationTime
  7440. ) {
  7441. // This algorithm can't optimize by searching from both ends since we
  7442. // don't have backpointers on fibers. I'm trying to see how far we can get
  7443. // with that model. If it ends up not being worth the tradeoffs, we can
  7444. // add it later.
  7445. // Even with a two ended optimization, we'd want to optimize for the case
  7446. // where there are few changes and brute force the comparison instead of
  7447. // going for the Map. It'd like to explore hitting that path first in
  7448. // forward-only mode and only go for the Map once we notice that we need
  7449. // lots of look ahead. This doesn't handle reversal as well as two ended
  7450. // search but that's unusual. Besides, for the two ended optimization to
  7451. // work on Iterables, we'd need to copy the whole set.
  7452. // In this first iteration, we'll just live with hitting the bad case
  7453. // (adding everything to a Map) in for every insert/move.
  7454. // If you change this code, also update reconcileChildrenIterator() which
  7455. // uses the same algorithm.
  7456. {
  7457. // First, validate keys.
  7458. var knownKeys = null;
  7459. for (var i = 0; i < newChildren.length; i++) {
  7460. var child = newChildren[i];
  7461. knownKeys = warnOnInvalidKey(child, knownKeys);
  7462. }
  7463. }
  7464. var resultingFirstChild = null;
  7465. var previousNewFiber = null;
  7466. var oldFiber = currentFirstChild;
  7467. var lastPlacedIndex = 0;
  7468. var newIdx = 0;
  7469. var nextOldFiber = null;
  7470. for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
  7471. if (oldFiber.index > newIdx) {
  7472. nextOldFiber = oldFiber;
  7473. oldFiber = null;
  7474. } else {
  7475. nextOldFiber = oldFiber.sibling;
  7476. }
  7477. var newFiber = updateSlot(
  7478. returnFiber,
  7479. oldFiber,
  7480. newChildren[newIdx],
  7481. expirationTime
  7482. );
  7483. if (newFiber === null) {
  7484. // TODO: This breaks on empty slots like null children. That's
  7485. // unfortunate because it triggers the slow path all the time. We need
  7486. // a better way to communicate whether this was a miss or null,
  7487. // boolean, undefined, etc.
  7488. if (oldFiber === null) {
  7489. oldFiber = nextOldFiber;
  7490. }
  7491. break;
  7492. }
  7493. if (shouldTrackSideEffects) {
  7494. if (oldFiber && newFiber.alternate === null) {
  7495. // We matched the slot, but we didn't reuse the existing fiber, so we
  7496. // need to delete the existing child.
  7497. deleteChild(returnFiber, oldFiber);
  7498. }
  7499. }
  7500. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  7501. if (previousNewFiber === null) {
  7502. // TODO: Move out of the loop. This only happens for the first run.
  7503. resultingFirstChild = newFiber;
  7504. } else {
  7505. // TODO: Defer siblings if we're not at the right index for this slot.
  7506. // I.e. if we had null values before, then we want to defer this
  7507. // for each null value. However, we also don't want to call updateSlot
  7508. // with the previous one.
  7509. previousNewFiber.sibling = newFiber;
  7510. }
  7511. previousNewFiber = newFiber;
  7512. oldFiber = nextOldFiber;
  7513. }
  7514. if (newIdx === newChildren.length) {
  7515. // We've reached the end of the new children. We can delete the rest.
  7516. deleteRemainingChildren(returnFiber, oldFiber);
  7517. return resultingFirstChild;
  7518. }
  7519. if (oldFiber === null) {
  7520. // If we don't have any more existing children we can choose a fast path
  7521. // since the rest will all be insertions.
  7522. for (; newIdx < newChildren.length; newIdx++) {
  7523. var _newFiber = createChild(
  7524. returnFiber,
  7525. newChildren[newIdx],
  7526. expirationTime
  7527. );
  7528. if (_newFiber === null) {
  7529. continue;
  7530. }
  7531. lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
  7532. if (previousNewFiber === null) {
  7533. // TODO: Move out of the loop. This only happens for the first run.
  7534. resultingFirstChild = _newFiber;
  7535. } else {
  7536. previousNewFiber.sibling = _newFiber;
  7537. }
  7538. previousNewFiber = _newFiber;
  7539. }
  7540. return resultingFirstChild;
  7541. } // Add all children to a key map for quick lookups.
  7542. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  7543. for (; newIdx < newChildren.length; newIdx++) {
  7544. var _newFiber2 = updateFromMap(
  7545. existingChildren,
  7546. returnFiber,
  7547. newIdx,
  7548. newChildren[newIdx],
  7549. expirationTime
  7550. );
  7551. if (_newFiber2 !== null) {
  7552. if (shouldTrackSideEffects) {
  7553. if (_newFiber2.alternate !== null) {
  7554. // The new fiber is a work in progress, but if there exists a
  7555. // current, that means that we reused the fiber. We need to delete
  7556. // it from the child list so that we don't add it to the deletion
  7557. // list.
  7558. existingChildren.delete(
  7559. _newFiber2.key === null ? newIdx : _newFiber2.key
  7560. );
  7561. }
  7562. }
  7563. lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
  7564. if (previousNewFiber === null) {
  7565. resultingFirstChild = _newFiber2;
  7566. } else {
  7567. previousNewFiber.sibling = _newFiber2;
  7568. }
  7569. previousNewFiber = _newFiber2;
  7570. }
  7571. }
  7572. if (shouldTrackSideEffects) {
  7573. // Any existing children that weren't consumed above were deleted. We need
  7574. // to add them to the deletion list.
  7575. existingChildren.forEach(function(child) {
  7576. return deleteChild(returnFiber, child);
  7577. });
  7578. }
  7579. return resultingFirstChild;
  7580. }
  7581. function reconcileChildrenIterator(
  7582. returnFiber,
  7583. currentFirstChild,
  7584. newChildrenIterable,
  7585. expirationTime
  7586. ) {
  7587. // This is the same implementation as reconcileChildrenArray(),
  7588. // but using the iterator instead.
  7589. var iteratorFn = getIteratorFn(newChildrenIterable);
  7590. if (!(typeof iteratorFn === "function")) {
  7591. throw Error(
  7592. "An object is not an iterable. This error is likely caused by a bug in React. Please file an issue."
  7593. );
  7594. }
  7595. {
  7596. // We don't support rendering Generators because it's a mutation.
  7597. // See https://github.com/facebook/react/issues/12995
  7598. if (
  7599. typeof Symbol === "function" && // $FlowFixMe Flow doesn't know about toStringTag
  7600. newChildrenIterable[Symbol.toStringTag] === "Generator"
  7601. ) {
  7602. if (!didWarnAboutGenerators) {
  7603. error(
  7604. "Using Generators as children is unsupported and will likely yield " +
  7605. "unexpected results because enumerating a generator mutates it. " +
  7606. "You may convert it to an array with `Array.from()` or the " +
  7607. "`[...spread]` operator before rendering. Keep in mind " +
  7608. "you might need to polyfill these features for older browsers."
  7609. );
  7610. }
  7611. didWarnAboutGenerators = true;
  7612. } // Warn about using Maps as children
  7613. if (newChildrenIterable.entries === iteratorFn) {
  7614. if (!didWarnAboutMaps) {
  7615. error(
  7616. "Using Maps as children is unsupported and will likely yield " +
  7617. "unexpected results. Convert it to a sequence/iterable of keyed " +
  7618. "ReactElements instead."
  7619. );
  7620. }
  7621. didWarnAboutMaps = true;
  7622. } // First, validate keys.
  7623. // We'll get a different iterator later for the main pass.
  7624. var _newChildren = iteratorFn.call(newChildrenIterable);
  7625. if (_newChildren) {
  7626. var knownKeys = null;
  7627. var _step = _newChildren.next();
  7628. for (; !_step.done; _step = _newChildren.next()) {
  7629. var child = _step.value;
  7630. knownKeys = warnOnInvalidKey(child, knownKeys);
  7631. }
  7632. }
  7633. }
  7634. var newChildren = iteratorFn.call(newChildrenIterable);
  7635. if (!(newChildren != null)) {
  7636. throw Error("An iterable object provided no iterator.");
  7637. }
  7638. var resultingFirstChild = null;
  7639. var previousNewFiber = null;
  7640. var oldFiber = currentFirstChild;
  7641. var lastPlacedIndex = 0;
  7642. var newIdx = 0;
  7643. var nextOldFiber = null;
  7644. var step = newChildren.next();
  7645. for (
  7646. ;
  7647. oldFiber !== null && !step.done;
  7648. newIdx++, step = newChildren.next()
  7649. ) {
  7650. if (oldFiber.index > newIdx) {
  7651. nextOldFiber = oldFiber;
  7652. oldFiber = null;
  7653. } else {
  7654. nextOldFiber = oldFiber.sibling;
  7655. }
  7656. var newFiber = updateSlot(
  7657. returnFiber,
  7658. oldFiber,
  7659. step.value,
  7660. expirationTime
  7661. );
  7662. if (newFiber === null) {
  7663. // TODO: This breaks on empty slots like null children. That's
  7664. // unfortunate because it triggers the slow path all the time. We need
  7665. // a better way to communicate whether this was a miss or null,
  7666. // boolean, undefined, etc.
  7667. if (oldFiber === null) {
  7668. oldFiber = nextOldFiber;
  7669. }
  7670. break;
  7671. }
  7672. if (shouldTrackSideEffects) {
  7673. if (oldFiber && newFiber.alternate === null) {
  7674. // We matched the slot, but we didn't reuse the existing fiber, so we
  7675. // need to delete the existing child.
  7676. deleteChild(returnFiber, oldFiber);
  7677. }
  7678. }
  7679. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  7680. if (previousNewFiber === null) {
  7681. // TODO: Move out of the loop. This only happens for the first run.
  7682. resultingFirstChild = newFiber;
  7683. } else {
  7684. // TODO: Defer siblings if we're not at the right index for this slot.
  7685. // I.e. if we had null values before, then we want to defer this
  7686. // for each null value. However, we also don't want to call updateSlot
  7687. // with the previous one.
  7688. previousNewFiber.sibling = newFiber;
  7689. }
  7690. previousNewFiber = newFiber;
  7691. oldFiber = nextOldFiber;
  7692. }
  7693. if (step.done) {
  7694. // We've reached the end of the new children. We can delete the rest.
  7695. deleteRemainingChildren(returnFiber, oldFiber);
  7696. return resultingFirstChild;
  7697. }
  7698. if (oldFiber === null) {
  7699. // If we don't have any more existing children we can choose a fast path
  7700. // since the rest will all be insertions.
  7701. for (; !step.done; newIdx++, step = newChildren.next()) {
  7702. var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
  7703. if (_newFiber3 === null) {
  7704. continue;
  7705. }
  7706. lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
  7707. if (previousNewFiber === null) {
  7708. // TODO: Move out of the loop. This only happens for the first run.
  7709. resultingFirstChild = _newFiber3;
  7710. } else {
  7711. previousNewFiber.sibling = _newFiber3;
  7712. }
  7713. previousNewFiber = _newFiber3;
  7714. }
  7715. return resultingFirstChild;
  7716. } // Add all children to a key map for quick lookups.
  7717. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  7718. for (; !step.done; newIdx++, step = newChildren.next()) {
  7719. var _newFiber4 = updateFromMap(
  7720. existingChildren,
  7721. returnFiber,
  7722. newIdx,
  7723. step.value,
  7724. expirationTime
  7725. );
  7726. if (_newFiber4 !== null) {
  7727. if (shouldTrackSideEffects) {
  7728. if (_newFiber4.alternate !== null) {
  7729. // The new fiber is a work in progress, but if there exists a
  7730. // current, that means that we reused the fiber. We need to delete
  7731. // it from the child list so that we don't add it to the deletion
  7732. // list.
  7733. existingChildren.delete(
  7734. _newFiber4.key === null ? newIdx : _newFiber4.key
  7735. );
  7736. }
  7737. }
  7738. lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
  7739. if (previousNewFiber === null) {
  7740. resultingFirstChild = _newFiber4;
  7741. } else {
  7742. previousNewFiber.sibling = _newFiber4;
  7743. }
  7744. previousNewFiber = _newFiber4;
  7745. }
  7746. }
  7747. if (shouldTrackSideEffects) {
  7748. // Any existing children that weren't consumed above were deleted. We need
  7749. // to add them to the deletion list.
  7750. existingChildren.forEach(function(child) {
  7751. return deleteChild(returnFiber, child);
  7752. });
  7753. }
  7754. return resultingFirstChild;
  7755. }
  7756. function reconcileSingleTextNode(
  7757. returnFiber,
  7758. currentFirstChild,
  7759. textContent,
  7760. expirationTime
  7761. ) {
  7762. // There's no need to check for keys on text nodes since we don't have a
  7763. // way to define them.
  7764. if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
  7765. // We already have an existing node so let's just update it and delete
  7766. // the rest.
  7767. deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
  7768. var existing = useFiber(currentFirstChild, textContent);
  7769. existing.return = returnFiber;
  7770. return existing;
  7771. } // The existing first child is not a text node so we need to create one
  7772. // and delete the existing ones.
  7773. deleteRemainingChildren(returnFiber, currentFirstChild);
  7774. var created = createFiberFromText(
  7775. textContent,
  7776. returnFiber.mode,
  7777. expirationTime
  7778. );
  7779. created.return = returnFiber;
  7780. return created;
  7781. }
  7782. function reconcileSingleElement(
  7783. returnFiber,
  7784. currentFirstChild,
  7785. element,
  7786. expirationTime
  7787. ) {
  7788. var key = element.key;
  7789. var child = currentFirstChild;
  7790. while (child !== null) {
  7791. // TODO: If key === null and child.key === null, then this only applies to
  7792. // the first item in the list.
  7793. if (child.key === key) {
  7794. switch (child.tag) {
  7795. case Fragment: {
  7796. if (element.type === REACT_FRAGMENT_TYPE) {
  7797. deleteRemainingChildren(returnFiber, child.sibling);
  7798. var existing = useFiber(child, element.props.children);
  7799. existing.return = returnFiber;
  7800. {
  7801. existing._debugSource = element._source;
  7802. existing._debugOwner = element._owner;
  7803. }
  7804. return existing;
  7805. }
  7806. break;
  7807. }
  7808. case Block:
  7809. // We intentionally fallthrough here if enableBlocksAPI is not on.
  7810. // eslint-disable-next-lined no-fallthrough
  7811. default: {
  7812. if (
  7813. child.elementType === element.type || // Keep this check inline so it only runs on the false path:
  7814. isCompatibleFamilyForHotReloading(child, element)
  7815. ) {
  7816. deleteRemainingChildren(returnFiber, child.sibling);
  7817. var _existing3 = useFiber(child, element.props);
  7818. _existing3.ref = coerceRef(returnFiber, child, element);
  7819. _existing3.return = returnFiber;
  7820. {
  7821. _existing3._debugSource = element._source;
  7822. _existing3._debugOwner = element._owner;
  7823. }
  7824. return _existing3;
  7825. }
  7826. break;
  7827. }
  7828. } // Didn't match.
  7829. deleteRemainingChildren(returnFiber, child);
  7830. break;
  7831. } else {
  7832. deleteChild(returnFiber, child);
  7833. }
  7834. child = child.sibling;
  7835. }
  7836. if (element.type === REACT_FRAGMENT_TYPE) {
  7837. var created = createFiberFromFragment(
  7838. element.props.children,
  7839. returnFiber.mode,
  7840. expirationTime,
  7841. element.key
  7842. );
  7843. created.return = returnFiber;
  7844. return created;
  7845. } else {
  7846. var _created4 = createFiberFromElement(
  7847. element,
  7848. returnFiber.mode,
  7849. expirationTime
  7850. );
  7851. _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
  7852. _created4.return = returnFiber;
  7853. return _created4;
  7854. }
  7855. }
  7856. function reconcileSinglePortal(
  7857. returnFiber,
  7858. currentFirstChild,
  7859. portal,
  7860. expirationTime
  7861. ) {
  7862. var key = portal.key;
  7863. var child = currentFirstChild;
  7864. while (child !== null) {
  7865. // TODO: If key === null and child.key === null, then this only applies to
  7866. // the first item in the list.
  7867. if (child.key === key) {
  7868. if (
  7869. child.tag === HostPortal &&
  7870. child.stateNode.containerInfo === portal.containerInfo &&
  7871. child.stateNode.implementation === portal.implementation
  7872. ) {
  7873. deleteRemainingChildren(returnFiber, child.sibling);
  7874. var existing = useFiber(child, portal.children || []);
  7875. existing.return = returnFiber;
  7876. return existing;
  7877. } else {
  7878. deleteRemainingChildren(returnFiber, child);
  7879. break;
  7880. }
  7881. } else {
  7882. deleteChild(returnFiber, child);
  7883. }
  7884. child = child.sibling;
  7885. }
  7886. var created = createFiberFromPortal(
  7887. portal,
  7888. returnFiber.mode,
  7889. expirationTime
  7890. );
  7891. created.return = returnFiber;
  7892. return created;
  7893. } // This API will tag the children with the side-effect of the reconciliation
  7894. // itself. They will be added to the side-effect list as we pass through the
  7895. // children and the parent.
  7896. function reconcileChildFibers(
  7897. returnFiber,
  7898. currentFirstChild,
  7899. newChild,
  7900. expirationTime
  7901. ) {
  7902. // This function is not recursive.
  7903. // If the top level item is an array, we treat it as a set of children,
  7904. // not as a fragment. Nested arrays on the other hand will be treated as
  7905. // fragment nodes. Recursion happens at the normal flow.
  7906. // Handle top level unkeyed fragments as if they were arrays.
  7907. // This leads to an ambiguity between <>{[...]}</> and <>...</>.
  7908. // We treat the ambiguous cases above the same.
  7909. var isUnkeyedTopLevelFragment =
  7910. typeof newChild === "object" &&
  7911. newChild !== null &&
  7912. newChild.type === REACT_FRAGMENT_TYPE &&
  7913. newChild.key === null;
  7914. if (isUnkeyedTopLevelFragment) {
  7915. newChild = newChild.props.children;
  7916. } // Handle object types
  7917. var isObject = typeof newChild === "object" && newChild !== null;
  7918. if (isObject) {
  7919. switch (newChild.$$typeof) {
  7920. case REACT_ELEMENT_TYPE:
  7921. return placeSingleChild(
  7922. reconcileSingleElement(
  7923. returnFiber,
  7924. currentFirstChild,
  7925. newChild,
  7926. expirationTime
  7927. )
  7928. );
  7929. case REACT_PORTAL_TYPE:
  7930. return placeSingleChild(
  7931. reconcileSinglePortal(
  7932. returnFiber,
  7933. currentFirstChild,
  7934. newChild,
  7935. expirationTime
  7936. )
  7937. );
  7938. }
  7939. }
  7940. if (typeof newChild === "string" || typeof newChild === "number") {
  7941. return placeSingleChild(
  7942. reconcileSingleTextNode(
  7943. returnFiber,
  7944. currentFirstChild,
  7945. "" + newChild,
  7946. expirationTime
  7947. )
  7948. );
  7949. }
  7950. if (isArray$1(newChild)) {
  7951. return reconcileChildrenArray(
  7952. returnFiber,
  7953. currentFirstChild,
  7954. newChild,
  7955. expirationTime
  7956. );
  7957. }
  7958. if (getIteratorFn(newChild)) {
  7959. return reconcileChildrenIterator(
  7960. returnFiber,
  7961. currentFirstChild,
  7962. newChild,
  7963. expirationTime
  7964. );
  7965. }
  7966. if (isObject) {
  7967. throwOnInvalidObjectType(returnFiber, newChild);
  7968. }
  7969. {
  7970. if (typeof newChild === "function") {
  7971. warnOnFunctionType();
  7972. }
  7973. }
  7974. if (typeof newChild === "undefined" && !isUnkeyedTopLevelFragment) {
  7975. // If the new child is undefined, and the return fiber is a composite
  7976. // component, throw an error. If Fiber return types are disabled,
  7977. // we already threw above.
  7978. switch (returnFiber.tag) {
  7979. case ClassComponent: {
  7980. {
  7981. var instance = returnFiber.stateNode;
  7982. if (instance.render._isMockFunction) {
  7983. // We allow auto-mocks to proceed as if they're returning null.
  7984. break;
  7985. }
  7986. }
  7987. }
  7988. // Intentionally fall through to the next case, which handles both
  7989. // functions and classes
  7990. // eslint-disable-next-lined no-fallthrough
  7991. case FunctionComponent: {
  7992. var Component = returnFiber.type;
  7993. {
  7994. throw Error(
  7995. (Component.displayName || Component.name || "Component") +
  7996. "(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null."
  7997. );
  7998. }
  7999. }
  8000. }
  8001. } // Remaining cases are all treated as empty.
  8002. return deleteRemainingChildren(returnFiber, currentFirstChild);
  8003. }
  8004. return reconcileChildFibers;
  8005. }
  8006. var reconcileChildFibers = ChildReconciler(true);
  8007. var mountChildFibers = ChildReconciler(false);
  8008. function cloneChildFibers(current, workInProgress) {
  8009. if (!(current === null || workInProgress.child === current.child)) {
  8010. throw Error("Resuming work not yet implemented.");
  8011. }
  8012. if (workInProgress.child === null) {
  8013. return;
  8014. }
  8015. var currentChild = workInProgress.child;
  8016. var newChild = createWorkInProgress(currentChild, currentChild.pendingProps);
  8017. workInProgress.child = newChild;
  8018. newChild.return = workInProgress;
  8019. while (currentChild.sibling !== null) {
  8020. currentChild = currentChild.sibling;
  8021. newChild = newChild.sibling = createWorkInProgress(
  8022. currentChild,
  8023. currentChild.pendingProps
  8024. );
  8025. newChild.return = workInProgress;
  8026. }
  8027. newChild.sibling = null;
  8028. } // Reset a workInProgress child set to prepare it for a second pass.
  8029. function resetChildFibers(workInProgress, renderExpirationTime) {
  8030. var child = workInProgress.child;
  8031. while (child !== null) {
  8032. resetWorkInProgress(child, renderExpirationTime);
  8033. child = child.sibling;
  8034. }
  8035. }
  8036. var NO_CONTEXT = {};
  8037. var contextStackCursor$1 = createCursor(NO_CONTEXT);
  8038. var contextFiberStackCursor = createCursor(NO_CONTEXT);
  8039. var rootInstanceStackCursor = createCursor(NO_CONTEXT);
  8040. function requiredContext(c) {
  8041. if (!(c !== NO_CONTEXT)) {
  8042. throw Error(
  8043. "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue."
  8044. );
  8045. }
  8046. return c;
  8047. }
  8048. function getRootHostContainer() {
  8049. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  8050. return rootInstance;
  8051. }
  8052. function pushHostContainer(fiber, nextRootInstance) {
  8053. // Push current root instance onto the stack;
  8054. // This allows us to reset root when portals are popped.
  8055. push(rootInstanceStackCursor, nextRootInstance, fiber); // Track the context and the Fiber that provided it.
  8056. // This enables us to pop only Fibers that provide unique contexts.
  8057. push(contextFiberStackCursor, fiber, fiber); // Finally, we need to push the host context to the stack.
  8058. // However, we can't just call getRootHostContext() and push it because
  8059. // we'd have a different number of entries on the stack depending on
  8060. // whether getRootHostContext() throws somewhere in renderer code or not.
  8061. // So we push an empty value first. This lets us safely unwind on errors.
  8062. push(contextStackCursor$1, NO_CONTEXT, fiber);
  8063. var nextRootContext = getRootHostContext(); // Now that we know this function doesn't throw, replace it.
  8064. pop(contextStackCursor$1, fiber);
  8065. push(contextStackCursor$1, nextRootContext, fiber);
  8066. }
  8067. function popHostContainer(fiber) {
  8068. pop(contextStackCursor$1, fiber);
  8069. pop(contextFiberStackCursor, fiber);
  8070. pop(rootInstanceStackCursor, fiber);
  8071. }
  8072. function getHostContext() {
  8073. var context = requiredContext(contextStackCursor$1.current);
  8074. return context;
  8075. }
  8076. function pushHostContext(fiber) {
  8077. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  8078. var context = requiredContext(contextStackCursor$1.current);
  8079. var nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique.
  8080. if (context === nextContext) {
  8081. return;
  8082. } // Track the context and the Fiber that provided it.
  8083. // This enables us to pop only Fibers that provide unique contexts.
  8084. push(contextFiberStackCursor, fiber, fiber);
  8085. push(contextStackCursor$1, nextContext, fiber);
  8086. }
  8087. function popHostContext(fiber) {
  8088. // Do not pop unless this Fiber provided the current context.
  8089. // pushHostContext() only pushes Fibers that provide unique contexts.
  8090. if (contextFiberStackCursor.current !== fiber) {
  8091. return;
  8092. }
  8093. pop(contextStackCursor$1, fiber);
  8094. pop(contextFiberStackCursor, fiber);
  8095. }
  8096. var DefaultSuspenseContext = 0; // The Suspense Context is split into two parts. The lower bits is
  8097. // inherited deeply down the subtree. The upper bits only affect
  8098. // this immediate suspense boundary and gets reset each new
  8099. // boundary or suspense list.
  8100. var SubtreeSuspenseContextMask = 1; // Subtree Flags:
  8101. // InvisibleParentSuspenseContext indicates that one of our parent Suspense
  8102. // boundaries is not currently showing visible main content.
  8103. // Either because it is already showing a fallback or is not mounted at all.
  8104. // We can use this to determine if it is desirable to trigger a fallback at
  8105. // the parent. If not, then we might need to trigger undesirable boundaries
  8106. // and/or suspend the commit to avoid hiding the parent content.
  8107. var InvisibleParentSuspenseContext = 1; // Shallow Flags:
  8108. // ForceSuspenseFallback can be used by SuspenseList to force newly added
  8109. // items into their fallback state during one of the render passes.
  8110. var ForceSuspenseFallback = 2;
  8111. var suspenseStackCursor = createCursor(DefaultSuspenseContext);
  8112. function hasSuspenseContext(parentContext, flag) {
  8113. return (parentContext & flag) !== 0;
  8114. }
  8115. function setDefaultShallowSuspenseContext(parentContext) {
  8116. return parentContext & SubtreeSuspenseContextMask;
  8117. }
  8118. function setShallowSuspenseContext(parentContext, shallowContext) {
  8119. return (parentContext & SubtreeSuspenseContextMask) | shallowContext;
  8120. }
  8121. function addSubtreeSuspenseContext(parentContext, subtreeContext) {
  8122. return parentContext | subtreeContext;
  8123. }
  8124. function pushSuspenseContext(fiber, newContext) {
  8125. push(suspenseStackCursor, newContext, fiber);
  8126. }
  8127. function popSuspenseContext(fiber) {
  8128. pop(suspenseStackCursor, fiber);
  8129. }
  8130. function shouldCaptureSuspense(workInProgress, hasInvisibleParent) {
  8131. // If it was the primary children that just suspended, capture and render the
  8132. // fallback. Otherwise, don't capture and bubble to the next boundary.
  8133. var nextState = workInProgress.memoizedState;
  8134. if (nextState !== null) {
  8135. if (nextState.dehydrated !== null) {
  8136. // A dehydrated boundary always captures.
  8137. return true;
  8138. }
  8139. return false;
  8140. }
  8141. var props = workInProgress.memoizedProps; // In order to capture, the Suspense component must have a fallback prop.
  8142. if (props.fallback === undefined) {
  8143. return false;
  8144. } // Regular boundaries always capture.
  8145. if (props.unstable_avoidThisFallback !== true) {
  8146. return true;
  8147. } // If it's a boundary we should avoid, then we prefer to bubble up to the
  8148. // parent boundary if it is currently invisible.
  8149. if (hasInvisibleParent) {
  8150. return false;
  8151. } // If the parent is not able to handle it, we must handle it.
  8152. return true;
  8153. }
  8154. function findFirstSuspended(row) {
  8155. var node = row;
  8156. while (node !== null) {
  8157. if (node.tag === SuspenseComponent) {
  8158. var state = node.memoizedState;
  8159. if (state !== null) {
  8160. var dehydrated = state.dehydrated;
  8161. if (
  8162. dehydrated === null ||
  8163. isSuspenseInstancePending() ||
  8164. isSuspenseInstanceFallback()
  8165. ) {
  8166. return node;
  8167. }
  8168. }
  8169. } else if (
  8170. node.tag === SuspenseListComponent && // revealOrder undefined can't be trusted because it don't
  8171. // keep track of whether it suspended or not.
  8172. node.memoizedProps.revealOrder !== undefined
  8173. ) {
  8174. var didSuspend = (node.effectTag & DidCapture) !== NoEffect;
  8175. if (didSuspend) {
  8176. return node;
  8177. }
  8178. } else if (node.child !== null) {
  8179. node.child.return = node;
  8180. node = node.child;
  8181. continue;
  8182. }
  8183. if (node === row) {
  8184. return null;
  8185. }
  8186. while (node.sibling === null) {
  8187. if (node.return === null || node.return === row) {
  8188. return null;
  8189. }
  8190. node = node.return;
  8191. }
  8192. node.sibling.return = node.return;
  8193. node = node.sibling;
  8194. }
  8195. return null;
  8196. }
  8197. function createDeprecatedResponderListener(responder, props) {
  8198. var eventResponderListener = {
  8199. responder: responder,
  8200. props: props
  8201. };
  8202. {
  8203. Object.freeze(eventResponderListener);
  8204. }
  8205. return eventResponderListener;
  8206. }
  8207. var HasEffect =
  8208. /* */
  8209. 1; // Represents the phase in which the effect (not the clean-up) fires.
  8210. var Layout =
  8211. /* */
  8212. 2;
  8213. var Passive$1 =
  8214. /* */
  8215. 4;
  8216. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher,
  8217. ReactCurrentBatchConfig$1 = ReactSharedInternals.ReactCurrentBatchConfig;
  8218. var didWarnAboutMismatchedHooksForComponent;
  8219. {
  8220. didWarnAboutMismatchedHooksForComponent = new Set();
  8221. }
  8222. // These are set right before calling the component.
  8223. var renderExpirationTime = NoWork; // The work-in-progress fiber. I've named it differently to distinguish it from
  8224. // the work-in-progress hook.
  8225. var currentlyRenderingFiber$1 = null; // Hooks are stored as a linked list on the fiber's memoizedState field. The
  8226. // current hook list is the list that belongs to the current fiber. The
  8227. // work-in-progress hook list is a new list that will be added to the
  8228. // work-in-progress fiber.
  8229. var currentHook = null;
  8230. var workInProgressHook = null; // Whether an update was scheduled at any point during the render phase. This
  8231. // does not get reset if we do another render pass; only when we're completely
  8232. // finished evaluating this component. This is an optimization so we know
  8233. // whether we need to clear render phase updates after a throw.
  8234. var didScheduleRenderPhaseUpdate = false;
  8235. var RE_RENDER_LIMIT = 25; // In DEV, this is the name of the currently executing primitive hook
  8236. var currentHookNameInDev = null; // In DEV, this list ensures that hooks are called in the same order between renders.
  8237. // The list stores the order of hooks used during the initial render (mount).
  8238. // Subsequent renders (updates) reference this list.
  8239. var hookTypesDev = null;
  8240. var hookTypesUpdateIndexDev = -1; // In DEV, this tracks whether currently rendering component needs to ignore
  8241. // the dependencies for Hooks that need them (e.g. useEffect or useMemo).
  8242. // When true, such Hooks will always be "remounted". Only used during hot reload.
  8243. var ignorePreviousDependencies = false;
  8244. function mountHookTypesDev() {
  8245. {
  8246. var hookName = currentHookNameInDev;
  8247. if (hookTypesDev === null) {
  8248. hookTypesDev = [hookName];
  8249. } else {
  8250. hookTypesDev.push(hookName);
  8251. }
  8252. }
  8253. }
  8254. function updateHookTypesDev() {
  8255. {
  8256. var hookName = currentHookNameInDev;
  8257. if (hookTypesDev !== null) {
  8258. hookTypesUpdateIndexDev++;
  8259. if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
  8260. warnOnHookMismatchInDev(hookName);
  8261. }
  8262. }
  8263. }
  8264. }
  8265. function checkDepsAreArrayDev(deps) {
  8266. {
  8267. if (deps !== undefined && deps !== null && !Array.isArray(deps)) {
  8268. // Verify deps, but only on mount to avoid extra checks.
  8269. // It's unlikely their type would change as usually you define them inline.
  8270. error(
  8271. "%s received a final argument that is not an array (instead, received `%s`). When " +
  8272. "specified, the final argument must be an array.",
  8273. currentHookNameInDev,
  8274. typeof deps
  8275. );
  8276. }
  8277. }
  8278. }
  8279. function warnOnHookMismatchInDev(currentHookName) {
  8280. {
  8281. var componentName = getComponentName(currentlyRenderingFiber$1.type);
  8282. if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
  8283. didWarnAboutMismatchedHooksForComponent.add(componentName);
  8284. if (hookTypesDev !== null) {
  8285. var table = "";
  8286. var secondColumnStart = 30;
  8287. for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
  8288. var oldHookName = hookTypesDev[i];
  8289. var newHookName =
  8290. i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
  8291. var row = i + 1 + ". " + oldHookName; // Extra space so second column lines up
  8292. // lol @ IE not supporting String#repeat
  8293. while (row.length < secondColumnStart) {
  8294. row += " ";
  8295. }
  8296. row += newHookName + "\n";
  8297. table += row;
  8298. }
  8299. error(
  8300. "React has detected a change in the order of Hooks called by %s. " +
  8301. "This will lead to bugs and errors if not fixed. " +
  8302. "For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks\n\n" +
  8303. " Previous render Next render\n" +
  8304. " ------------------------------------------------------\n" +
  8305. "%s" +
  8306. " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
  8307. componentName,
  8308. table
  8309. );
  8310. }
  8311. }
  8312. }
  8313. }
  8314. function throwInvalidHookError() {
  8315. {
  8316. throw Error(
  8317. "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."
  8318. );
  8319. }
  8320. }
  8321. function areHookInputsEqual(nextDeps, prevDeps) {
  8322. {
  8323. if (ignorePreviousDependencies) {
  8324. // Only true when this component is being hot reloaded.
  8325. return false;
  8326. }
  8327. }
  8328. if (prevDeps === null) {
  8329. {
  8330. error(
  8331. "%s received a final argument during this render, but not during " +
  8332. "the previous render. Even though the final argument is optional, " +
  8333. "its type cannot change between renders.",
  8334. currentHookNameInDev
  8335. );
  8336. }
  8337. return false;
  8338. }
  8339. {
  8340. // Don't bother comparing lengths in prod because these arrays should be
  8341. // passed inline.
  8342. if (nextDeps.length !== prevDeps.length) {
  8343. error(
  8344. "The final argument passed to %s changed size between renders. The " +
  8345. "order and size of this array must remain constant.\n\n" +
  8346. "Previous: %s\n" +
  8347. "Incoming: %s",
  8348. currentHookNameInDev,
  8349. "[" + prevDeps.join(", ") + "]",
  8350. "[" + nextDeps.join(", ") + "]"
  8351. );
  8352. }
  8353. }
  8354. for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
  8355. if (objectIs(nextDeps[i], prevDeps[i])) {
  8356. continue;
  8357. }
  8358. return false;
  8359. }
  8360. return true;
  8361. }
  8362. function renderWithHooks(
  8363. current,
  8364. workInProgress,
  8365. Component,
  8366. props,
  8367. secondArg,
  8368. nextRenderExpirationTime
  8369. ) {
  8370. renderExpirationTime = nextRenderExpirationTime;
  8371. currentlyRenderingFiber$1 = workInProgress;
  8372. {
  8373. hookTypesDev = current !== null ? current._debugHookTypes : null;
  8374. hookTypesUpdateIndexDev = -1; // Used for hot reloading:
  8375. ignorePreviousDependencies =
  8376. current !== null && current.type !== workInProgress.type;
  8377. }
  8378. workInProgress.memoizedState = null;
  8379. workInProgress.updateQueue = null;
  8380. workInProgress.expirationTime = NoWork; // The following should have already been reset
  8381. // currentHook = null;
  8382. // workInProgressHook = null;
  8383. // didScheduleRenderPhaseUpdate = false;
  8384. // TODO Warn if no hooks are used at all during mount, then some are used during update.
  8385. // Currently we will identify the update render as a mount because memoizedState === null.
  8386. // This is tricky because it's valid for certain types of components (e.g. React.lazy)
  8387. // Using memoizedState to differentiate between mount/update only works if at least one stateful hook is used.
  8388. // Non-stateful hooks (e.g. context) don't get added to memoizedState,
  8389. // so memoizedState would be null during updates and mounts.
  8390. {
  8391. if (current !== null && current.memoizedState !== null) {
  8392. ReactCurrentDispatcher.current = HooksDispatcherOnUpdateInDEV;
  8393. } else if (hookTypesDev !== null) {
  8394. // This dispatcher handles an edge case where a component is updating,
  8395. // but no stateful hooks have been used.
  8396. // We want to match the production code behavior (which will use HooksDispatcherOnMount),
  8397. // but with the extra DEV validation to ensure hooks ordering hasn't changed.
  8398. // This dispatcher does that.
  8399. ReactCurrentDispatcher.current = HooksDispatcherOnMountWithHookTypesInDEV;
  8400. } else {
  8401. ReactCurrentDispatcher.current = HooksDispatcherOnMountInDEV;
  8402. }
  8403. }
  8404. var children = Component(props, secondArg); // Check if there was a render phase update
  8405. if (workInProgress.expirationTime === renderExpirationTime) {
  8406. // Keep rendering in a loop for as long as render phase updates continue to
  8407. // be scheduled. Use a counter to prevent infinite loops.
  8408. var numberOfReRenders = 0;
  8409. do {
  8410. workInProgress.expirationTime = NoWork;
  8411. if (!(numberOfReRenders < RE_RENDER_LIMIT)) {
  8412. throw Error(
  8413. "Too many re-renders. React limits the number of renders to prevent an infinite loop."
  8414. );
  8415. }
  8416. numberOfReRenders += 1;
  8417. {
  8418. // Even when hot reloading, allow dependencies to stabilize
  8419. // after first render to prevent infinite render phase updates.
  8420. ignorePreviousDependencies = false;
  8421. } // Start over from the beginning of the list
  8422. currentHook = null;
  8423. workInProgressHook = null;
  8424. workInProgress.updateQueue = null;
  8425. {
  8426. // Also validate hook order for cascading updates.
  8427. hookTypesUpdateIndexDev = -1;
  8428. }
  8429. ReactCurrentDispatcher.current = HooksDispatcherOnRerenderInDEV;
  8430. children = Component(props, secondArg);
  8431. } while (workInProgress.expirationTime === renderExpirationTime);
  8432. } // We can assume the previous dispatcher is always this one, since we set it
  8433. // at the beginning of the render phase and there's no re-entrancy.
  8434. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  8435. {
  8436. workInProgress._debugHookTypes = hookTypesDev;
  8437. } // This check uses currentHook so that it works the same in DEV and prod bundles.
  8438. // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
  8439. var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
  8440. renderExpirationTime = NoWork;
  8441. currentlyRenderingFiber$1 = null;
  8442. currentHook = null;
  8443. workInProgressHook = null;
  8444. {
  8445. currentHookNameInDev = null;
  8446. hookTypesDev = null;
  8447. hookTypesUpdateIndexDev = -1;
  8448. }
  8449. didScheduleRenderPhaseUpdate = false;
  8450. if (!!didRenderTooFewHooks) {
  8451. throw Error(
  8452. "Rendered fewer hooks than expected. This may be caused by an accidental early return statement."
  8453. );
  8454. }
  8455. return children;
  8456. }
  8457. function bailoutHooks(current, workInProgress, expirationTime) {
  8458. workInProgress.updateQueue = current.updateQueue;
  8459. workInProgress.effectTag &= ~(Passive | Update);
  8460. if (current.expirationTime <= expirationTime) {
  8461. current.expirationTime = NoWork;
  8462. }
  8463. }
  8464. function resetHooksAfterThrow() {
  8465. // We can assume the previous dispatcher is always this one, since we set it
  8466. // at the beginning of the render phase and there's no re-entrancy.
  8467. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  8468. if (didScheduleRenderPhaseUpdate) {
  8469. // There were render phase updates. These are only valid for this render
  8470. // phase, which we are now aborting. Remove the updates from the queues so
  8471. // they do not persist to the next render. Do not remove updates from hooks
  8472. // that weren't processed.
  8473. //
  8474. // Only reset the updates from the queue if it has a clone. If it does
  8475. // not have a clone, that means it wasn't processed, and the updates were
  8476. // scheduled before we entered the render phase.
  8477. var hook = currentlyRenderingFiber$1.memoizedState;
  8478. while (hook !== null) {
  8479. var queue = hook.queue;
  8480. if (queue !== null) {
  8481. queue.pending = null;
  8482. }
  8483. hook = hook.next;
  8484. }
  8485. }
  8486. renderExpirationTime = NoWork;
  8487. currentlyRenderingFiber$1 = null;
  8488. currentHook = null;
  8489. workInProgressHook = null;
  8490. {
  8491. hookTypesDev = null;
  8492. hookTypesUpdateIndexDev = -1;
  8493. currentHookNameInDev = null;
  8494. }
  8495. didScheduleRenderPhaseUpdate = false;
  8496. }
  8497. function mountWorkInProgressHook() {
  8498. var hook = {
  8499. memoizedState: null,
  8500. baseState: null,
  8501. baseQueue: null,
  8502. queue: null,
  8503. next: null
  8504. };
  8505. if (workInProgressHook === null) {
  8506. // This is the first hook in the list
  8507. currentlyRenderingFiber$1.memoizedState = workInProgressHook = hook;
  8508. } else {
  8509. // Append to the end of the list
  8510. workInProgressHook = workInProgressHook.next = hook;
  8511. }
  8512. return workInProgressHook;
  8513. }
  8514. function updateWorkInProgressHook() {
  8515. // This function is used both for updates and for re-renders triggered by a
  8516. // render phase update. It assumes there is either a current hook we can
  8517. // clone, or a work-in-progress hook from a previous render pass that we can
  8518. // use as a base. When we reach the end of the base list, we must switch to
  8519. // the dispatcher used for mounts.
  8520. var nextCurrentHook;
  8521. if (currentHook === null) {
  8522. var current = currentlyRenderingFiber$1.alternate;
  8523. if (current !== null) {
  8524. nextCurrentHook = current.memoizedState;
  8525. } else {
  8526. nextCurrentHook = null;
  8527. }
  8528. } else {
  8529. nextCurrentHook = currentHook.next;
  8530. }
  8531. var nextWorkInProgressHook;
  8532. if (workInProgressHook === null) {
  8533. nextWorkInProgressHook = currentlyRenderingFiber$1.memoizedState;
  8534. } else {
  8535. nextWorkInProgressHook = workInProgressHook.next;
  8536. }
  8537. if (nextWorkInProgressHook !== null) {
  8538. // There's already a work-in-progress. Reuse it.
  8539. workInProgressHook = nextWorkInProgressHook;
  8540. nextWorkInProgressHook = workInProgressHook.next;
  8541. currentHook = nextCurrentHook;
  8542. } else {
  8543. // Clone from the current hook.
  8544. if (!(nextCurrentHook !== null)) {
  8545. throw Error("Rendered more hooks than during the previous render.");
  8546. }
  8547. currentHook = nextCurrentHook;
  8548. var newHook = {
  8549. memoizedState: currentHook.memoizedState,
  8550. baseState: currentHook.baseState,
  8551. baseQueue: currentHook.baseQueue,
  8552. queue: currentHook.queue,
  8553. next: null
  8554. };
  8555. if (workInProgressHook === null) {
  8556. // This is the first hook in the list.
  8557. currentlyRenderingFiber$1.memoizedState = workInProgressHook = newHook;
  8558. } else {
  8559. // Append to the end of the list.
  8560. workInProgressHook = workInProgressHook.next = newHook;
  8561. }
  8562. }
  8563. return workInProgressHook;
  8564. }
  8565. function createFunctionComponentUpdateQueue() {
  8566. return {
  8567. lastEffect: null
  8568. };
  8569. }
  8570. function basicStateReducer(state, action) {
  8571. // $FlowFixMe: Flow doesn't like mixed types
  8572. return typeof action === "function" ? action(state) : action;
  8573. }
  8574. function mountReducer(reducer, initialArg, init) {
  8575. var hook = mountWorkInProgressHook();
  8576. var initialState;
  8577. if (init !== undefined) {
  8578. initialState = init(initialArg);
  8579. } else {
  8580. initialState = initialArg;
  8581. }
  8582. hook.memoizedState = hook.baseState = initialState;
  8583. var queue = (hook.queue = {
  8584. pending: null,
  8585. dispatch: null,
  8586. lastRenderedReducer: reducer,
  8587. lastRenderedState: initialState
  8588. });
  8589. var dispatch = (queue.dispatch = dispatchAction.bind(
  8590. null,
  8591. currentlyRenderingFiber$1,
  8592. queue
  8593. ));
  8594. return [hook.memoizedState, dispatch];
  8595. }
  8596. function updateReducer(reducer, initialArg, init) {
  8597. var hook = updateWorkInProgressHook();
  8598. var queue = hook.queue;
  8599. if (!(queue !== null)) {
  8600. throw Error(
  8601. "Should have a queue. This is likely a bug in React. Please file an issue."
  8602. );
  8603. }
  8604. queue.lastRenderedReducer = reducer;
  8605. var current = currentHook; // The last rebase update that is NOT part of the base state.
  8606. var baseQueue = current.baseQueue; // The last pending update that hasn't been processed yet.
  8607. var pendingQueue = queue.pending;
  8608. if (pendingQueue !== null) {
  8609. // We have new updates that haven't been processed yet.
  8610. // We'll add them to the base queue.
  8611. if (baseQueue !== null) {
  8612. // Merge the pending queue and the base queue.
  8613. var baseFirst = baseQueue.next;
  8614. var pendingFirst = pendingQueue.next;
  8615. baseQueue.next = pendingFirst;
  8616. pendingQueue.next = baseFirst;
  8617. }
  8618. current.baseQueue = baseQueue = pendingQueue;
  8619. queue.pending = null;
  8620. }
  8621. if (baseQueue !== null) {
  8622. // We have a queue to process.
  8623. var first = baseQueue.next;
  8624. var newState = current.baseState;
  8625. var newBaseState = null;
  8626. var newBaseQueueFirst = null;
  8627. var newBaseQueueLast = null;
  8628. var update = first;
  8629. do {
  8630. var updateExpirationTime = update.expirationTime;
  8631. if (updateExpirationTime < renderExpirationTime) {
  8632. // Priority is insufficient. Skip this update. If this is the first
  8633. // skipped update, the previous update/state is the new base
  8634. // update/state.
  8635. var clone = {
  8636. expirationTime: update.expirationTime,
  8637. suspenseConfig: update.suspenseConfig,
  8638. action: update.action,
  8639. eagerReducer: update.eagerReducer,
  8640. eagerState: update.eagerState,
  8641. next: null
  8642. };
  8643. if (newBaseQueueLast === null) {
  8644. newBaseQueueFirst = newBaseQueueLast = clone;
  8645. newBaseState = newState;
  8646. } else {
  8647. newBaseQueueLast = newBaseQueueLast.next = clone;
  8648. } // Update the remaining priority in the queue.
  8649. if (updateExpirationTime > currentlyRenderingFiber$1.expirationTime) {
  8650. currentlyRenderingFiber$1.expirationTime = updateExpirationTime;
  8651. markUnprocessedUpdateTime(updateExpirationTime);
  8652. }
  8653. } else {
  8654. // This update does have sufficient priority.
  8655. if (newBaseQueueLast !== null) {
  8656. var _clone = {
  8657. expirationTime: Sync,
  8658. // This update is going to be committed so we never want uncommit it.
  8659. suspenseConfig: update.suspenseConfig,
  8660. action: update.action,
  8661. eagerReducer: update.eagerReducer,
  8662. eagerState: update.eagerState,
  8663. next: null
  8664. };
  8665. newBaseQueueLast = newBaseQueueLast.next = _clone;
  8666. } // Mark the event time of this update as relevant to this render pass.
  8667. // TODO: This should ideally use the true event time of this update rather than
  8668. // its priority which is a derived and not reverseable value.
  8669. // TODO: We should skip this update if it was already committed but currently
  8670. // we have no way of detecting the difference between a committed and suspended
  8671. // update here.
  8672. markRenderEventTimeAndConfig(
  8673. updateExpirationTime,
  8674. update.suspenseConfig
  8675. ); // Process this update.
  8676. if (update.eagerReducer === reducer) {
  8677. // If this update was processed eagerly, and its reducer matches the
  8678. // current reducer, we can use the eagerly computed state.
  8679. newState = update.eagerState;
  8680. } else {
  8681. var action = update.action;
  8682. newState = reducer(newState, action);
  8683. }
  8684. }
  8685. update = update.next;
  8686. } while (update !== null && update !== first);
  8687. if (newBaseQueueLast === null) {
  8688. newBaseState = newState;
  8689. } else {
  8690. newBaseQueueLast.next = newBaseQueueFirst;
  8691. } // Mark that the fiber performed work, but only if the new state is
  8692. // different from the current state.
  8693. if (!objectIs(newState, hook.memoizedState)) {
  8694. markWorkInProgressReceivedUpdate();
  8695. }
  8696. hook.memoizedState = newState;
  8697. hook.baseState = newBaseState;
  8698. hook.baseQueue = newBaseQueueLast;
  8699. queue.lastRenderedState = newState;
  8700. }
  8701. var dispatch = queue.dispatch;
  8702. return [hook.memoizedState, dispatch];
  8703. }
  8704. function rerenderReducer(reducer, initialArg, init) {
  8705. var hook = updateWorkInProgressHook();
  8706. var queue = hook.queue;
  8707. if (!(queue !== null)) {
  8708. throw Error(
  8709. "Should have a queue. This is likely a bug in React. Please file an issue."
  8710. );
  8711. }
  8712. queue.lastRenderedReducer = reducer; // This is a re-render. Apply the new render phase updates to the previous
  8713. // work-in-progress hook.
  8714. var dispatch = queue.dispatch;
  8715. var lastRenderPhaseUpdate = queue.pending;
  8716. var newState = hook.memoizedState;
  8717. if (lastRenderPhaseUpdate !== null) {
  8718. // The queue doesn't persist past this render pass.
  8719. queue.pending = null;
  8720. var firstRenderPhaseUpdate = lastRenderPhaseUpdate.next;
  8721. var update = firstRenderPhaseUpdate;
  8722. do {
  8723. // Process this render phase update. We don't have to check the
  8724. // priority because it will always be the same as the current
  8725. // render's.
  8726. var action = update.action;
  8727. newState = reducer(newState, action);
  8728. update = update.next;
  8729. } while (update !== firstRenderPhaseUpdate); // Mark that the fiber performed work, but only if the new state is
  8730. // different from the current state.
  8731. if (!objectIs(newState, hook.memoizedState)) {
  8732. markWorkInProgressReceivedUpdate();
  8733. }
  8734. hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
  8735. // the base state unless the queue is empty.
  8736. // TODO: Not sure if this is the desired semantics, but it's what we
  8737. // do for gDSFP. I can't remember why.
  8738. if (hook.baseQueue === null) {
  8739. hook.baseState = newState;
  8740. }
  8741. queue.lastRenderedState = newState;
  8742. }
  8743. return [newState, dispatch];
  8744. }
  8745. function mountState(initialState) {
  8746. var hook = mountWorkInProgressHook();
  8747. if (typeof initialState === "function") {
  8748. // $FlowFixMe: Flow doesn't like mixed types
  8749. initialState = initialState();
  8750. }
  8751. hook.memoizedState = hook.baseState = initialState;
  8752. var queue = (hook.queue = {
  8753. pending: null,
  8754. dispatch: null,
  8755. lastRenderedReducer: basicStateReducer,
  8756. lastRenderedState: initialState
  8757. });
  8758. var dispatch = (queue.dispatch = dispatchAction.bind(
  8759. null,
  8760. currentlyRenderingFiber$1,
  8761. queue
  8762. ));
  8763. return [hook.memoizedState, dispatch];
  8764. }
  8765. function updateState(initialState) {
  8766. return updateReducer(basicStateReducer);
  8767. }
  8768. function rerenderState(initialState) {
  8769. return rerenderReducer(basicStateReducer);
  8770. }
  8771. function pushEffect(tag, create, destroy, deps) {
  8772. var effect = {
  8773. tag: tag,
  8774. create: create,
  8775. destroy: destroy,
  8776. deps: deps,
  8777. // Circular
  8778. next: null
  8779. };
  8780. var componentUpdateQueue = currentlyRenderingFiber$1.updateQueue;
  8781. if (componentUpdateQueue === null) {
  8782. componentUpdateQueue = createFunctionComponentUpdateQueue();
  8783. currentlyRenderingFiber$1.updateQueue = componentUpdateQueue;
  8784. componentUpdateQueue.lastEffect = effect.next = effect;
  8785. } else {
  8786. var lastEffect = componentUpdateQueue.lastEffect;
  8787. if (lastEffect === null) {
  8788. componentUpdateQueue.lastEffect = effect.next = effect;
  8789. } else {
  8790. var firstEffect = lastEffect.next;
  8791. lastEffect.next = effect;
  8792. effect.next = firstEffect;
  8793. componentUpdateQueue.lastEffect = effect;
  8794. }
  8795. }
  8796. return effect;
  8797. }
  8798. function mountRef(initialValue) {
  8799. var hook = mountWorkInProgressHook();
  8800. var ref = {
  8801. current: initialValue
  8802. };
  8803. {
  8804. Object.seal(ref);
  8805. }
  8806. hook.memoizedState = ref;
  8807. return ref;
  8808. }
  8809. function updateRef(initialValue) {
  8810. var hook = updateWorkInProgressHook();
  8811. return hook.memoizedState;
  8812. }
  8813. function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  8814. var hook = mountWorkInProgressHook();
  8815. var nextDeps = deps === undefined ? null : deps;
  8816. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  8817. hook.memoizedState = pushEffect(
  8818. HasEffect | hookEffectTag,
  8819. create,
  8820. undefined,
  8821. nextDeps
  8822. );
  8823. }
  8824. function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  8825. var hook = updateWorkInProgressHook();
  8826. var nextDeps = deps === undefined ? null : deps;
  8827. var destroy = undefined;
  8828. if (currentHook !== null) {
  8829. var prevEffect = currentHook.memoizedState;
  8830. destroy = prevEffect.destroy;
  8831. if (nextDeps !== null) {
  8832. var prevDeps = prevEffect.deps;
  8833. if (areHookInputsEqual(nextDeps, prevDeps)) {
  8834. pushEffect(hookEffectTag, create, destroy, nextDeps);
  8835. return;
  8836. }
  8837. }
  8838. }
  8839. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  8840. hook.memoizedState = pushEffect(
  8841. HasEffect | hookEffectTag,
  8842. create,
  8843. destroy,
  8844. nextDeps
  8845. );
  8846. }
  8847. function mountEffect(create, deps) {
  8848. return mountEffectImpl(Update | Passive, Passive$1, create, deps);
  8849. }
  8850. function updateEffect(create, deps) {
  8851. return updateEffectImpl(Update | Passive, Passive$1, create, deps);
  8852. }
  8853. function mountLayoutEffect(create, deps) {
  8854. return mountEffectImpl(Update, Layout, create, deps);
  8855. }
  8856. function updateLayoutEffect(create, deps) {
  8857. return updateEffectImpl(Update, Layout, create, deps);
  8858. }
  8859. function imperativeHandleEffect(create, ref) {
  8860. if (typeof ref === "function") {
  8861. var refCallback = ref;
  8862. var _inst = create();
  8863. refCallback(_inst);
  8864. return function() {
  8865. refCallback(null);
  8866. };
  8867. } else if (ref !== null && ref !== undefined) {
  8868. var refObject = ref;
  8869. {
  8870. if (!refObject.hasOwnProperty("current")) {
  8871. error(
  8872. "Expected useImperativeHandle() first argument to either be a " +
  8873. "ref callback or React.createRef() object. Instead received: %s.",
  8874. "an object with keys {" + Object.keys(refObject).join(", ") + "}"
  8875. );
  8876. }
  8877. }
  8878. var _inst2 = create();
  8879. refObject.current = _inst2;
  8880. return function() {
  8881. refObject.current = null;
  8882. };
  8883. }
  8884. }
  8885. function mountImperativeHandle(ref, create, deps) {
  8886. {
  8887. if (typeof create !== "function") {
  8888. error(
  8889. "Expected useImperativeHandle() second argument to be a function " +
  8890. "that creates a handle. Instead received: %s.",
  8891. create !== null ? typeof create : "null"
  8892. );
  8893. }
  8894. } // TODO: If deps are provided, should we skip comparing the ref itself?
  8895. var effectDeps =
  8896. deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  8897. return mountEffectImpl(
  8898. Update,
  8899. Layout,
  8900. imperativeHandleEffect.bind(null, create, ref),
  8901. effectDeps
  8902. );
  8903. }
  8904. function updateImperativeHandle(ref, create, deps) {
  8905. {
  8906. if (typeof create !== "function") {
  8907. error(
  8908. "Expected useImperativeHandle() second argument to be a function " +
  8909. "that creates a handle. Instead received: %s.",
  8910. create !== null ? typeof create : "null"
  8911. );
  8912. }
  8913. } // TODO: If deps are provided, should we skip comparing the ref itself?
  8914. var effectDeps =
  8915. deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  8916. return updateEffectImpl(
  8917. Update,
  8918. Layout,
  8919. imperativeHandleEffect.bind(null, create, ref),
  8920. effectDeps
  8921. );
  8922. }
  8923. function mountDebugValue(value, formatterFn) {
  8924. // This hook is normally a no-op.
  8925. // The react-debug-hooks package injects its own implementation
  8926. // so that e.g. DevTools can display custom hook values.
  8927. }
  8928. var updateDebugValue = mountDebugValue;
  8929. function mountCallback(callback, deps) {
  8930. var hook = mountWorkInProgressHook();
  8931. var nextDeps = deps === undefined ? null : deps;
  8932. hook.memoizedState = [callback, nextDeps];
  8933. return callback;
  8934. }
  8935. function updateCallback(callback, deps) {
  8936. var hook = updateWorkInProgressHook();
  8937. var nextDeps = deps === undefined ? null : deps;
  8938. var prevState = hook.memoizedState;
  8939. if (prevState !== null) {
  8940. if (nextDeps !== null) {
  8941. var prevDeps = prevState[1];
  8942. if (areHookInputsEqual(nextDeps, prevDeps)) {
  8943. return prevState[0];
  8944. }
  8945. }
  8946. }
  8947. hook.memoizedState = [callback, nextDeps];
  8948. return callback;
  8949. }
  8950. function mountMemo(nextCreate, deps) {
  8951. var hook = mountWorkInProgressHook();
  8952. var nextDeps = deps === undefined ? null : deps;
  8953. var nextValue = nextCreate();
  8954. hook.memoizedState = [nextValue, nextDeps];
  8955. return nextValue;
  8956. }
  8957. function updateMemo(nextCreate, deps) {
  8958. var hook = updateWorkInProgressHook();
  8959. var nextDeps = deps === undefined ? null : deps;
  8960. var prevState = hook.memoizedState;
  8961. if (prevState !== null) {
  8962. // Assume these are defined. If they're not, areHookInputsEqual will warn.
  8963. if (nextDeps !== null) {
  8964. var prevDeps = prevState[1];
  8965. if (areHookInputsEqual(nextDeps, prevDeps)) {
  8966. return prevState[0];
  8967. }
  8968. }
  8969. }
  8970. var nextValue = nextCreate();
  8971. hook.memoizedState = [nextValue, nextDeps];
  8972. return nextValue;
  8973. }
  8974. function mountDeferredValue(value, config) {
  8975. var _mountState = mountState(value),
  8976. prevValue = _mountState[0],
  8977. setValue = _mountState[1];
  8978. mountEffect(
  8979. function() {
  8980. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  8981. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  8982. try {
  8983. setValue(value);
  8984. } finally {
  8985. ReactCurrentBatchConfig$1.suspense = previousConfig;
  8986. }
  8987. },
  8988. [value, config]
  8989. );
  8990. return prevValue;
  8991. }
  8992. function updateDeferredValue(value, config) {
  8993. var _updateState = updateState(),
  8994. prevValue = _updateState[0],
  8995. setValue = _updateState[1];
  8996. updateEffect(
  8997. function() {
  8998. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  8999. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  9000. try {
  9001. setValue(value);
  9002. } finally {
  9003. ReactCurrentBatchConfig$1.suspense = previousConfig;
  9004. }
  9005. },
  9006. [value, config]
  9007. );
  9008. return prevValue;
  9009. }
  9010. function rerenderDeferredValue(value, config) {
  9011. var _rerenderState = rerenderState(),
  9012. prevValue = _rerenderState[0],
  9013. setValue = _rerenderState[1];
  9014. updateEffect(
  9015. function() {
  9016. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  9017. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  9018. try {
  9019. setValue(value);
  9020. } finally {
  9021. ReactCurrentBatchConfig$1.suspense = previousConfig;
  9022. }
  9023. },
  9024. [value, config]
  9025. );
  9026. return prevValue;
  9027. }
  9028. function startTransition(setPending, config, callback) {
  9029. var priorityLevel = getCurrentPriorityLevel();
  9030. runWithPriority(
  9031. priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
  9032. function() {
  9033. setPending(true);
  9034. }
  9035. );
  9036. runWithPriority(
  9037. priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
  9038. function() {
  9039. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  9040. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  9041. try {
  9042. setPending(false);
  9043. callback();
  9044. } finally {
  9045. ReactCurrentBatchConfig$1.suspense = previousConfig;
  9046. }
  9047. }
  9048. );
  9049. }
  9050. function mountTransition(config) {
  9051. var _mountState2 = mountState(false),
  9052. isPending = _mountState2[0],
  9053. setPending = _mountState2[1];
  9054. var start = mountCallback(startTransition.bind(null, setPending, config), [
  9055. setPending,
  9056. config
  9057. ]);
  9058. return [start, isPending];
  9059. }
  9060. function updateTransition(config) {
  9061. var _updateState2 = updateState(),
  9062. isPending = _updateState2[0],
  9063. setPending = _updateState2[1];
  9064. var start = updateCallback(startTransition.bind(null, setPending, config), [
  9065. setPending,
  9066. config
  9067. ]);
  9068. return [start, isPending];
  9069. }
  9070. function rerenderTransition(config) {
  9071. var _rerenderState2 = rerenderState(),
  9072. isPending = _rerenderState2[0],
  9073. setPending = _rerenderState2[1];
  9074. var start = updateCallback(startTransition.bind(null, setPending, config), [
  9075. setPending,
  9076. config
  9077. ]);
  9078. return [start, isPending];
  9079. }
  9080. function dispatchAction(fiber, queue, action) {
  9081. {
  9082. if (typeof arguments[3] === "function") {
  9083. error(
  9084. "State updates from the useState() and useReducer() Hooks don't support the " +
  9085. "second callback argument. To execute a side effect after " +
  9086. "rendering, declare it in the component body with useEffect()."
  9087. );
  9088. }
  9089. }
  9090. var currentTime = requestCurrentTimeForUpdate();
  9091. var suspenseConfig = requestCurrentSuspenseConfig();
  9092. var expirationTime = computeExpirationForFiber(
  9093. currentTime,
  9094. fiber,
  9095. suspenseConfig
  9096. );
  9097. var update = {
  9098. expirationTime: expirationTime,
  9099. suspenseConfig: suspenseConfig,
  9100. action: action,
  9101. eagerReducer: null,
  9102. eagerState: null,
  9103. next: null
  9104. };
  9105. {
  9106. update.priority = getCurrentPriorityLevel();
  9107. } // Append the update to the end of the list.
  9108. var pending = queue.pending;
  9109. if (pending === null) {
  9110. // This is the first update. Create a circular list.
  9111. update.next = update;
  9112. } else {
  9113. update.next = pending.next;
  9114. pending.next = update;
  9115. }
  9116. queue.pending = update;
  9117. var alternate = fiber.alternate;
  9118. if (
  9119. fiber === currentlyRenderingFiber$1 ||
  9120. (alternate !== null && alternate === currentlyRenderingFiber$1)
  9121. ) {
  9122. // This is a render phase update. Stash it in a lazily-created map of
  9123. // queue -> linked list of updates. After this render pass, we'll restart
  9124. // and apply the stashed updates on top of the work-in-progress hook.
  9125. didScheduleRenderPhaseUpdate = true;
  9126. update.expirationTime = renderExpirationTime;
  9127. currentlyRenderingFiber$1.expirationTime = renderExpirationTime;
  9128. } else {
  9129. if (
  9130. fiber.expirationTime === NoWork &&
  9131. (alternate === null || alternate.expirationTime === NoWork)
  9132. ) {
  9133. // The queue is currently empty, which means we can eagerly compute the
  9134. // next state before entering the render phase. If the new state is the
  9135. // same as the current state, we may be able to bail out entirely.
  9136. var lastRenderedReducer = queue.lastRenderedReducer;
  9137. if (lastRenderedReducer !== null) {
  9138. var prevDispatcher;
  9139. {
  9140. prevDispatcher = ReactCurrentDispatcher.current;
  9141. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9142. }
  9143. try {
  9144. var currentState = queue.lastRenderedState;
  9145. var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
  9146. // it, on the update object. If the reducer hasn't changed by the
  9147. // time we enter the render phase, then the eager state can be used
  9148. // without calling the reducer again.
  9149. update.eagerReducer = lastRenderedReducer;
  9150. update.eagerState = eagerState;
  9151. if (objectIs(eagerState, currentState)) {
  9152. // Fast path. We can bail out without scheduling React to re-render.
  9153. // It's still possible that we'll need to rebase this update later,
  9154. // if the component re-renders for a different reason and by that
  9155. // time the reducer has changed.
  9156. return;
  9157. }
  9158. } catch (error) {
  9159. // Suppress the error. It will throw again in the render phase.
  9160. } finally {
  9161. {
  9162. ReactCurrentDispatcher.current = prevDispatcher;
  9163. }
  9164. }
  9165. }
  9166. }
  9167. scheduleWork(fiber, expirationTime);
  9168. }
  9169. }
  9170. function mountEventListener(event) {
  9171. return undefined;
  9172. }
  9173. function updateEventListener(event) {
  9174. return undefined;
  9175. }
  9176. var ContextOnlyDispatcher = {
  9177. readContext: readContext,
  9178. useCallback: throwInvalidHookError,
  9179. useContext: throwInvalidHookError,
  9180. useEffect: throwInvalidHookError,
  9181. useImperativeHandle: throwInvalidHookError,
  9182. useLayoutEffect: throwInvalidHookError,
  9183. useMemo: throwInvalidHookError,
  9184. useReducer: throwInvalidHookError,
  9185. useRef: throwInvalidHookError,
  9186. useState: throwInvalidHookError,
  9187. useDebugValue: throwInvalidHookError,
  9188. useResponder: throwInvalidHookError,
  9189. useDeferredValue: throwInvalidHookError,
  9190. useTransition: throwInvalidHookError,
  9191. useEvent: throwInvalidHookError
  9192. };
  9193. var HooksDispatcherOnMountInDEV = null;
  9194. var HooksDispatcherOnMountWithHookTypesInDEV = null;
  9195. var HooksDispatcherOnUpdateInDEV = null;
  9196. var HooksDispatcherOnRerenderInDEV = null;
  9197. var InvalidNestedHooksDispatcherOnMountInDEV = null;
  9198. var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
  9199. var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
  9200. {
  9201. var warnInvalidContextAccess = function() {
  9202. error(
  9203. "Context can only be read while React is rendering. " +
  9204. "In classes, you can read it in the render method or getDerivedStateFromProps. " +
  9205. "In function components, you can read it directly in the function body, but not " +
  9206. "inside Hooks like useReducer() or useMemo()."
  9207. );
  9208. };
  9209. var warnInvalidHookAccess = function() {
  9210. error(
  9211. "Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. " +
  9212. "You can only call Hooks at the top level of your React function. " +
  9213. "For more information, see " +
  9214. "https://fb.me/rules-of-hooks"
  9215. );
  9216. };
  9217. HooksDispatcherOnMountInDEV = {
  9218. readContext: function(context, observedBits) {
  9219. return readContext(context, observedBits);
  9220. },
  9221. useCallback: function(callback, deps) {
  9222. currentHookNameInDev = "useCallback";
  9223. mountHookTypesDev();
  9224. checkDepsAreArrayDev(deps);
  9225. return mountCallback(callback, deps);
  9226. },
  9227. useContext: function(context, observedBits) {
  9228. currentHookNameInDev = "useContext";
  9229. mountHookTypesDev();
  9230. return readContext(context, observedBits);
  9231. },
  9232. useEffect: function(create, deps) {
  9233. currentHookNameInDev = "useEffect";
  9234. mountHookTypesDev();
  9235. checkDepsAreArrayDev(deps);
  9236. return mountEffect(create, deps);
  9237. },
  9238. useImperativeHandle: function(ref, create, deps) {
  9239. currentHookNameInDev = "useImperativeHandle";
  9240. mountHookTypesDev();
  9241. checkDepsAreArrayDev(deps);
  9242. return mountImperativeHandle(ref, create, deps);
  9243. },
  9244. useLayoutEffect: function(create, deps) {
  9245. currentHookNameInDev = "useLayoutEffect";
  9246. mountHookTypesDev();
  9247. checkDepsAreArrayDev(deps);
  9248. return mountLayoutEffect(create, deps);
  9249. },
  9250. useMemo: function(create, deps) {
  9251. currentHookNameInDev = "useMemo";
  9252. mountHookTypesDev();
  9253. checkDepsAreArrayDev(deps);
  9254. var prevDispatcher = ReactCurrentDispatcher.current;
  9255. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9256. try {
  9257. return mountMemo(create, deps);
  9258. } finally {
  9259. ReactCurrentDispatcher.current = prevDispatcher;
  9260. }
  9261. },
  9262. useReducer: function(reducer, initialArg, init) {
  9263. currentHookNameInDev = "useReducer";
  9264. mountHookTypesDev();
  9265. var prevDispatcher = ReactCurrentDispatcher.current;
  9266. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9267. try {
  9268. return mountReducer(reducer, initialArg, init);
  9269. } finally {
  9270. ReactCurrentDispatcher.current = prevDispatcher;
  9271. }
  9272. },
  9273. useRef: function(initialValue) {
  9274. currentHookNameInDev = "useRef";
  9275. mountHookTypesDev();
  9276. return mountRef(initialValue);
  9277. },
  9278. useState: function(initialState) {
  9279. currentHookNameInDev = "useState";
  9280. mountHookTypesDev();
  9281. var prevDispatcher = ReactCurrentDispatcher.current;
  9282. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9283. try {
  9284. return mountState(initialState);
  9285. } finally {
  9286. ReactCurrentDispatcher.current = prevDispatcher;
  9287. }
  9288. },
  9289. useDebugValue: function(value, formatterFn) {
  9290. currentHookNameInDev = "useDebugValue";
  9291. mountHookTypesDev();
  9292. return mountDebugValue();
  9293. },
  9294. useResponder: function(responder, props) {
  9295. currentHookNameInDev = "useResponder";
  9296. mountHookTypesDev();
  9297. return createDeprecatedResponderListener(responder, props);
  9298. },
  9299. useDeferredValue: function(value, config) {
  9300. currentHookNameInDev = "useDeferredValue";
  9301. mountHookTypesDev();
  9302. return mountDeferredValue(value, config);
  9303. },
  9304. useTransition: function(config) {
  9305. currentHookNameInDev = "useTransition";
  9306. mountHookTypesDev();
  9307. return mountTransition(config);
  9308. },
  9309. useEvent: function(event) {
  9310. currentHookNameInDev = "useEvent";
  9311. mountHookTypesDev();
  9312. return mountEventListener();
  9313. }
  9314. };
  9315. HooksDispatcherOnMountWithHookTypesInDEV = {
  9316. readContext: function(context, observedBits) {
  9317. return readContext(context, observedBits);
  9318. },
  9319. useCallback: function(callback, deps) {
  9320. currentHookNameInDev = "useCallback";
  9321. updateHookTypesDev();
  9322. return mountCallback(callback, deps);
  9323. },
  9324. useContext: function(context, observedBits) {
  9325. currentHookNameInDev = "useContext";
  9326. updateHookTypesDev();
  9327. return readContext(context, observedBits);
  9328. },
  9329. useEffect: function(create, deps) {
  9330. currentHookNameInDev = "useEffect";
  9331. updateHookTypesDev();
  9332. return mountEffect(create, deps);
  9333. },
  9334. useImperativeHandle: function(ref, create, deps) {
  9335. currentHookNameInDev = "useImperativeHandle";
  9336. updateHookTypesDev();
  9337. return mountImperativeHandle(ref, create, deps);
  9338. },
  9339. useLayoutEffect: function(create, deps) {
  9340. currentHookNameInDev = "useLayoutEffect";
  9341. updateHookTypesDev();
  9342. return mountLayoutEffect(create, deps);
  9343. },
  9344. useMemo: function(create, deps) {
  9345. currentHookNameInDev = "useMemo";
  9346. updateHookTypesDev();
  9347. var prevDispatcher = ReactCurrentDispatcher.current;
  9348. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9349. try {
  9350. return mountMemo(create, deps);
  9351. } finally {
  9352. ReactCurrentDispatcher.current = prevDispatcher;
  9353. }
  9354. },
  9355. useReducer: function(reducer, initialArg, init) {
  9356. currentHookNameInDev = "useReducer";
  9357. updateHookTypesDev();
  9358. var prevDispatcher = ReactCurrentDispatcher.current;
  9359. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9360. try {
  9361. return mountReducer(reducer, initialArg, init);
  9362. } finally {
  9363. ReactCurrentDispatcher.current = prevDispatcher;
  9364. }
  9365. },
  9366. useRef: function(initialValue) {
  9367. currentHookNameInDev = "useRef";
  9368. updateHookTypesDev();
  9369. return mountRef(initialValue);
  9370. },
  9371. useState: function(initialState) {
  9372. currentHookNameInDev = "useState";
  9373. updateHookTypesDev();
  9374. var prevDispatcher = ReactCurrentDispatcher.current;
  9375. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9376. try {
  9377. return mountState(initialState);
  9378. } finally {
  9379. ReactCurrentDispatcher.current = prevDispatcher;
  9380. }
  9381. },
  9382. useDebugValue: function(value, formatterFn) {
  9383. currentHookNameInDev = "useDebugValue";
  9384. updateHookTypesDev();
  9385. return mountDebugValue();
  9386. },
  9387. useResponder: function(responder, props) {
  9388. currentHookNameInDev = "useResponder";
  9389. updateHookTypesDev();
  9390. return createDeprecatedResponderListener(responder, props);
  9391. },
  9392. useDeferredValue: function(value, config) {
  9393. currentHookNameInDev = "useDeferredValue";
  9394. updateHookTypesDev();
  9395. return mountDeferredValue(value, config);
  9396. },
  9397. useTransition: function(config) {
  9398. currentHookNameInDev = "useTransition";
  9399. updateHookTypesDev();
  9400. return mountTransition(config);
  9401. },
  9402. useEvent: function(event) {
  9403. currentHookNameInDev = "useEvent";
  9404. updateHookTypesDev();
  9405. return mountEventListener();
  9406. }
  9407. };
  9408. HooksDispatcherOnUpdateInDEV = {
  9409. readContext: function(context, observedBits) {
  9410. return readContext(context, observedBits);
  9411. },
  9412. useCallback: function(callback, deps) {
  9413. currentHookNameInDev = "useCallback";
  9414. updateHookTypesDev();
  9415. return updateCallback(callback, deps);
  9416. },
  9417. useContext: function(context, observedBits) {
  9418. currentHookNameInDev = "useContext";
  9419. updateHookTypesDev();
  9420. return readContext(context, observedBits);
  9421. },
  9422. useEffect: function(create, deps) {
  9423. currentHookNameInDev = "useEffect";
  9424. updateHookTypesDev();
  9425. return updateEffect(create, deps);
  9426. },
  9427. useImperativeHandle: function(ref, create, deps) {
  9428. currentHookNameInDev = "useImperativeHandle";
  9429. updateHookTypesDev();
  9430. return updateImperativeHandle(ref, create, deps);
  9431. },
  9432. useLayoutEffect: function(create, deps) {
  9433. currentHookNameInDev = "useLayoutEffect";
  9434. updateHookTypesDev();
  9435. return updateLayoutEffect(create, deps);
  9436. },
  9437. useMemo: function(create, deps) {
  9438. currentHookNameInDev = "useMemo";
  9439. updateHookTypesDev();
  9440. var prevDispatcher = ReactCurrentDispatcher.current;
  9441. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9442. try {
  9443. return updateMemo(create, deps);
  9444. } finally {
  9445. ReactCurrentDispatcher.current = prevDispatcher;
  9446. }
  9447. },
  9448. useReducer: function(reducer, initialArg, init) {
  9449. currentHookNameInDev = "useReducer";
  9450. updateHookTypesDev();
  9451. var prevDispatcher = ReactCurrentDispatcher.current;
  9452. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9453. try {
  9454. return updateReducer(reducer, initialArg, init);
  9455. } finally {
  9456. ReactCurrentDispatcher.current = prevDispatcher;
  9457. }
  9458. },
  9459. useRef: function(initialValue) {
  9460. currentHookNameInDev = "useRef";
  9461. updateHookTypesDev();
  9462. return updateRef();
  9463. },
  9464. useState: function(initialState) {
  9465. currentHookNameInDev = "useState";
  9466. updateHookTypesDev();
  9467. var prevDispatcher = ReactCurrentDispatcher.current;
  9468. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9469. try {
  9470. return updateState(initialState);
  9471. } finally {
  9472. ReactCurrentDispatcher.current = prevDispatcher;
  9473. }
  9474. },
  9475. useDebugValue: function(value, formatterFn) {
  9476. currentHookNameInDev = "useDebugValue";
  9477. updateHookTypesDev();
  9478. return updateDebugValue();
  9479. },
  9480. useResponder: function(responder, props) {
  9481. currentHookNameInDev = "useResponder";
  9482. updateHookTypesDev();
  9483. return createDeprecatedResponderListener(responder, props);
  9484. },
  9485. useDeferredValue: function(value, config) {
  9486. currentHookNameInDev = "useDeferredValue";
  9487. updateHookTypesDev();
  9488. return updateDeferredValue(value, config);
  9489. },
  9490. useTransition: function(config) {
  9491. currentHookNameInDev = "useTransition";
  9492. updateHookTypesDev();
  9493. return updateTransition(config);
  9494. },
  9495. useEvent: function(event) {
  9496. currentHookNameInDev = "useEvent";
  9497. updateHookTypesDev();
  9498. return updateEventListener();
  9499. }
  9500. };
  9501. HooksDispatcherOnRerenderInDEV = {
  9502. readContext: function(context, observedBits) {
  9503. return readContext(context, observedBits);
  9504. },
  9505. useCallback: function(callback, deps) {
  9506. currentHookNameInDev = "useCallback";
  9507. updateHookTypesDev();
  9508. return updateCallback(callback, deps);
  9509. },
  9510. useContext: function(context, observedBits) {
  9511. currentHookNameInDev = "useContext";
  9512. updateHookTypesDev();
  9513. return readContext(context, observedBits);
  9514. },
  9515. useEffect: function(create, deps) {
  9516. currentHookNameInDev = "useEffect";
  9517. updateHookTypesDev();
  9518. return updateEffect(create, deps);
  9519. },
  9520. useImperativeHandle: function(ref, create, deps) {
  9521. currentHookNameInDev = "useImperativeHandle";
  9522. updateHookTypesDev();
  9523. return updateImperativeHandle(ref, create, deps);
  9524. },
  9525. useLayoutEffect: function(create, deps) {
  9526. currentHookNameInDev = "useLayoutEffect";
  9527. updateHookTypesDev();
  9528. return updateLayoutEffect(create, deps);
  9529. },
  9530. useMemo: function(create, deps) {
  9531. currentHookNameInDev = "useMemo";
  9532. updateHookTypesDev();
  9533. var prevDispatcher = ReactCurrentDispatcher.current;
  9534. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  9535. try {
  9536. return updateMemo(create, deps);
  9537. } finally {
  9538. ReactCurrentDispatcher.current = prevDispatcher;
  9539. }
  9540. },
  9541. useReducer: function(reducer, initialArg, init) {
  9542. currentHookNameInDev = "useReducer";
  9543. updateHookTypesDev();
  9544. var prevDispatcher = ReactCurrentDispatcher.current;
  9545. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  9546. try {
  9547. return rerenderReducer(reducer, initialArg, init);
  9548. } finally {
  9549. ReactCurrentDispatcher.current = prevDispatcher;
  9550. }
  9551. },
  9552. useRef: function(initialValue) {
  9553. currentHookNameInDev = "useRef";
  9554. updateHookTypesDev();
  9555. return updateRef();
  9556. },
  9557. useState: function(initialState) {
  9558. currentHookNameInDev = "useState";
  9559. updateHookTypesDev();
  9560. var prevDispatcher = ReactCurrentDispatcher.current;
  9561. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  9562. try {
  9563. return rerenderState(initialState);
  9564. } finally {
  9565. ReactCurrentDispatcher.current = prevDispatcher;
  9566. }
  9567. },
  9568. useDebugValue: function(value, formatterFn) {
  9569. currentHookNameInDev = "useDebugValue";
  9570. updateHookTypesDev();
  9571. return updateDebugValue();
  9572. },
  9573. useResponder: function(responder, props) {
  9574. currentHookNameInDev = "useResponder";
  9575. updateHookTypesDev();
  9576. return createDeprecatedResponderListener(responder, props);
  9577. },
  9578. useDeferredValue: function(value, config) {
  9579. currentHookNameInDev = "useDeferredValue";
  9580. updateHookTypesDev();
  9581. return rerenderDeferredValue(value, config);
  9582. },
  9583. useTransition: function(config) {
  9584. currentHookNameInDev = "useTransition";
  9585. updateHookTypesDev();
  9586. return rerenderTransition(config);
  9587. },
  9588. useEvent: function(event) {
  9589. currentHookNameInDev = "useEvent";
  9590. updateHookTypesDev();
  9591. return updateEventListener();
  9592. }
  9593. };
  9594. InvalidNestedHooksDispatcherOnMountInDEV = {
  9595. readContext: function(context, observedBits) {
  9596. warnInvalidContextAccess();
  9597. return readContext(context, observedBits);
  9598. },
  9599. useCallback: function(callback, deps) {
  9600. currentHookNameInDev = "useCallback";
  9601. warnInvalidHookAccess();
  9602. mountHookTypesDev();
  9603. return mountCallback(callback, deps);
  9604. },
  9605. useContext: function(context, observedBits) {
  9606. currentHookNameInDev = "useContext";
  9607. warnInvalidHookAccess();
  9608. mountHookTypesDev();
  9609. return readContext(context, observedBits);
  9610. },
  9611. useEffect: function(create, deps) {
  9612. currentHookNameInDev = "useEffect";
  9613. warnInvalidHookAccess();
  9614. mountHookTypesDev();
  9615. return mountEffect(create, deps);
  9616. },
  9617. useImperativeHandle: function(ref, create, deps) {
  9618. currentHookNameInDev = "useImperativeHandle";
  9619. warnInvalidHookAccess();
  9620. mountHookTypesDev();
  9621. return mountImperativeHandle(ref, create, deps);
  9622. },
  9623. useLayoutEffect: function(create, deps) {
  9624. currentHookNameInDev = "useLayoutEffect";
  9625. warnInvalidHookAccess();
  9626. mountHookTypesDev();
  9627. return mountLayoutEffect(create, deps);
  9628. },
  9629. useMemo: function(create, deps) {
  9630. currentHookNameInDev = "useMemo";
  9631. warnInvalidHookAccess();
  9632. mountHookTypesDev();
  9633. var prevDispatcher = ReactCurrentDispatcher.current;
  9634. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9635. try {
  9636. return mountMemo(create, deps);
  9637. } finally {
  9638. ReactCurrentDispatcher.current = prevDispatcher;
  9639. }
  9640. },
  9641. useReducer: function(reducer, initialArg, init) {
  9642. currentHookNameInDev = "useReducer";
  9643. warnInvalidHookAccess();
  9644. mountHookTypesDev();
  9645. var prevDispatcher = ReactCurrentDispatcher.current;
  9646. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9647. try {
  9648. return mountReducer(reducer, initialArg, init);
  9649. } finally {
  9650. ReactCurrentDispatcher.current = prevDispatcher;
  9651. }
  9652. },
  9653. useRef: function(initialValue) {
  9654. currentHookNameInDev = "useRef";
  9655. warnInvalidHookAccess();
  9656. mountHookTypesDev();
  9657. return mountRef(initialValue);
  9658. },
  9659. useState: function(initialState) {
  9660. currentHookNameInDev = "useState";
  9661. warnInvalidHookAccess();
  9662. mountHookTypesDev();
  9663. var prevDispatcher = ReactCurrentDispatcher.current;
  9664. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9665. try {
  9666. return mountState(initialState);
  9667. } finally {
  9668. ReactCurrentDispatcher.current = prevDispatcher;
  9669. }
  9670. },
  9671. useDebugValue: function(value, formatterFn) {
  9672. currentHookNameInDev = "useDebugValue";
  9673. warnInvalidHookAccess();
  9674. mountHookTypesDev();
  9675. return mountDebugValue();
  9676. },
  9677. useResponder: function(responder, props) {
  9678. currentHookNameInDev = "useResponder";
  9679. warnInvalidHookAccess();
  9680. mountHookTypesDev();
  9681. return createDeprecatedResponderListener(responder, props);
  9682. },
  9683. useDeferredValue: function(value, config) {
  9684. currentHookNameInDev = "useDeferredValue";
  9685. warnInvalidHookAccess();
  9686. mountHookTypesDev();
  9687. return mountDeferredValue(value, config);
  9688. },
  9689. useTransition: function(config) {
  9690. currentHookNameInDev = "useTransition";
  9691. warnInvalidHookAccess();
  9692. mountHookTypesDev();
  9693. return mountTransition(config);
  9694. },
  9695. useEvent: function(event) {
  9696. currentHookNameInDev = "useEvent";
  9697. warnInvalidHookAccess();
  9698. mountHookTypesDev();
  9699. return mountEventListener();
  9700. }
  9701. };
  9702. InvalidNestedHooksDispatcherOnUpdateInDEV = {
  9703. readContext: function(context, observedBits) {
  9704. warnInvalidContextAccess();
  9705. return readContext(context, observedBits);
  9706. },
  9707. useCallback: function(callback, deps) {
  9708. currentHookNameInDev = "useCallback";
  9709. warnInvalidHookAccess();
  9710. updateHookTypesDev();
  9711. return updateCallback(callback, deps);
  9712. },
  9713. useContext: function(context, observedBits) {
  9714. currentHookNameInDev = "useContext";
  9715. warnInvalidHookAccess();
  9716. updateHookTypesDev();
  9717. return readContext(context, observedBits);
  9718. },
  9719. useEffect: function(create, deps) {
  9720. currentHookNameInDev = "useEffect";
  9721. warnInvalidHookAccess();
  9722. updateHookTypesDev();
  9723. return updateEffect(create, deps);
  9724. },
  9725. useImperativeHandle: function(ref, create, deps) {
  9726. currentHookNameInDev = "useImperativeHandle";
  9727. warnInvalidHookAccess();
  9728. updateHookTypesDev();
  9729. return updateImperativeHandle(ref, create, deps);
  9730. },
  9731. useLayoutEffect: function(create, deps) {
  9732. currentHookNameInDev = "useLayoutEffect";
  9733. warnInvalidHookAccess();
  9734. updateHookTypesDev();
  9735. return updateLayoutEffect(create, deps);
  9736. },
  9737. useMemo: function(create, deps) {
  9738. currentHookNameInDev = "useMemo";
  9739. warnInvalidHookAccess();
  9740. updateHookTypesDev();
  9741. var prevDispatcher = ReactCurrentDispatcher.current;
  9742. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9743. try {
  9744. return updateMemo(create, deps);
  9745. } finally {
  9746. ReactCurrentDispatcher.current = prevDispatcher;
  9747. }
  9748. },
  9749. useReducer: function(reducer, initialArg, init) {
  9750. currentHookNameInDev = "useReducer";
  9751. warnInvalidHookAccess();
  9752. updateHookTypesDev();
  9753. var prevDispatcher = ReactCurrentDispatcher.current;
  9754. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9755. try {
  9756. return updateReducer(reducer, initialArg, init);
  9757. } finally {
  9758. ReactCurrentDispatcher.current = prevDispatcher;
  9759. }
  9760. },
  9761. useRef: function(initialValue) {
  9762. currentHookNameInDev = "useRef";
  9763. warnInvalidHookAccess();
  9764. updateHookTypesDev();
  9765. return updateRef();
  9766. },
  9767. useState: function(initialState) {
  9768. currentHookNameInDev = "useState";
  9769. warnInvalidHookAccess();
  9770. updateHookTypesDev();
  9771. var prevDispatcher = ReactCurrentDispatcher.current;
  9772. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9773. try {
  9774. return updateState(initialState);
  9775. } finally {
  9776. ReactCurrentDispatcher.current = prevDispatcher;
  9777. }
  9778. },
  9779. useDebugValue: function(value, formatterFn) {
  9780. currentHookNameInDev = "useDebugValue";
  9781. warnInvalidHookAccess();
  9782. updateHookTypesDev();
  9783. return updateDebugValue();
  9784. },
  9785. useResponder: function(responder, props) {
  9786. currentHookNameInDev = "useResponder";
  9787. warnInvalidHookAccess();
  9788. updateHookTypesDev();
  9789. return createDeprecatedResponderListener(responder, props);
  9790. },
  9791. useDeferredValue: function(value, config) {
  9792. currentHookNameInDev = "useDeferredValue";
  9793. warnInvalidHookAccess();
  9794. updateHookTypesDev();
  9795. return updateDeferredValue(value, config);
  9796. },
  9797. useTransition: function(config) {
  9798. currentHookNameInDev = "useTransition";
  9799. warnInvalidHookAccess();
  9800. updateHookTypesDev();
  9801. return updateTransition(config);
  9802. },
  9803. useEvent: function(event) {
  9804. currentHookNameInDev = "useEvent";
  9805. warnInvalidHookAccess();
  9806. updateHookTypesDev();
  9807. return updateEventListener();
  9808. }
  9809. };
  9810. InvalidNestedHooksDispatcherOnRerenderInDEV = {
  9811. readContext: function(context, observedBits) {
  9812. warnInvalidContextAccess();
  9813. return readContext(context, observedBits);
  9814. },
  9815. useCallback: function(callback, deps) {
  9816. currentHookNameInDev = "useCallback";
  9817. warnInvalidHookAccess();
  9818. updateHookTypesDev();
  9819. return updateCallback(callback, deps);
  9820. },
  9821. useContext: function(context, observedBits) {
  9822. currentHookNameInDev = "useContext";
  9823. warnInvalidHookAccess();
  9824. updateHookTypesDev();
  9825. return readContext(context, observedBits);
  9826. },
  9827. useEffect: function(create, deps) {
  9828. currentHookNameInDev = "useEffect";
  9829. warnInvalidHookAccess();
  9830. updateHookTypesDev();
  9831. return updateEffect(create, deps);
  9832. },
  9833. useImperativeHandle: function(ref, create, deps) {
  9834. currentHookNameInDev = "useImperativeHandle";
  9835. warnInvalidHookAccess();
  9836. updateHookTypesDev();
  9837. return updateImperativeHandle(ref, create, deps);
  9838. },
  9839. useLayoutEffect: function(create, deps) {
  9840. currentHookNameInDev = "useLayoutEffect";
  9841. warnInvalidHookAccess();
  9842. updateHookTypesDev();
  9843. return updateLayoutEffect(create, deps);
  9844. },
  9845. useMemo: function(create, deps) {
  9846. currentHookNameInDev = "useMemo";
  9847. warnInvalidHookAccess();
  9848. updateHookTypesDev();
  9849. var prevDispatcher = ReactCurrentDispatcher.current;
  9850. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9851. try {
  9852. return updateMemo(create, deps);
  9853. } finally {
  9854. ReactCurrentDispatcher.current = prevDispatcher;
  9855. }
  9856. },
  9857. useReducer: function(reducer, initialArg, init) {
  9858. currentHookNameInDev = "useReducer";
  9859. warnInvalidHookAccess();
  9860. updateHookTypesDev();
  9861. var prevDispatcher = ReactCurrentDispatcher.current;
  9862. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9863. try {
  9864. return rerenderReducer(reducer, initialArg, init);
  9865. } finally {
  9866. ReactCurrentDispatcher.current = prevDispatcher;
  9867. }
  9868. },
  9869. useRef: function(initialValue) {
  9870. currentHookNameInDev = "useRef";
  9871. warnInvalidHookAccess();
  9872. updateHookTypesDev();
  9873. return updateRef();
  9874. },
  9875. useState: function(initialState) {
  9876. currentHookNameInDev = "useState";
  9877. warnInvalidHookAccess();
  9878. updateHookTypesDev();
  9879. var prevDispatcher = ReactCurrentDispatcher.current;
  9880. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9881. try {
  9882. return rerenderState(initialState);
  9883. } finally {
  9884. ReactCurrentDispatcher.current = prevDispatcher;
  9885. }
  9886. },
  9887. useDebugValue: function(value, formatterFn) {
  9888. currentHookNameInDev = "useDebugValue";
  9889. warnInvalidHookAccess();
  9890. updateHookTypesDev();
  9891. return updateDebugValue();
  9892. },
  9893. useResponder: function(responder, props) {
  9894. currentHookNameInDev = "useResponder";
  9895. warnInvalidHookAccess();
  9896. updateHookTypesDev();
  9897. return createDeprecatedResponderListener(responder, props);
  9898. },
  9899. useDeferredValue: function(value, config) {
  9900. currentHookNameInDev = "useDeferredValue";
  9901. warnInvalidHookAccess();
  9902. updateHookTypesDev();
  9903. return rerenderDeferredValue(value, config);
  9904. },
  9905. useTransition: function(config) {
  9906. currentHookNameInDev = "useTransition";
  9907. warnInvalidHookAccess();
  9908. updateHookTypesDev();
  9909. return rerenderTransition(config);
  9910. },
  9911. useEvent: function(event) {
  9912. currentHookNameInDev = "useEvent";
  9913. warnInvalidHookAccess();
  9914. updateHookTypesDev();
  9915. return updateEventListener();
  9916. }
  9917. };
  9918. }
  9919. var now$1 = Scheduler.unstable_now;
  9920. var commitTime = 0;
  9921. var profilerStartTime = -1;
  9922. function getCommitTime() {
  9923. return commitTime;
  9924. }
  9925. function recordCommitTime() {
  9926. commitTime = now$1();
  9927. }
  9928. function startProfilerTimer(fiber) {
  9929. profilerStartTime = now$1();
  9930. if (fiber.actualStartTime < 0) {
  9931. fiber.actualStartTime = now$1();
  9932. }
  9933. }
  9934. function stopProfilerTimerIfRunning(fiber) {
  9935. profilerStartTime = -1;
  9936. }
  9937. function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
  9938. if (profilerStartTime >= 0) {
  9939. var elapsedTime = now$1() - profilerStartTime;
  9940. fiber.actualDuration += elapsedTime;
  9941. if (overrideBaseTime) {
  9942. fiber.selfBaseDuration = elapsedTime;
  9943. }
  9944. profilerStartTime = -1;
  9945. }
  9946. }
  9947. function enterHydrationState(fiber) {
  9948. {
  9949. return false;
  9950. }
  9951. }
  9952. function prepareToHydrateHostInstance(
  9953. fiber,
  9954. rootContainerInstance,
  9955. hostContext
  9956. ) {
  9957. {
  9958. {
  9959. throw Error(
  9960. "Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue."
  9961. );
  9962. }
  9963. }
  9964. }
  9965. function prepareToHydrateHostTextInstance(fiber) {
  9966. {
  9967. {
  9968. throw Error(
  9969. "Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue."
  9970. );
  9971. }
  9972. }
  9973. var shouldUpdate = hydrateTextInstance();
  9974. }
  9975. function popHydrationState(fiber) {
  9976. {
  9977. return false;
  9978. }
  9979. }
  9980. var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
  9981. var didReceiveUpdate = false;
  9982. var didWarnAboutBadClass;
  9983. var didWarnAboutModulePatternComponent;
  9984. var didWarnAboutContextTypeOnFunctionComponent;
  9985. var didWarnAboutGetDerivedStateOnFunctionComponent;
  9986. var didWarnAboutFunctionRefs;
  9987. var didWarnAboutReassigningProps;
  9988. var didWarnAboutRevealOrder;
  9989. var didWarnAboutTailOptions;
  9990. {
  9991. didWarnAboutBadClass = {};
  9992. didWarnAboutModulePatternComponent = {};
  9993. didWarnAboutContextTypeOnFunctionComponent = {};
  9994. didWarnAboutGetDerivedStateOnFunctionComponent = {};
  9995. didWarnAboutFunctionRefs = {};
  9996. didWarnAboutReassigningProps = false;
  9997. didWarnAboutRevealOrder = {};
  9998. didWarnAboutTailOptions = {};
  9999. }
  10000. function reconcileChildren(
  10001. current,
  10002. workInProgress,
  10003. nextChildren,
  10004. renderExpirationTime
  10005. ) {
  10006. if (current === null) {
  10007. // If this is a fresh new component that hasn't been rendered yet, we
  10008. // won't update its child set by applying minimal side-effects. Instead,
  10009. // we will add them all to the child before it gets rendered. That means
  10010. // we can optimize this reconciliation pass by not tracking side-effects.
  10011. workInProgress.child = mountChildFibers(
  10012. workInProgress,
  10013. null,
  10014. nextChildren,
  10015. renderExpirationTime
  10016. );
  10017. } else {
  10018. // If the current child is the same as the work in progress, it means that
  10019. // we haven't yet started any work on these children. Therefore, we use
  10020. // the clone algorithm to create a copy of all the current children.
  10021. // If we had any progressed work already, that is invalid at this point so
  10022. // let's throw it out.
  10023. workInProgress.child = reconcileChildFibers(
  10024. workInProgress,
  10025. current.child,
  10026. nextChildren,
  10027. renderExpirationTime
  10028. );
  10029. }
  10030. }
  10031. function forceUnmountCurrentAndReconcile(
  10032. current,
  10033. workInProgress,
  10034. nextChildren,
  10035. renderExpirationTime
  10036. ) {
  10037. // This function is fork of reconcileChildren. It's used in cases where we
  10038. // want to reconcile without matching against the existing set. This has the
  10039. // effect of all current children being unmounted; even if the type and key
  10040. // are the same, the old child is unmounted and a new child is created.
  10041. //
  10042. // To do this, we're going to go through the reconcile algorithm twice. In
  10043. // the first pass, we schedule a deletion for all the current children by
  10044. // passing null.
  10045. workInProgress.child = reconcileChildFibers(
  10046. workInProgress,
  10047. current.child,
  10048. null,
  10049. renderExpirationTime
  10050. ); // In the second pass, we mount the new children. The trick here is that we
  10051. // pass null in place of where we usually pass the current child set. This has
  10052. // the effect of remounting all children regardless of whether their
  10053. // identities match.
  10054. workInProgress.child = reconcileChildFibers(
  10055. workInProgress,
  10056. null,
  10057. nextChildren,
  10058. renderExpirationTime
  10059. );
  10060. }
  10061. function updateForwardRef(
  10062. current,
  10063. workInProgress,
  10064. Component,
  10065. nextProps,
  10066. renderExpirationTime
  10067. ) {
  10068. // TODO: current can be non-null here even if the component
  10069. // hasn't yet mounted. This happens after the first render suspends.
  10070. // We'll need to figure out if this is fine or can cause issues.
  10071. {
  10072. if (workInProgress.type !== workInProgress.elementType) {
  10073. // Lazy component props can't be validated in createElement
  10074. // because they're only guaranteed to be resolved here.
  10075. var innerPropTypes = Component.propTypes;
  10076. if (innerPropTypes) {
  10077. checkPropTypes(
  10078. innerPropTypes,
  10079. nextProps, // Resolved props
  10080. "prop",
  10081. getComponentName(Component)
  10082. );
  10083. }
  10084. }
  10085. }
  10086. var render = Component.render;
  10087. var ref = workInProgress.ref; // The rest is a fork of updateFunctionComponent
  10088. var nextChildren;
  10089. prepareToReadContext(workInProgress, renderExpirationTime);
  10090. {
  10091. ReactCurrentOwner$1.current = workInProgress;
  10092. setIsRendering(true);
  10093. nextChildren = renderWithHooks(
  10094. current,
  10095. workInProgress,
  10096. render,
  10097. nextProps,
  10098. ref,
  10099. renderExpirationTime
  10100. );
  10101. if (workInProgress.mode & StrictMode) {
  10102. // Only double-render components with Hooks
  10103. if (workInProgress.memoizedState !== null) {
  10104. nextChildren = renderWithHooks(
  10105. current,
  10106. workInProgress,
  10107. render,
  10108. nextProps,
  10109. ref,
  10110. renderExpirationTime
  10111. );
  10112. }
  10113. }
  10114. setIsRendering(false);
  10115. }
  10116. if (current !== null && !didReceiveUpdate) {
  10117. bailoutHooks(current, workInProgress, renderExpirationTime);
  10118. return bailoutOnAlreadyFinishedWork(
  10119. current,
  10120. workInProgress,
  10121. renderExpirationTime
  10122. );
  10123. } // React DevTools reads this flag.
  10124. workInProgress.effectTag |= PerformedWork;
  10125. reconcileChildren(
  10126. current,
  10127. workInProgress,
  10128. nextChildren,
  10129. renderExpirationTime
  10130. );
  10131. return workInProgress.child;
  10132. }
  10133. function updateMemoComponent(
  10134. current,
  10135. workInProgress,
  10136. Component,
  10137. nextProps,
  10138. updateExpirationTime,
  10139. renderExpirationTime
  10140. ) {
  10141. if (current === null) {
  10142. var type = Component.type;
  10143. if (
  10144. isSimpleFunctionComponent(type) &&
  10145. Component.compare === null && // SimpleMemoComponent codepath doesn't resolve outer props either.
  10146. Component.defaultProps === undefined
  10147. ) {
  10148. var resolvedType = type;
  10149. {
  10150. resolvedType = resolveFunctionForHotReloading(type);
  10151. } // If this is a plain function component without default props,
  10152. // and with only the default shallow comparison, we upgrade it
  10153. // to a SimpleMemoComponent to allow fast path updates.
  10154. workInProgress.tag = SimpleMemoComponent;
  10155. workInProgress.type = resolvedType;
  10156. {
  10157. validateFunctionComponentInDev(workInProgress, type);
  10158. }
  10159. return updateSimpleMemoComponent(
  10160. current,
  10161. workInProgress,
  10162. resolvedType,
  10163. nextProps,
  10164. updateExpirationTime,
  10165. renderExpirationTime
  10166. );
  10167. }
  10168. {
  10169. var innerPropTypes = type.propTypes;
  10170. if (innerPropTypes) {
  10171. // Inner memo component props aren't currently validated in createElement.
  10172. // We could move it there, but we'd still need this for lazy code path.
  10173. checkPropTypes(
  10174. innerPropTypes,
  10175. nextProps, // Resolved props
  10176. "prop",
  10177. getComponentName(type)
  10178. );
  10179. }
  10180. }
  10181. var child = createFiberFromTypeAndProps(
  10182. Component.type,
  10183. null,
  10184. nextProps,
  10185. null,
  10186. workInProgress.mode,
  10187. renderExpirationTime
  10188. );
  10189. child.ref = workInProgress.ref;
  10190. child.return = workInProgress;
  10191. workInProgress.child = child;
  10192. return child;
  10193. }
  10194. {
  10195. var _type = Component.type;
  10196. var _innerPropTypes = _type.propTypes;
  10197. if (_innerPropTypes) {
  10198. // Inner memo component props aren't currently validated in createElement.
  10199. // We could move it there, but we'd still need this for lazy code path.
  10200. checkPropTypes(
  10201. _innerPropTypes,
  10202. nextProps, // Resolved props
  10203. "prop",
  10204. getComponentName(_type)
  10205. );
  10206. }
  10207. }
  10208. var currentChild = current.child; // This is always exactly one child
  10209. if (updateExpirationTime < renderExpirationTime) {
  10210. // This will be the props with resolved defaultProps,
  10211. // unlike current.memoizedProps which will be the unresolved ones.
  10212. var prevProps = currentChild.memoizedProps; // Default to shallow comparison
  10213. var compare = Component.compare;
  10214. compare = compare !== null ? compare : shallowEqual;
  10215. if (compare(prevProps, nextProps) && current.ref === workInProgress.ref) {
  10216. return bailoutOnAlreadyFinishedWork(
  10217. current,
  10218. workInProgress,
  10219. renderExpirationTime
  10220. );
  10221. }
  10222. } // React DevTools reads this flag.
  10223. workInProgress.effectTag |= PerformedWork;
  10224. var newChild = createWorkInProgress(currentChild, nextProps);
  10225. newChild.ref = workInProgress.ref;
  10226. newChild.return = workInProgress;
  10227. workInProgress.child = newChild;
  10228. return newChild;
  10229. }
  10230. function updateSimpleMemoComponent(
  10231. current,
  10232. workInProgress,
  10233. Component,
  10234. nextProps,
  10235. updateExpirationTime,
  10236. renderExpirationTime
  10237. ) {
  10238. // TODO: current can be non-null here even if the component
  10239. // hasn't yet mounted. This happens when the inner render suspends.
  10240. // We'll need to figure out if this is fine or can cause issues.
  10241. {
  10242. if (workInProgress.type !== workInProgress.elementType) {
  10243. // Lazy component props can't be validated in createElement
  10244. // because they're only guaranteed to be resolved here.
  10245. var outerMemoType = workInProgress.elementType;
  10246. if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
  10247. // We warn when you define propTypes on lazy()
  10248. // so let's just skip over it to find memo() outer wrapper.
  10249. // Inner props for memo are validated later.
  10250. outerMemoType = refineResolvedLazyComponent(outerMemoType);
  10251. }
  10252. var outerPropTypes = outerMemoType && outerMemoType.propTypes;
  10253. if (outerPropTypes) {
  10254. checkPropTypes(
  10255. outerPropTypes,
  10256. nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
  10257. "prop",
  10258. getComponentName(outerMemoType)
  10259. );
  10260. } // Inner propTypes will be validated in the function component path.
  10261. }
  10262. }
  10263. if (current !== null) {
  10264. var prevProps = current.memoizedProps;
  10265. if (
  10266. shallowEqual(prevProps, nextProps) &&
  10267. current.ref === workInProgress.ref && // Prevent bailout if the implementation changed due to hot reload.
  10268. workInProgress.type === current.type
  10269. ) {
  10270. didReceiveUpdate = false;
  10271. if (updateExpirationTime < renderExpirationTime) {
  10272. // The pending update priority was cleared at the beginning of
  10273. // beginWork. We're about to bail out, but there might be additional
  10274. // updates at a lower priority. Usually, the priority level of the
  10275. // remaining updates is accumlated during the evaluation of the
  10276. // component (i.e. when processing the update queue). But since since
  10277. // we're bailing out early *without* evaluating the component, we need
  10278. // to account for it here, too. Reset to the value of the current fiber.
  10279. // NOTE: This only applies to SimpleMemoComponent, not MemoComponent,
  10280. // because a MemoComponent fiber does not have hooks or an update queue;
  10281. // rather, it wraps around an inner component, which may or may not
  10282. // contains hooks.
  10283. // TODO: Move the reset at in beginWork out of the common path so that
  10284. // this is no longer necessary.
  10285. workInProgress.expirationTime = current.expirationTime;
  10286. return bailoutOnAlreadyFinishedWork(
  10287. current,
  10288. workInProgress,
  10289. renderExpirationTime
  10290. );
  10291. }
  10292. }
  10293. }
  10294. return updateFunctionComponent(
  10295. current,
  10296. workInProgress,
  10297. Component,
  10298. nextProps,
  10299. renderExpirationTime
  10300. );
  10301. }
  10302. function updateFragment(current, workInProgress, renderExpirationTime) {
  10303. var nextChildren = workInProgress.pendingProps;
  10304. reconcileChildren(
  10305. current,
  10306. workInProgress,
  10307. nextChildren,
  10308. renderExpirationTime
  10309. );
  10310. return workInProgress.child;
  10311. }
  10312. function updateMode(current, workInProgress, renderExpirationTime) {
  10313. var nextChildren = workInProgress.pendingProps.children;
  10314. reconcileChildren(
  10315. current,
  10316. workInProgress,
  10317. nextChildren,
  10318. renderExpirationTime
  10319. );
  10320. return workInProgress.child;
  10321. }
  10322. function updateProfiler(current, workInProgress, renderExpirationTime) {
  10323. {
  10324. workInProgress.effectTag |= Update; // Reset effect durations for the next eventual effect phase.
  10325. // These are reset during render to allow the DevTools commit hook a chance to read them,
  10326. var stateNode = workInProgress.stateNode;
  10327. stateNode.effectDuration = 0;
  10328. stateNode.passiveEffectDuration = 0;
  10329. }
  10330. var nextProps = workInProgress.pendingProps;
  10331. var nextChildren = nextProps.children;
  10332. reconcileChildren(
  10333. current,
  10334. workInProgress,
  10335. nextChildren,
  10336. renderExpirationTime
  10337. );
  10338. return workInProgress.child;
  10339. }
  10340. function markRef(current, workInProgress) {
  10341. var ref = workInProgress.ref;
  10342. if (
  10343. (current === null && ref !== null) ||
  10344. (current !== null && current.ref !== ref)
  10345. ) {
  10346. // Schedule a Ref effect
  10347. workInProgress.effectTag |= Ref;
  10348. }
  10349. }
  10350. function updateFunctionComponent(
  10351. current,
  10352. workInProgress,
  10353. Component,
  10354. nextProps,
  10355. renderExpirationTime
  10356. ) {
  10357. {
  10358. if (workInProgress.type !== workInProgress.elementType) {
  10359. // Lazy component props can't be validated in createElement
  10360. // because they're only guaranteed to be resolved here.
  10361. var innerPropTypes = Component.propTypes;
  10362. if (innerPropTypes) {
  10363. checkPropTypes(
  10364. innerPropTypes,
  10365. nextProps, // Resolved props
  10366. "prop",
  10367. getComponentName(Component)
  10368. );
  10369. }
  10370. }
  10371. }
  10372. var context;
  10373. {
  10374. var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
  10375. context = getMaskedContext(workInProgress, unmaskedContext);
  10376. }
  10377. var nextChildren;
  10378. prepareToReadContext(workInProgress, renderExpirationTime);
  10379. {
  10380. ReactCurrentOwner$1.current = workInProgress;
  10381. setIsRendering(true);
  10382. nextChildren = renderWithHooks(
  10383. current,
  10384. workInProgress,
  10385. Component,
  10386. nextProps,
  10387. context,
  10388. renderExpirationTime
  10389. );
  10390. if (workInProgress.mode & StrictMode) {
  10391. // Only double-render components with Hooks
  10392. if (workInProgress.memoizedState !== null) {
  10393. nextChildren = renderWithHooks(
  10394. current,
  10395. workInProgress,
  10396. Component,
  10397. nextProps,
  10398. context,
  10399. renderExpirationTime
  10400. );
  10401. }
  10402. }
  10403. setIsRendering(false);
  10404. }
  10405. if (current !== null && !didReceiveUpdate) {
  10406. bailoutHooks(current, workInProgress, renderExpirationTime);
  10407. return bailoutOnAlreadyFinishedWork(
  10408. current,
  10409. workInProgress,
  10410. renderExpirationTime
  10411. );
  10412. } // React DevTools reads this flag.
  10413. workInProgress.effectTag |= PerformedWork;
  10414. reconcileChildren(
  10415. current,
  10416. workInProgress,
  10417. nextChildren,
  10418. renderExpirationTime
  10419. );
  10420. return workInProgress.child;
  10421. }
  10422. function updateClassComponent(
  10423. current,
  10424. workInProgress,
  10425. Component,
  10426. nextProps,
  10427. renderExpirationTime
  10428. ) {
  10429. {
  10430. if (workInProgress.type !== workInProgress.elementType) {
  10431. // Lazy component props can't be validated in createElement
  10432. // because they're only guaranteed to be resolved here.
  10433. var innerPropTypes = Component.propTypes;
  10434. if (innerPropTypes) {
  10435. checkPropTypes(
  10436. innerPropTypes,
  10437. nextProps, // Resolved props
  10438. "prop",
  10439. getComponentName(Component)
  10440. );
  10441. }
  10442. }
  10443. } // Push context providers early to prevent context stack mismatches.
  10444. // During mounting we don't know the child context yet as the instance doesn't exist.
  10445. // We will invalidate the child context in finishClassComponent() right after rendering.
  10446. var hasContext;
  10447. if (isContextProvider(Component)) {
  10448. hasContext = true;
  10449. pushContextProvider(workInProgress);
  10450. } else {
  10451. hasContext = false;
  10452. }
  10453. prepareToReadContext(workInProgress, renderExpirationTime);
  10454. var instance = workInProgress.stateNode;
  10455. var shouldUpdate;
  10456. if (instance === null) {
  10457. if (current !== null) {
  10458. // A class component without an instance only mounts if it suspended
  10459. // inside a non-concurrent tree, in an inconsistent state. We want to
  10460. // treat it like a new mount, even though an empty version of it already
  10461. // committed. Disconnect the alternate pointers.
  10462. current.alternate = null;
  10463. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  10464. workInProgress.effectTag |= Placement;
  10465. } // In the initial pass we might need to construct the instance.
  10466. constructClassInstance(workInProgress, Component, nextProps);
  10467. mountClassInstance(
  10468. workInProgress,
  10469. Component,
  10470. nextProps,
  10471. renderExpirationTime
  10472. );
  10473. shouldUpdate = true;
  10474. } else if (current === null) {
  10475. // In a resume, we'll already have an instance we can reuse.
  10476. shouldUpdate = resumeMountClassInstance(
  10477. workInProgress,
  10478. Component,
  10479. nextProps,
  10480. renderExpirationTime
  10481. );
  10482. } else {
  10483. shouldUpdate = updateClassInstance(
  10484. current,
  10485. workInProgress,
  10486. Component,
  10487. nextProps,
  10488. renderExpirationTime
  10489. );
  10490. }
  10491. var nextUnitOfWork = finishClassComponent(
  10492. current,
  10493. workInProgress,
  10494. Component,
  10495. shouldUpdate,
  10496. hasContext,
  10497. renderExpirationTime
  10498. );
  10499. {
  10500. var inst = workInProgress.stateNode;
  10501. if (inst.props !== nextProps) {
  10502. if (!didWarnAboutReassigningProps) {
  10503. error(
  10504. "It looks like %s is reassigning its own `this.props` while rendering. " +
  10505. "This is not supported and can lead to confusing bugs.",
  10506. getComponentName(workInProgress.type) || "a component"
  10507. );
  10508. }
  10509. didWarnAboutReassigningProps = true;
  10510. }
  10511. }
  10512. return nextUnitOfWork;
  10513. }
  10514. function finishClassComponent(
  10515. current,
  10516. workInProgress,
  10517. Component,
  10518. shouldUpdate,
  10519. hasContext,
  10520. renderExpirationTime
  10521. ) {
  10522. // Refs should update even if shouldComponentUpdate returns false
  10523. markRef(current, workInProgress);
  10524. var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
  10525. if (!shouldUpdate && !didCaptureError) {
  10526. // Context providers should defer to sCU for rendering
  10527. if (hasContext) {
  10528. invalidateContextProvider(workInProgress, Component, false);
  10529. }
  10530. return bailoutOnAlreadyFinishedWork(
  10531. current,
  10532. workInProgress,
  10533. renderExpirationTime
  10534. );
  10535. }
  10536. var instance = workInProgress.stateNode; // Rerender
  10537. ReactCurrentOwner$1.current = workInProgress;
  10538. var nextChildren;
  10539. if (
  10540. didCaptureError &&
  10541. typeof Component.getDerivedStateFromError !== "function"
  10542. ) {
  10543. // If we captured an error, but getDerivedStateFromError is not defined,
  10544. // unmount all the children. componentDidCatch will schedule an update to
  10545. // re-render a fallback. This is temporary until we migrate everyone to
  10546. // the new API.
  10547. // TODO: Warn in a future release.
  10548. nextChildren = null;
  10549. {
  10550. stopProfilerTimerIfRunning();
  10551. }
  10552. } else {
  10553. {
  10554. setIsRendering(true);
  10555. nextChildren = instance.render();
  10556. if (workInProgress.mode & StrictMode) {
  10557. instance.render();
  10558. }
  10559. setIsRendering(false);
  10560. }
  10561. } // React DevTools reads this flag.
  10562. workInProgress.effectTag |= PerformedWork;
  10563. if (current !== null && didCaptureError) {
  10564. // If we're recovering from an error, reconcile without reusing any of
  10565. // the existing children. Conceptually, the normal children and the children
  10566. // that are shown on error are two different sets, so we shouldn't reuse
  10567. // normal children even if their identities match.
  10568. forceUnmountCurrentAndReconcile(
  10569. current,
  10570. workInProgress,
  10571. nextChildren,
  10572. renderExpirationTime
  10573. );
  10574. } else {
  10575. reconcileChildren(
  10576. current,
  10577. workInProgress,
  10578. nextChildren,
  10579. renderExpirationTime
  10580. );
  10581. } // Memoize state using the values we just used to render.
  10582. // TODO: Restructure so we never read values from the instance.
  10583. workInProgress.memoizedState = instance.state; // The context might have changed so we need to recalculate it.
  10584. if (hasContext) {
  10585. invalidateContextProvider(workInProgress, Component, true);
  10586. }
  10587. return workInProgress.child;
  10588. }
  10589. function pushHostRootContext(workInProgress) {
  10590. var root = workInProgress.stateNode;
  10591. if (root.pendingContext) {
  10592. pushTopLevelContextObject(
  10593. workInProgress,
  10594. root.pendingContext,
  10595. root.pendingContext !== root.context
  10596. );
  10597. } else if (root.context) {
  10598. // Should always be set
  10599. pushTopLevelContextObject(workInProgress, root.context, false);
  10600. }
  10601. pushHostContainer(workInProgress, root.containerInfo);
  10602. }
  10603. function updateHostRoot(current, workInProgress, renderExpirationTime) {
  10604. pushHostRootContext(workInProgress);
  10605. var updateQueue = workInProgress.updateQueue;
  10606. if (!(current !== null && updateQueue !== null)) {
  10607. throw Error(
  10608. "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."
  10609. );
  10610. }
  10611. var nextProps = workInProgress.pendingProps;
  10612. var prevState = workInProgress.memoizedState;
  10613. var prevChildren = prevState !== null ? prevState.element : null;
  10614. cloneUpdateQueue(current, workInProgress);
  10615. processUpdateQueue(workInProgress, nextProps, null, renderExpirationTime);
  10616. var nextState = workInProgress.memoizedState; // Caution: React DevTools currently depends on this property
  10617. // being called "element".
  10618. var nextChildren = nextState.element;
  10619. if (nextChildren === prevChildren) {
  10620. return bailoutOnAlreadyFinishedWork(
  10621. current,
  10622. workInProgress,
  10623. renderExpirationTime
  10624. );
  10625. }
  10626. var root = workInProgress.stateNode;
  10627. if (root.hydrate && enterHydrationState()) {
  10628. // If we don't have any current children this might be the first pass.
  10629. // We always try to hydrate. If this isn't a hydration pass there won't
  10630. // be any children to hydrate which is effectively the same thing as
  10631. // not hydrating.
  10632. var child = mountChildFibers(
  10633. workInProgress,
  10634. null,
  10635. nextChildren,
  10636. renderExpirationTime
  10637. );
  10638. workInProgress.child = child;
  10639. var node = child;
  10640. while (node) {
  10641. // Mark each child as hydrating. This is a fast path to know whether this
  10642. // tree is part of a hydrating tree. This is used to determine if a child
  10643. // node has fully mounted yet, and for scheduling event replaying.
  10644. // Conceptually this is similar to Placement in that a new subtree is
  10645. // inserted into the React tree here. It just happens to not need DOM
  10646. // mutations because it already exists.
  10647. node.effectTag = (node.effectTag & ~Placement) | Hydrating;
  10648. node = node.sibling;
  10649. }
  10650. } else {
  10651. // Otherwise reset hydration state in case we aborted and resumed another
  10652. // root.
  10653. reconcileChildren(
  10654. current,
  10655. workInProgress,
  10656. nextChildren,
  10657. renderExpirationTime
  10658. );
  10659. }
  10660. return workInProgress.child;
  10661. }
  10662. function updateHostComponent(current, workInProgress, renderExpirationTime) {
  10663. pushHostContext(workInProgress);
  10664. var type = workInProgress.type;
  10665. var nextProps = workInProgress.pendingProps;
  10666. var prevProps = current !== null ? current.memoizedProps : null;
  10667. var nextChildren = nextProps.children;
  10668. if (prevProps !== null && shouldSetTextContent()) {
  10669. // If we're switching from a direct text child to a normal child, or to
  10670. // empty, we need to schedule the text content to be reset.
  10671. workInProgress.effectTag |= ContentReset;
  10672. }
  10673. markRef(current, workInProgress); // Check the host config to see if the children are offscreen/hidden.
  10674. if (
  10675. workInProgress.mode & ConcurrentMode &&
  10676. renderExpirationTime !== Never &&
  10677. shouldDeprioritizeSubtree()
  10678. ) {
  10679. {
  10680. markSpawnedWork(Never);
  10681. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  10682. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  10683. return null;
  10684. }
  10685. reconcileChildren(
  10686. current,
  10687. workInProgress,
  10688. nextChildren,
  10689. renderExpirationTime
  10690. );
  10691. return workInProgress.child;
  10692. }
  10693. function updateHostText(current, workInProgress) {
  10694. // immediately after.
  10695. return null;
  10696. }
  10697. function mountLazyComponent(
  10698. _current,
  10699. workInProgress,
  10700. elementType,
  10701. updateExpirationTime,
  10702. renderExpirationTime
  10703. ) {
  10704. if (_current !== null) {
  10705. // A lazy component only mounts if it suspended inside a non-
  10706. // concurrent tree, in an inconsistent state. We want to treat it like
  10707. // a new mount, even though an empty version of it already committed.
  10708. // Disconnect the alternate pointers.
  10709. _current.alternate = null;
  10710. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  10711. workInProgress.effectTag |= Placement;
  10712. }
  10713. var props = workInProgress.pendingProps; // We can't start a User Timing measurement with correct label yet.
  10714. // Cancel and resume right after we know the tag.
  10715. cancelWorkTimer(workInProgress);
  10716. var Component = readLazyComponentType(elementType); // Store the unwrapped component in the type.
  10717. workInProgress.type = Component;
  10718. var resolvedTag = (workInProgress.tag = resolveLazyComponentTag(Component));
  10719. startWorkTimer(workInProgress);
  10720. var resolvedProps = resolveDefaultProps(Component, props);
  10721. var child;
  10722. switch (resolvedTag) {
  10723. case FunctionComponent: {
  10724. {
  10725. validateFunctionComponentInDev(workInProgress, Component);
  10726. workInProgress.type = Component = resolveFunctionForHotReloading(
  10727. Component
  10728. );
  10729. }
  10730. child = updateFunctionComponent(
  10731. null,
  10732. workInProgress,
  10733. Component,
  10734. resolvedProps,
  10735. renderExpirationTime
  10736. );
  10737. return child;
  10738. }
  10739. case ClassComponent: {
  10740. {
  10741. workInProgress.type = Component = resolveClassForHotReloading(
  10742. Component
  10743. );
  10744. }
  10745. child = updateClassComponent(
  10746. null,
  10747. workInProgress,
  10748. Component,
  10749. resolvedProps,
  10750. renderExpirationTime
  10751. );
  10752. return child;
  10753. }
  10754. case ForwardRef: {
  10755. {
  10756. workInProgress.type = Component = resolveForwardRefForHotReloading(
  10757. Component
  10758. );
  10759. }
  10760. child = updateForwardRef(
  10761. null,
  10762. workInProgress,
  10763. Component,
  10764. resolvedProps,
  10765. renderExpirationTime
  10766. );
  10767. return child;
  10768. }
  10769. case MemoComponent: {
  10770. {
  10771. if (workInProgress.type !== workInProgress.elementType) {
  10772. var outerPropTypes = Component.propTypes;
  10773. if (outerPropTypes) {
  10774. checkPropTypes(
  10775. outerPropTypes,
  10776. resolvedProps, // Resolved for outer only
  10777. "prop",
  10778. getComponentName(Component)
  10779. );
  10780. }
  10781. }
  10782. }
  10783. child = updateMemoComponent(
  10784. null,
  10785. workInProgress,
  10786. Component,
  10787. resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
  10788. updateExpirationTime,
  10789. renderExpirationTime
  10790. );
  10791. return child;
  10792. }
  10793. }
  10794. var hint = "";
  10795. {
  10796. if (
  10797. Component !== null &&
  10798. typeof Component === "object" &&
  10799. Component.$$typeof === REACT_LAZY_TYPE
  10800. ) {
  10801. hint = " Did you wrap a component in React.lazy() more than once?";
  10802. }
  10803. } // This message intentionally doesn't mention ForwardRef or MemoComponent
  10804. // because the fact that it's a separate type of work is an
  10805. // implementation detail.
  10806. {
  10807. throw Error(
  10808. "Element type is invalid. Received a promise that resolves to: " +
  10809. Component +
  10810. ". Lazy element type must resolve to a class or function." +
  10811. hint
  10812. );
  10813. }
  10814. }
  10815. function mountIncompleteClassComponent(
  10816. _current,
  10817. workInProgress,
  10818. Component,
  10819. nextProps,
  10820. renderExpirationTime
  10821. ) {
  10822. if (_current !== null) {
  10823. // An incomplete component only mounts if it suspended inside a non-
  10824. // concurrent tree, in an inconsistent state. We want to treat it like
  10825. // a new mount, even though an empty version of it already committed.
  10826. // Disconnect the alternate pointers.
  10827. _current.alternate = null;
  10828. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  10829. workInProgress.effectTag |= Placement;
  10830. } // Promote the fiber to a class and try rendering again.
  10831. workInProgress.tag = ClassComponent; // The rest of this function is a fork of `updateClassComponent`
  10832. // Push context providers early to prevent context stack mismatches.
  10833. // During mounting we don't know the child context yet as the instance doesn't exist.
  10834. // We will invalidate the child context in finishClassComponent() right after rendering.
  10835. var hasContext;
  10836. if (isContextProvider(Component)) {
  10837. hasContext = true;
  10838. pushContextProvider(workInProgress);
  10839. } else {
  10840. hasContext = false;
  10841. }
  10842. prepareToReadContext(workInProgress, renderExpirationTime);
  10843. constructClassInstance(workInProgress, Component, nextProps);
  10844. mountClassInstance(
  10845. workInProgress,
  10846. Component,
  10847. nextProps,
  10848. renderExpirationTime
  10849. );
  10850. return finishClassComponent(
  10851. null,
  10852. workInProgress,
  10853. Component,
  10854. true,
  10855. hasContext,
  10856. renderExpirationTime
  10857. );
  10858. }
  10859. function mountIndeterminateComponent(
  10860. _current,
  10861. workInProgress,
  10862. Component,
  10863. renderExpirationTime
  10864. ) {
  10865. if (_current !== null) {
  10866. // An indeterminate component only mounts if it suspended inside a non-
  10867. // concurrent tree, in an inconsistent state. We want to treat it like
  10868. // a new mount, even though an empty version of it already committed.
  10869. // Disconnect the alternate pointers.
  10870. _current.alternate = null;
  10871. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  10872. workInProgress.effectTag |= Placement;
  10873. }
  10874. var props = workInProgress.pendingProps;
  10875. var context;
  10876. {
  10877. var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
  10878. context = getMaskedContext(workInProgress, unmaskedContext);
  10879. }
  10880. prepareToReadContext(workInProgress, renderExpirationTime);
  10881. var value;
  10882. {
  10883. if (
  10884. Component.prototype &&
  10885. typeof Component.prototype.render === "function"
  10886. ) {
  10887. var componentName = getComponentName(Component) || "Unknown";
  10888. if (!didWarnAboutBadClass[componentName]) {
  10889. error(
  10890. "The <%s /> component appears to have a render method, but doesn't extend React.Component. " +
  10891. "This is likely to cause errors. Change %s to extend React.Component instead.",
  10892. componentName,
  10893. componentName
  10894. );
  10895. didWarnAboutBadClass[componentName] = true;
  10896. }
  10897. }
  10898. if (workInProgress.mode & StrictMode) {
  10899. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
  10900. }
  10901. ReactCurrentOwner$1.current = workInProgress;
  10902. value = renderWithHooks(
  10903. null,
  10904. workInProgress,
  10905. Component,
  10906. props,
  10907. context,
  10908. renderExpirationTime
  10909. );
  10910. } // React DevTools reads this flag.
  10911. workInProgress.effectTag |= PerformedWork;
  10912. if (
  10913. typeof value === "object" &&
  10914. value !== null &&
  10915. typeof value.render === "function" &&
  10916. value.$$typeof === undefined
  10917. ) {
  10918. {
  10919. var _componentName = getComponentName(Component) || "Unknown";
  10920. if (!didWarnAboutModulePatternComponent[_componentName]) {
  10921. error(
  10922. "The <%s /> component appears to be a function component that returns a class instance. " +
  10923. "Change %s to a class that extends React.Component instead. " +
  10924. "If you can't use a class try assigning the prototype on the function as a workaround. " +
  10925. "`%s.prototype = React.Component.prototype`. Don't use an arrow function since it " +
  10926. "cannot be called with `new` by React.",
  10927. _componentName,
  10928. _componentName,
  10929. _componentName
  10930. );
  10931. didWarnAboutModulePatternComponent[_componentName] = true;
  10932. }
  10933. } // Proceed under the assumption that this is a class instance
  10934. workInProgress.tag = ClassComponent; // Throw out any hooks that were used.
  10935. workInProgress.memoizedState = null;
  10936. workInProgress.updateQueue = null; // Push context providers early to prevent context stack mismatches.
  10937. // During mounting we don't know the child context yet as the instance doesn't exist.
  10938. // We will invalidate the child context in finishClassComponent() right after rendering.
  10939. var hasContext = false;
  10940. if (isContextProvider(Component)) {
  10941. hasContext = true;
  10942. pushContextProvider(workInProgress);
  10943. } else {
  10944. hasContext = false;
  10945. }
  10946. workInProgress.memoizedState =
  10947. value.state !== null && value.state !== undefined ? value.state : null;
  10948. initializeUpdateQueue(workInProgress);
  10949. var getDerivedStateFromProps = Component.getDerivedStateFromProps;
  10950. if (typeof getDerivedStateFromProps === "function") {
  10951. applyDerivedStateFromProps(
  10952. workInProgress,
  10953. Component,
  10954. getDerivedStateFromProps,
  10955. props
  10956. );
  10957. }
  10958. adoptClassInstance(workInProgress, value);
  10959. mountClassInstance(workInProgress, Component, props, renderExpirationTime);
  10960. return finishClassComponent(
  10961. null,
  10962. workInProgress,
  10963. Component,
  10964. true,
  10965. hasContext,
  10966. renderExpirationTime
  10967. );
  10968. } else {
  10969. // Proceed under the assumption that this is a function component
  10970. workInProgress.tag = FunctionComponent;
  10971. {
  10972. if (workInProgress.mode & StrictMode) {
  10973. // Only double-render components with Hooks
  10974. if (workInProgress.memoizedState !== null) {
  10975. value = renderWithHooks(
  10976. null,
  10977. workInProgress,
  10978. Component,
  10979. props,
  10980. context,
  10981. renderExpirationTime
  10982. );
  10983. }
  10984. }
  10985. }
  10986. reconcileChildren(null, workInProgress, value, renderExpirationTime);
  10987. {
  10988. validateFunctionComponentInDev(workInProgress, Component);
  10989. }
  10990. return workInProgress.child;
  10991. }
  10992. }
  10993. function validateFunctionComponentInDev(workInProgress, Component) {
  10994. {
  10995. if (Component) {
  10996. if (Component.childContextTypes) {
  10997. error(
  10998. "%s(...): childContextTypes cannot be defined on a function component.",
  10999. Component.displayName || Component.name || "Component"
  11000. );
  11001. }
  11002. }
  11003. if (workInProgress.ref !== null) {
  11004. var info = "";
  11005. var ownerName = getCurrentFiberOwnerNameInDevOrNull();
  11006. if (ownerName) {
  11007. info += "\n\nCheck the render method of `" + ownerName + "`.";
  11008. }
  11009. var warningKey = ownerName || workInProgress._debugID || "";
  11010. var debugSource = workInProgress._debugSource;
  11011. if (debugSource) {
  11012. warningKey = debugSource.fileName + ":" + debugSource.lineNumber;
  11013. }
  11014. if (!didWarnAboutFunctionRefs[warningKey]) {
  11015. didWarnAboutFunctionRefs[warningKey] = true;
  11016. error(
  11017. "Function components cannot be given refs. " +
  11018. "Attempts to access this ref will fail. " +
  11019. "Did you mean to use React.forwardRef()?%s",
  11020. info
  11021. );
  11022. }
  11023. }
  11024. if (typeof Component.getDerivedStateFromProps === "function") {
  11025. var _componentName2 = getComponentName(Component) || "Unknown";
  11026. if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2]) {
  11027. error(
  11028. "%s: Function components do not support getDerivedStateFromProps.",
  11029. _componentName2
  11030. );
  11031. didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2] = true;
  11032. }
  11033. }
  11034. if (
  11035. typeof Component.contextType === "object" &&
  11036. Component.contextType !== null
  11037. ) {
  11038. var _componentName3 = getComponentName(Component) || "Unknown";
  11039. if (!didWarnAboutContextTypeOnFunctionComponent[_componentName3]) {
  11040. error(
  11041. "%s: Function components do not support contextType.",
  11042. _componentName3
  11043. );
  11044. didWarnAboutContextTypeOnFunctionComponent[_componentName3] = true;
  11045. }
  11046. }
  11047. }
  11048. }
  11049. var SUSPENDED_MARKER = {
  11050. dehydrated: null,
  11051. retryTime: NoWork
  11052. };
  11053. function shouldRemainOnFallback(suspenseContext, current, workInProgress) {
  11054. // If the context is telling us that we should show a fallback, and we're not
  11055. // already showing content, then we should show the fallback instead.
  11056. return (
  11057. hasSuspenseContext(suspenseContext, ForceSuspenseFallback) &&
  11058. (current === null || current.memoizedState !== null)
  11059. );
  11060. }
  11061. function updateSuspenseComponent(
  11062. current,
  11063. workInProgress,
  11064. renderExpirationTime
  11065. ) {
  11066. var mode = workInProgress.mode;
  11067. var nextProps = workInProgress.pendingProps; // This is used by DevTools to force a boundary to suspend.
  11068. {
  11069. if (shouldSuspend(workInProgress)) {
  11070. workInProgress.effectTag |= DidCapture;
  11071. }
  11072. }
  11073. var suspenseContext = suspenseStackCursor.current;
  11074. var nextDidTimeout = false;
  11075. var didSuspend = (workInProgress.effectTag & DidCapture) !== NoEffect;
  11076. if (didSuspend || shouldRemainOnFallback(suspenseContext, current)) {
  11077. // Something in this boundary's subtree already suspended. Switch to
  11078. // rendering the fallback children.
  11079. nextDidTimeout = true;
  11080. workInProgress.effectTag &= ~DidCapture;
  11081. } else {
  11082. // Attempting the main content
  11083. if (current === null || current.memoizedState !== null) {
  11084. // This is a new mount or this boundary is already showing a fallback state.
  11085. // Mark this subtree context as having at least one invisible parent that could
  11086. // handle the fallback state.
  11087. // Boundaries without fallbacks or should be avoided are not considered since
  11088. // they cannot handle preferred fallback states.
  11089. if (
  11090. nextProps.fallback !== undefined &&
  11091. nextProps.unstable_avoidThisFallback !== true
  11092. ) {
  11093. suspenseContext = addSubtreeSuspenseContext(
  11094. suspenseContext,
  11095. InvisibleParentSuspenseContext
  11096. );
  11097. }
  11098. }
  11099. }
  11100. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  11101. pushSuspenseContext(workInProgress, suspenseContext); // This next part is a bit confusing. If the children timeout, we switch to
  11102. // showing the fallback children in place of the "primary" children.
  11103. // However, we don't want to delete the primary children because then their
  11104. // state will be lost (both the React state and the host state, e.g.
  11105. // uncontrolled form inputs). Instead we keep them mounted and hide them.
  11106. // Both the fallback children AND the primary children are rendered at the
  11107. // same time. Once the primary children are un-suspended, we can delete
  11108. // the fallback children — don't need to preserve their state.
  11109. //
  11110. // The two sets of children are siblings in the host environment, but
  11111. // semantically, for purposes of reconciliation, they are two separate sets.
  11112. // So we store them using two fragment fibers.
  11113. //
  11114. // However, we want to avoid allocating extra fibers for every placeholder.
  11115. // They're only necessary when the children time out, because that's the
  11116. // only time when both sets are mounted.
  11117. //
  11118. // So, the extra fragment fibers are only used if the children time out.
  11119. // Otherwise, we render the primary children directly. This requires some
  11120. // custom reconciliation logic to preserve the state of the primary
  11121. // children. It's essentially a very basic form of re-parenting.
  11122. if (current === null) {
  11123. // If we're currently hydrating, try to hydrate this boundary.
  11124. // But only if this has a fallback.
  11125. if (nextProps.fallback !== undefined); // This is the initial mount. This branch is pretty simple because there's
  11126. // no previous state that needs to be preserved.
  11127. if (nextDidTimeout) {
  11128. // Mount separate fragments for primary and fallback children.
  11129. var nextFallbackChildren = nextProps.fallback;
  11130. var primaryChildFragment = createFiberFromFragment(
  11131. null,
  11132. mode,
  11133. NoWork,
  11134. null
  11135. );
  11136. primaryChildFragment.return = workInProgress;
  11137. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11138. // Outside of blocking mode, we commit the effects from the
  11139. // partially completed, timed-out tree, too.
  11140. var progressedState = workInProgress.memoizedState;
  11141. var progressedPrimaryChild =
  11142. progressedState !== null
  11143. ? workInProgress.child.child
  11144. : workInProgress.child;
  11145. primaryChildFragment.child = progressedPrimaryChild;
  11146. var progressedChild = progressedPrimaryChild;
  11147. while (progressedChild !== null) {
  11148. progressedChild.return = primaryChildFragment;
  11149. progressedChild = progressedChild.sibling;
  11150. }
  11151. }
  11152. var fallbackChildFragment = createFiberFromFragment(
  11153. nextFallbackChildren,
  11154. mode,
  11155. renderExpirationTime,
  11156. null
  11157. );
  11158. fallbackChildFragment.return = workInProgress;
  11159. primaryChildFragment.sibling = fallbackChildFragment; // Skip the primary children, and continue working on the
  11160. // fallback children.
  11161. workInProgress.memoizedState = SUSPENDED_MARKER;
  11162. workInProgress.child = primaryChildFragment;
  11163. return fallbackChildFragment;
  11164. } else {
  11165. // Mount the primary children without an intermediate fragment fiber.
  11166. var nextPrimaryChildren = nextProps.children;
  11167. workInProgress.memoizedState = null;
  11168. return (workInProgress.child = mountChildFibers(
  11169. workInProgress,
  11170. null,
  11171. nextPrimaryChildren,
  11172. renderExpirationTime
  11173. ));
  11174. }
  11175. } else {
  11176. // This is an update. This branch is more complicated because we need to
  11177. // ensure the state of the primary children is preserved.
  11178. var prevState = current.memoizedState;
  11179. if (prevState !== null) {
  11180. // wrapped in a fragment fiber.
  11181. var currentPrimaryChildFragment = current.child;
  11182. var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
  11183. if (nextDidTimeout) {
  11184. // Still timed out. Reuse the current primary children by cloning
  11185. // its fragment. We're going to skip over these entirely.
  11186. var _nextFallbackChildren2 = nextProps.fallback;
  11187. var _primaryChildFragment2 = createWorkInProgress(
  11188. currentPrimaryChildFragment,
  11189. currentPrimaryChildFragment.pendingProps
  11190. );
  11191. _primaryChildFragment2.return = workInProgress;
  11192. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11193. // Outside of blocking mode, we commit the effects from the
  11194. // partially completed, timed-out tree, too.
  11195. var _progressedState = workInProgress.memoizedState;
  11196. var _progressedPrimaryChild =
  11197. _progressedState !== null
  11198. ? workInProgress.child.child
  11199. : workInProgress.child;
  11200. if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
  11201. _primaryChildFragment2.child = _progressedPrimaryChild;
  11202. var _progressedChild2 = _progressedPrimaryChild;
  11203. while (_progressedChild2 !== null) {
  11204. _progressedChild2.return = _primaryChildFragment2;
  11205. _progressedChild2 = _progressedChild2.sibling;
  11206. }
  11207. }
  11208. } // Because primaryChildFragment is a new fiber that we're inserting as the
  11209. // parent of a new tree, we need to set its treeBaseDuration.
  11210. if (workInProgress.mode & ProfileMode) {
  11211. // treeBaseDuration is the sum of all the child tree base durations.
  11212. var _treeBaseDuration = 0;
  11213. var _hiddenChild = _primaryChildFragment2.child;
  11214. while (_hiddenChild !== null) {
  11215. _treeBaseDuration += _hiddenChild.treeBaseDuration;
  11216. _hiddenChild = _hiddenChild.sibling;
  11217. }
  11218. _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
  11219. } // Clone the fallback child fragment, too. These we'll continue
  11220. // working on.
  11221. var _fallbackChildFragment2 = createWorkInProgress(
  11222. currentFallbackChildFragment,
  11223. _nextFallbackChildren2
  11224. );
  11225. _fallbackChildFragment2.return = workInProgress;
  11226. _primaryChildFragment2.sibling = _fallbackChildFragment2;
  11227. _primaryChildFragment2.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  11228. // fallback children.
  11229. workInProgress.memoizedState = SUSPENDED_MARKER;
  11230. workInProgress.child = _primaryChildFragment2;
  11231. return _fallbackChildFragment2;
  11232. } else {
  11233. // No longer suspended. Switch back to showing the primary children,
  11234. // and remove the intermediate fragment fiber.
  11235. var _nextPrimaryChildren = nextProps.children;
  11236. var currentPrimaryChild = currentPrimaryChildFragment.child;
  11237. var primaryChild = reconcileChildFibers(
  11238. workInProgress,
  11239. currentPrimaryChild,
  11240. _nextPrimaryChildren,
  11241. renderExpirationTime
  11242. ); // If this render doesn't suspend, we need to delete the fallback
  11243. // children. Wait until the complete phase, after we've confirmed the
  11244. // fallback is no longer needed.
  11245. // TODO: Would it be better to store the fallback fragment on
  11246. // the stateNode?
  11247. // Continue rendering the children, like we normally do.
  11248. workInProgress.memoizedState = null;
  11249. return (workInProgress.child = primaryChild);
  11250. }
  11251. } else {
  11252. // The current tree has not already timed out. That means the primary
  11253. // children are not wrapped in a fragment fiber.
  11254. var _currentPrimaryChild = current.child;
  11255. if (nextDidTimeout) {
  11256. // Timed out. Wrap the children in a fragment fiber to keep them
  11257. // separate from the fallback children.
  11258. var _nextFallbackChildren3 = nextProps.fallback;
  11259. var _primaryChildFragment3 = createFiberFromFragment(
  11260. // It shouldn't matter what the pending props are because we aren't
  11261. // going to render this fragment.
  11262. null,
  11263. mode,
  11264. NoWork,
  11265. null
  11266. );
  11267. _primaryChildFragment3.return = workInProgress;
  11268. _primaryChildFragment3.child = _currentPrimaryChild;
  11269. if (_currentPrimaryChild !== null) {
  11270. _currentPrimaryChild.return = _primaryChildFragment3;
  11271. } // Even though we're creating a new fiber, there are no new children,
  11272. // because we're reusing an already mounted tree. So we don't need to
  11273. // schedule a placement.
  11274. // primaryChildFragment.effectTag |= Placement;
  11275. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11276. // Outside of blocking mode, we commit the effects from the
  11277. // partially completed, timed-out tree, too.
  11278. var _progressedState2 = workInProgress.memoizedState;
  11279. var _progressedPrimaryChild2 =
  11280. _progressedState2 !== null
  11281. ? workInProgress.child.child
  11282. : workInProgress.child;
  11283. _primaryChildFragment3.child = _progressedPrimaryChild2;
  11284. var _progressedChild3 = _progressedPrimaryChild2;
  11285. while (_progressedChild3 !== null) {
  11286. _progressedChild3.return = _primaryChildFragment3;
  11287. _progressedChild3 = _progressedChild3.sibling;
  11288. }
  11289. } // Because primaryChildFragment is a new fiber that we're inserting as the
  11290. // parent of a new tree, we need to set its treeBaseDuration.
  11291. if (workInProgress.mode & ProfileMode) {
  11292. // treeBaseDuration is the sum of all the child tree base durations.
  11293. var _treeBaseDuration2 = 0;
  11294. var _hiddenChild2 = _primaryChildFragment3.child;
  11295. while (_hiddenChild2 !== null) {
  11296. _treeBaseDuration2 += _hiddenChild2.treeBaseDuration;
  11297. _hiddenChild2 = _hiddenChild2.sibling;
  11298. }
  11299. _primaryChildFragment3.treeBaseDuration = _treeBaseDuration2;
  11300. } // Create a fragment from the fallback children, too.
  11301. var _fallbackChildFragment3 = createFiberFromFragment(
  11302. _nextFallbackChildren3,
  11303. mode,
  11304. renderExpirationTime,
  11305. null
  11306. );
  11307. _fallbackChildFragment3.return = workInProgress;
  11308. _primaryChildFragment3.sibling = _fallbackChildFragment3;
  11309. _fallbackChildFragment3.effectTag |= Placement;
  11310. _primaryChildFragment3.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  11311. // fallback children.
  11312. workInProgress.memoizedState = SUSPENDED_MARKER;
  11313. workInProgress.child = _primaryChildFragment3;
  11314. return _fallbackChildFragment3;
  11315. } else {
  11316. // Still haven't timed out. Continue rendering the children, like we
  11317. // normally do.
  11318. workInProgress.memoizedState = null;
  11319. var _nextPrimaryChildren2 = nextProps.children;
  11320. return (workInProgress.child = reconcileChildFibers(
  11321. workInProgress,
  11322. _currentPrimaryChild,
  11323. _nextPrimaryChildren2,
  11324. renderExpirationTime
  11325. ));
  11326. }
  11327. }
  11328. }
  11329. }
  11330. function scheduleWorkOnFiber(fiber, renderExpirationTime) {
  11331. if (fiber.expirationTime < renderExpirationTime) {
  11332. fiber.expirationTime = renderExpirationTime;
  11333. }
  11334. var alternate = fiber.alternate;
  11335. if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
  11336. alternate.expirationTime = renderExpirationTime;
  11337. }
  11338. scheduleWorkOnParentPath(fiber.return, renderExpirationTime);
  11339. }
  11340. function propagateSuspenseContextChange(
  11341. workInProgress,
  11342. firstChild,
  11343. renderExpirationTime
  11344. ) {
  11345. // Mark any Suspense boundaries with fallbacks as having work to do.
  11346. // If they were previously forced into fallbacks, they may now be able
  11347. // to unblock.
  11348. var node = firstChild;
  11349. while (node !== null) {
  11350. if (node.tag === SuspenseComponent) {
  11351. var state = node.memoizedState;
  11352. if (state !== null) {
  11353. scheduleWorkOnFiber(node, renderExpirationTime);
  11354. }
  11355. } else if (node.tag === SuspenseListComponent) {
  11356. // If the tail is hidden there might not be an Suspense boundaries
  11357. // to schedule work on. In this case we have to schedule it on the
  11358. // list itself.
  11359. // We don't have to traverse to the children of the list since
  11360. // the list will propagate the change when it rerenders.
  11361. scheduleWorkOnFiber(node, renderExpirationTime);
  11362. } else if (node.child !== null) {
  11363. node.child.return = node;
  11364. node = node.child;
  11365. continue;
  11366. }
  11367. if (node === workInProgress) {
  11368. return;
  11369. }
  11370. while (node.sibling === null) {
  11371. if (node.return === null || node.return === workInProgress) {
  11372. return;
  11373. }
  11374. node = node.return;
  11375. }
  11376. node.sibling.return = node.return;
  11377. node = node.sibling;
  11378. }
  11379. }
  11380. function findLastContentRow(firstChild) {
  11381. // This is going to find the last row among these children that is already
  11382. // showing content on the screen, as opposed to being in fallback state or
  11383. // new. If a row has multiple Suspense boundaries, any of them being in the
  11384. // fallback state, counts as the whole row being in a fallback state.
  11385. // Note that the "rows" will be workInProgress, but any nested children
  11386. // will still be current since we haven't rendered them yet. The mounted
  11387. // order may not be the same as the new order. We use the new order.
  11388. var row = firstChild;
  11389. var lastContentRow = null;
  11390. while (row !== null) {
  11391. var currentRow = row.alternate; // New rows can't be content rows.
  11392. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  11393. lastContentRow = row;
  11394. }
  11395. row = row.sibling;
  11396. }
  11397. return lastContentRow;
  11398. }
  11399. function validateRevealOrder(revealOrder) {
  11400. {
  11401. if (
  11402. revealOrder !== undefined &&
  11403. revealOrder !== "forwards" &&
  11404. revealOrder !== "backwards" &&
  11405. revealOrder !== "together" &&
  11406. !didWarnAboutRevealOrder[revealOrder]
  11407. ) {
  11408. didWarnAboutRevealOrder[revealOrder] = true;
  11409. if (typeof revealOrder === "string") {
  11410. switch (revealOrder.toLowerCase()) {
  11411. case "together":
  11412. case "forwards":
  11413. case "backwards": {
  11414. error(
  11415. '"%s" is not a valid value for revealOrder on <SuspenseList />. ' +
  11416. 'Use lowercase "%s" instead.',
  11417. revealOrder,
  11418. revealOrder.toLowerCase()
  11419. );
  11420. break;
  11421. }
  11422. case "forward":
  11423. case "backward": {
  11424. error(
  11425. '"%s" is not a valid value for revealOrder on <SuspenseList />. ' +
  11426. 'React uses the -s suffix in the spelling. Use "%ss" instead.',
  11427. revealOrder,
  11428. revealOrder.toLowerCase()
  11429. );
  11430. break;
  11431. }
  11432. default:
  11433. error(
  11434. '"%s" is not a supported revealOrder on <SuspenseList />. ' +
  11435. 'Did you mean "together", "forwards" or "backwards"?',
  11436. revealOrder
  11437. );
  11438. break;
  11439. }
  11440. } else {
  11441. error(
  11442. "%s is not a supported value for revealOrder on <SuspenseList />. " +
  11443. 'Did you mean "together", "forwards" or "backwards"?',
  11444. revealOrder
  11445. );
  11446. }
  11447. }
  11448. }
  11449. }
  11450. function validateTailOptions(tailMode, revealOrder) {
  11451. {
  11452. if (tailMode !== undefined && !didWarnAboutTailOptions[tailMode]) {
  11453. if (tailMode !== "collapsed" && tailMode !== "hidden") {
  11454. didWarnAboutTailOptions[tailMode] = true;
  11455. error(
  11456. '"%s" is not a supported value for tail on <SuspenseList />. ' +
  11457. 'Did you mean "collapsed" or "hidden"?',
  11458. tailMode
  11459. );
  11460. } else if (revealOrder !== "forwards" && revealOrder !== "backwards") {
  11461. didWarnAboutTailOptions[tailMode] = true;
  11462. error(
  11463. '<SuspenseList tail="%s" /> is only valid if revealOrder is ' +
  11464. '"forwards" or "backwards". ' +
  11465. 'Did you mean to specify revealOrder="forwards"?',
  11466. tailMode
  11467. );
  11468. }
  11469. }
  11470. }
  11471. }
  11472. function validateSuspenseListNestedChild(childSlot, index) {
  11473. {
  11474. var isArray = Array.isArray(childSlot);
  11475. var isIterable = !isArray && typeof getIteratorFn(childSlot) === "function";
  11476. if (isArray || isIterable) {
  11477. var type = isArray ? "array" : "iterable";
  11478. error(
  11479. "A nested %s was passed to row #%s in <SuspenseList />. Wrap it in " +
  11480. "an additional SuspenseList to configure its revealOrder: " +
  11481. "<SuspenseList revealOrder=...> ... " +
  11482. "<SuspenseList revealOrder=...>{%s}</SuspenseList> ... " +
  11483. "</SuspenseList>",
  11484. type,
  11485. index,
  11486. type
  11487. );
  11488. return false;
  11489. }
  11490. }
  11491. return true;
  11492. }
  11493. function validateSuspenseListChildren(children, revealOrder) {
  11494. {
  11495. if (
  11496. (revealOrder === "forwards" || revealOrder === "backwards") &&
  11497. children !== undefined &&
  11498. children !== null &&
  11499. children !== false
  11500. ) {
  11501. if (Array.isArray(children)) {
  11502. for (var i = 0; i < children.length; i++) {
  11503. if (!validateSuspenseListNestedChild(children[i], i)) {
  11504. return;
  11505. }
  11506. }
  11507. } else {
  11508. var iteratorFn = getIteratorFn(children);
  11509. if (typeof iteratorFn === "function") {
  11510. var childrenIterator = iteratorFn.call(children);
  11511. if (childrenIterator) {
  11512. var step = childrenIterator.next();
  11513. var _i = 0;
  11514. for (; !step.done; step = childrenIterator.next()) {
  11515. if (!validateSuspenseListNestedChild(step.value, _i)) {
  11516. return;
  11517. }
  11518. _i++;
  11519. }
  11520. }
  11521. } else {
  11522. error(
  11523. 'A single row was passed to a <SuspenseList revealOrder="%s" />. ' +
  11524. "This is not useful since it needs multiple rows. " +
  11525. "Did you mean to pass multiple children or an array?",
  11526. revealOrder
  11527. );
  11528. }
  11529. }
  11530. }
  11531. }
  11532. }
  11533. function initSuspenseListRenderState(
  11534. workInProgress,
  11535. isBackwards,
  11536. tail,
  11537. lastContentRow,
  11538. tailMode,
  11539. lastEffectBeforeRendering
  11540. ) {
  11541. var renderState = workInProgress.memoizedState;
  11542. if (renderState === null) {
  11543. workInProgress.memoizedState = {
  11544. isBackwards: isBackwards,
  11545. rendering: null,
  11546. renderingStartTime: 0,
  11547. last: lastContentRow,
  11548. tail: tail,
  11549. tailExpiration: 0,
  11550. tailMode: tailMode,
  11551. lastEffect: lastEffectBeforeRendering
  11552. };
  11553. } else {
  11554. // We can reuse the existing object from previous renders.
  11555. renderState.isBackwards = isBackwards;
  11556. renderState.rendering = null;
  11557. renderState.renderingStartTime = 0;
  11558. renderState.last = lastContentRow;
  11559. renderState.tail = tail;
  11560. renderState.tailExpiration = 0;
  11561. renderState.tailMode = tailMode;
  11562. renderState.lastEffect = lastEffectBeforeRendering;
  11563. }
  11564. } // This can end up rendering this component multiple passes.
  11565. // The first pass splits the children fibers into two sets. A head and tail.
  11566. // We first render the head. If anything is in fallback state, we do another
  11567. // pass through beginWork to rerender all children (including the tail) with
  11568. // the force suspend context. If the first render didn't have anything in
  11569. // in fallback state. Then we render each row in the tail one-by-one.
  11570. // That happens in the completeWork phase without going back to beginWork.
  11571. function updateSuspenseListComponent(
  11572. current,
  11573. workInProgress,
  11574. renderExpirationTime
  11575. ) {
  11576. var nextProps = workInProgress.pendingProps;
  11577. var revealOrder = nextProps.revealOrder;
  11578. var tailMode = nextProps.tail;
  11579. var newChildren = nextProps.children;
  11580. validateRevealOrder(revealOrder);
  11581. validateTailOptions(tailMode, revealOrder);
  11582. validateSuspenseListChildren(newChildren, revealOrder);
  11583. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  11584. var suspenseContext = suspenseStackCursor.current;
  11585. var shouldForceFallback = hasSuspenseContext(
  11586. suspenseContext,
  11587. ForceSuspenseFallback
  11588. );
  11589. if (shouldForceFallback) {
  11590. suspenseContext = setShallowSuspenseContext(
  11591. suspenseContext,
  11592. ForceSuspenseFallback
  11593. );
  11594. workInProgress.effectTag |= DidCapture;
  11595. } else {
  11596. var didSuspendBefore =
  11597. current !== null && (current.effectTag & DidCapture) !== NoEffect;
  11598. if (didSuspendBefore) {
  11599. // If we previously forced a fallback, we need to schedule work
  11600. // on any nested boundaries to let them know to try to render
  11601. // again. This is the same as context updating.
  11602. propagateSuspenseContextChange(
  11603. workInProgress,
  11604. workInProgress.child,
  11605. renderExpirationTime
  11606. );
  11607. }
  11608. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  11609. }
  11610. pushSuspenseContext(workInProgress, suspenseContext);
  11611. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11612. // Outside of blocking mode, SuspenseList doesn't work so we just
  11613. // use make it a noop by treating it as the default revealOrder.
  11614. workInProgress.memoizedState = null;
  11615. } else {
  11616. switch (revealOrder) {
  11617. case "forwards": {
  11618. var lastContentRow = findLastContentRow(workInProgress.child);
  11619. var tail;
  11620. if (lastContentRow === null) {
  11621. // The whole list is part of the tail.
  11622. // TODO: We could fast path by just rendering the tail now.
  11623. tail = workInProgress.child;
  11624. workInProgress.child = null;
  11625. } else {
  11626. // Disconnect the tail rows after the content row.
  11627. // We're going to render them separately later.
  11628. tail = lastContentRow.sibling;
  11629. lastContentRow.sibling = null;
  11630. }
  11631. initSuspenseListRenderState(
  11632. workInProgress,
  11633. false, // isBackwards
  11634. tail,
  11635. lastContentRow,
  11636. tailMode,
  11637. workInProgress.lastEffect
  11638. );
  11639. break;
  11640. }
  11641. case "backwards": {
  11642. // We're going to find the first row that has existing content.
  11643. // At the same time we're going to reverse the list of everything
  11644. // we pass in the meantime. That's going to be our tail in reverse
  11645. // order.
  11646. var _tail = null;
  11647. var row = workInProgress.child;
  11648. workInProgress.child = null;
  11649. while (row !== null) {
  11650. var currentRow = row.alternate; // New rows can't be content rows.
  11651. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  11652. // This is the beginning of the main content.
  11653. workInProgress.child = row;
  11654. break;
  11655. }
  11656. var nextRow = row.sibling;
  11657. row.sibling = _tail;
  11658. _tail = row;
  11659. row = nextRow;
  11660. } // TODO: If workInProgress.child is null, we can continue on the tail immediately.
  11661. initSuspenseListRenderState(
  11662. workInProgress,
  11663. true, // isBackwards
  11664. _tail,
  11665. null, // last
  11666. tailMode,
  11667. workInProgress.lastEffect
  11668. );
  11669. break;
  11670. }
  11671. case "together": {
  11672. initSuspenseListRenderState(
  11673. workInProgress,
  11674. false, // isBackwards
  11675. null, // tail
  11676. null, // last
  11677. undefined,
  11678. workInProgress.lastEffect
  11679. );
  11680. break;
  11681. }
  11682. default: {
  11683. // The default reveal order is the same as not having
  11684. // a boundary.
  11685. workInProgress.memoizedState = null;
  11686. }
  11687. }
  11688. }
  11689. return workInProgress.child;
  11690. }
  11691. function updatePortalComponent(current, workInProgress, renderExpirationTime) {
  11692. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  11693. var nextChildren = workInProgress.pendingProps;
  11694. if (current === null) {
  11695. // Portals are special because we don't append the children during mount
  11696. // but at commit. Therefore we need to track insertions which the normal
  11697. // flow doesn't do during mount. This doesn't happen at the root because
  11698. // the root always starts with a "current" with a null child.
  11699. // TODO: Consider unifying this with how the root works.
  11700. workInProgress.child = reconcileChildFibers(
  11701. workInProgress,
  11702. null,
  11703. nextChildren,
  11704. renderExpirationTime
  11705. );
  11706. } else {
  11707. reconcileChildren(
  11708. current,
  11709. workInProgress,
  11710. nextChildren,
  11711. renderExpirationTime
  11712. );
  11713. }
  11714. return workInProgress.child;
  11715. }
  11716. function updateContextProvider(current, workInProgress, renderExpirationTime) {
  11717. var providerType = workInProgress.type;
  11718. var context = providerType._context;
  11719. var newProps = workInProgress.pendingProps;
  11720. var oldProps = workInProgress.memoizedProps;
  11721. var newValue = newProps.value;
  11722. {
  11723. var providerPropTypes = workInProgress.type.propTypes;
  11724. if (providerPropTypes) {
  11725. checkPropTypes(providerPropTypes, newProps, "prop", "Context.Provider");
  11726. }
  11727. }
  11728. pushProvider(workInProgress, newValue);
  11729. if (oldProps !== null) {
  11730. var oldValue = oldProps.value;
  11731. var changedBits = calculateChangedBits(context, newValue, oldValue);
  11732. if (changedBits === 0) {
  11733. // No change. Bailout early if children are the same.
  11734. if (oldProps.children === newProps.children && !hasContextChanged()) {
  11735. return bailoutOnAlreadyFinishedWork(
  11736. current,
  11737. workInProgress,
  11738. renderExpirationTime
  11739. );
  11740. }
  11741. } else {
  11742. // The context value changed. Search for matching consumers and schedule
  11743. // them to update.
  11744. propagateContextChange(
  11745. workInProgress,
  11746. context,
  11747. changedBits,
  11748. renderExpirationTime
  11749. );
  11750. }
  11751. }
  11752. var newChildren = newProps.children;
  11753. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  11754. return workInProgress.child;
  11755. }
  11756. var hasWarnedAboutUsingContextAsConsumer = false;
  11757. function updateContextConsumer(current, workInProgress, renderExpirationTime) {
  11758. var context = workInProgress.type; // The logic below for Context differs depending on PROD or DEV mode. In
  11759. // DEV mode, we create a separate object for Context.Consumer that acts
  11760. // like a proxy to Context. This proxy object adds unnecessary code in PROD
  11761. // so we use the old behaviour (Context.Consumer references Context) to
  11762. // reduce size and overhead. The separate object references context via
  11763. // a property called "_context", which also gives us the ability to check
  11764. // in DEV mode if this property exists or not and warn if it does not.
  11765. {
  11766. if (context._context === undefined) {
  11767. // This may be because it's a Context (rather than a Consumer).
  11768. // Or it may be because it's older React where they're the same thing.
  11769. // We only want to warn if we're sure it's a new React.
  11770. if (context !== context.Consumer) {
  11771. if (!hasWarnedAboutUsingContextAsConsumer) {
  11772. hasWarnedAboutUsingContextAsConsumer = true;
  11773. error(
  11774. "Rendering <Context> directly is not supported and will be removed in " +
  11775. "a future major release. Did you mean to render <Context.Consumer> instead?"
  11776. );
  11777. }
  11778. }
  11779. } else {
  11780. context = context._context;
  11781. }
  11782. }
  11783. var newProps = workInProgress.pendingProps;
  11784. var render = newProps.children;
  11785. {
  11786. if (typeof render !== "function") {
  11787. error(
  11788. "A context consumer was rendered with multiple children, or a child " +
  11789. "that isn't a function. A context consumer expects a single child " +
  11790. "that is a function. If you did pass a function, make sure there " +
  11791. "is no trailing or leading whitespace around it."
  11792. );
  11793. }
  11794. }
  11795. prepareToReadContext(workInProgress, renderExpirationTime);
  11796. var newValue = readContext(context, newProps.unstable_observedBits);
  11797. var newChildren;
  11798. {
  11799. ReactCurrentOwner$1.current = workInProgress;
  11800. setIsRendering(true);
  11801. newChildren = render(newValue);
  11802. setIsRendering(false);
  11803. } // React DevTools reads this flag.
  11804. workInProgress.effectTag |= PerformedWork;
  11805. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  11806. return workInProgress.child;
  11807. }
  11808. function markWorkInProgressReceivedUpdate() {
  11809. didReceiveUpdate = true;
  11810. }
  11811. function bailoutOnAlreadyFinishedWork(
  11812. current,
  11813. workInProgress,
  11814. renderExpirationTime
  11815. ) {
  11816. cancelWorkTimer(workInProgress);
  11817. if (current !== null) {
  11818. // Reuse previous dependencies
  11819. workInProgress.dependencies = current.dependencies;
  11820. }
  11821. {
  11822. // Don't update "base" render times for bailouts.
  11823. stopProfilerTimerIfRunning();
  11824. }
  11825. var updateExpirationTime = workInProgress.expirationTime;
  11826. if (updateExpirationTime !== NoWork) {
  11827. markUnprocessedUpdateTime(updateExpirationTime);
  11828. } // Check if the children have any pending work.
  11829. var childExpirationTime = workInProgress.childExpirationTime;
  11830. if (childExpirationTime < renderExpirationTime) {
  11831. // The children don't have any work either. We can skip them.
  11832. // TODO: Once we add back resuming, we should check if the children are
  11833. // a work-in-progress set. If so, we need to transfer their effects.
  11834. return null;
  11835. } else {
  11836. // This fiber doesn't have work, but its subtree does. Clone the child
  11837. // fibers and continue.
  11838. cloneChildFibers(current, workInProgress);
  11839. return workInProgress.child;
  11840. }
  11841. }
  11842. function remountFiber(current, oldWorkInProgress, newWorkInProgress) {
  11843. {
  11844. var returnFiber = oldWorkInProgress.return;
  11845. if (returnFiber === null) {
  11846. throw new Error("Cannot swap the root fiber.");
  11847. } // Disconnect from the old current.
  11848. // It will get deleted.
  11849. current.alternate = null;
  11850. oldWorkInProgress.alternate = null; // Connect to the new tree.
  11851. newWorkInProgress.index = oldWorkInProgress.index;
  11852. newWorkInProgress.sibling = oldWorkInProgress.sibling;
  11853. newWorkInProgress.return = oldWorkInProgress.return;
  11854. newWorkInProgress.ref = oldWorkInProgress.ref; // Replace the child/sibling pointers above it.
  11855. if (oldWorkInProgress === returnFiber.child) {
  11856. returnFiber.child = newWorkInProgress;
  11857. } else {
  11858. var prevSibling = returnFiber.child;
  11859. if (prevSibling === null) {
  11860. throw new Error("Expected parent to have a child.");
  11861. }
  11862. while (prevSibling.sibling !== oldWorkInProgress) {
  11863. prevSibling = prevSibling.sibling;
  11864. if (prevSibling === null) {
  11865. throw new Error("Expected to find the previous sibling.");
  11866. }
  11867. }
  11868. prevSibling.sibling = newWorkInProgress;
  11869. } // Delete the old fiber and place the new one.
  11870. // Since the old fiber is disconnected, we have to schedule it manually.
  11871. var last = returnFiber.lastEffect;
  11872. if (last !== null) {
  11873. last.nextEffect = current;
  11874. returnFiber.lastEffect = current;
  11875. } else {
  11876. returnFiber.firstEffect = returnFiber.lastEffect = current;
  11877. }
  11878. current.nextEffect = null;
  11879. current.effectTag = Deletion;
  11880. newWorkInProgress.effectTag |= Placement; // Restart work from the new fiber.
  11881. return newWorkInProgress;
  11882. }
  11883. }
  11884. function beginWork(current, workInProgress, renderExpirationTime) {
  11885. var updateExpirationTime = workInProgress.expirationTime;
  11886. {
  11887. if (workInProgress._debugNeedsRemount && current !== null) {
  11888. // This will restart the begin phase with a new fiber.
  11889. return remountFiber(
  11890. current,
  11891. workInProgress,
  11892. createFiberFromTypeAndProps(
  11893. workInProgress.type,
  11894. workInProgress.key,
  11895. workInProgress.pendingProps,
  11896. workInProgress._debugOwner || null,
  11897. workInProgress.mode,
  11898. workInProgress.expirationTime
  11899. )
  11900. );
  11901. }
  11902. }
  11903. if (current !== null) {
  11904. var oldProps = current.memoizedProps;
  11905. var newProps = workInProgress.pendingProps;
  11906. if (
  11907. oldProps !== newProps ||
  11908. hasContextChanged() || // Force a re-render if the implementation changed due to hot reload:
  11909. workInProgress.type !== current.type
  11910. ) {
  11911. // If props or context changed, mark the fiber as having performed work.
  11912. // This may be unset if the props are determined to be equal later (memo).
  11913. didReceiveUpdate = true;
  11914. } else if (updateExpirationTime < renderExpirationTime) {
  11915. didReceiveUpdate = false; // This fiber does not have any pending work. Bailout without entering
  11916. // the begin phase. There's still some bookkeeping we that needs to be done
  11917. // in this optimized path, mostly pushing stuff onto the stack.
  11918. switch (workInProgress.tag) {
  11919. case HostRoot:
  11920. pushHostRootContext(workInProgress);
  11921. break;
  11922. case HostComponent:
  11923. pushHostContext(workInProgress);
  11924. if (
  11925. workInProgress.mode & ConcurrentMode &&
  11926. renderExpirationTime !== Never &&
  11927. shouldDeprioritizeSubtree(workInProgress.type)
  11928. ) {
  11929. {
  11930. markSpawnedWork(Never);
  11931. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  11932. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  11933. return null;
  11934. }
  11935. break;
  11936. case ClassComponent: {
  11937. var Component = workInProgress.type;
  11938. if (isContextProvider(Component)) {
  11939. pushContextProvider(workInProgress);
  11940. }
  11941. break;
  11942. }
  11943. case HostPortal:
  11944. pushHostContainer(
  11945. workInProgress,
  11946. workInProgress.stateNode.containerInfo
  11947. );
  11948. break;
  11949. case ContextProvider: {
  11950. var newValue = workInProgress.memoizedProps.value;
  11951. pushProvider(workInProgress, newValue);
  11952. break;
  11953. }
  11954. case Profiler:
  11955. {
  11956. // Profiler should only call onRender when one of its descendants actually rendered.
  11957. var hasChildWork =
  11958. workInProgress.childExpirationTime >= renderExpirationTime;
  11959. if (hasChildWork) {
  11960. workInProgress.effectTag |= Update;
  11961. } // Reset effect durations for the next eventual effect phase.
  11962. // These are reset during render to allow the DevTools commit hook a chance to read them,
  11963. var stateNode = workInProgress.stateNode;
  11964. stateNode.effectDuration = 0;
  11965. stateNode.passiveEffectDuration = 0;
  11966. }
  11967. break;
  11968. case SuspenseComponent: {
  11969. var state = workInProgress.memoizedState;
  11970. if (state !== null) {
  11971. // whether to retry the primary children, or to skip over it and
  11972. // go straight to the fallback. Check the priority of the primary
  11973. // child fragment.
  11974. var primaryChildFragment = workInProgress.child;
  11975. var primaryChildExpirationTime =
  11976. primaryChildFragment.childExpirationTime;
  11977. if (
  11978. primaryChildExpirationTime !== NoWork &&
  11979. primaryChildExpirationTime >= renderExpirationTime
  11980. ) {
  11981. // The primary children have pending work. Use the normal path
  11982. // to attempt to render the primary children again.
  11983. return updateSuspenseComponent(
  11984. current,
  11985. workInProgress,
  11986. renderExpirationTime
  11987. );
  11988. } else {
  11989. pushSuspenseContext(
  11990. workInProgress,
  11991. setDefaultShallowSuspenseContext(suspenseStackCursor.current)
  11992. ); // The primary children do not have pending work with sufficient
  11993. // priority. Bailout.
  11994. var child = bailoutOnAlreadyFinishedWork(
  11995. current,
  11996. workInProgress,
  11997. renderExpirationTime
  11998. );
  11999. if (child !== null) {
  12000. // The fallback children have pending work. Skip over the
  12001. // primary children and work on the fallback.
  12002. return child.sibling;
  12003. } else {
  12004. return null;
  12005. }
  12006. }
  12007. } else {
  12008. pushSuspenseContext(
  12009. workInProgress,
  12010. setDefaultShallowSuspenseContext(suspenseStackCursor.current)
  12011. );
  12012. }
  12013. break;
  12014. }
  12015. case SuspenseListComponent: {
  12016. var didSuspendBefore = (current.effectTag & DidCapture) !== NoEffect;
  12017. var _hasChildWork =
  12018. workInProgress.childExpirationTime >= renderExpirationTime;
  12019. if (didSuspendBefore) {
  12020. if (_hasChildWork) {
  12021. // If something was in fallback state last time, and we have all the
  12022. // same children then we're still in progressive loading state.
  12023. // Something might get unblocked by state updates or retries in the
  12024. // tree which will affect the tail. So we need to use the normal
  12025. // path to compute the correct tail.
  12026. return updateSuspenseListComponent(
  12027. current,
  12028. workInProgress,
  12029. renderExpirationTime
  12030. );
  12031. } // If none of the children had any work, that means that none of
  12032. // them got retried so they'll still be blocked in the same way
  12033. // as before. We can fast bail out.
  12034. workInProgress.effectTag |= DidCapture;
  12035. } // If nothing suspended before and we're rendering the same children,
  12036. // then the tail doesn't matter. Anything new that suspends will work
  12037. // in the "together" mode, so we can continue from the state we had.
  12038. var renderState = workInProgress.memoizedState;
  12039. if (renderState !== null) {
  12040. // Reset to the "together" mode in case we've started a different
  12041. // update in the past but didn't complete it.
  12042. renderState.rendering = null;
  12043. renderState.tail = null;
  12044. }
  12045. pushSuspenseContext(workInProgress, suspenseStackCursor.current);
  12046. if (_hasChildWork) {
  12047. break;
  12048. } else {
  12049. // If none of the children had any work, that means that none of
  12050. // them got retried so they'll still be blocked in the same way
  12051. // as before. We can fast bail out.
  12052. return null;
  12053. }
  12054. }
  12055. }
  12056. return bailoutOnAlreadyFinishedWork(
  12057. current,
  12058. workInProgress,
  12059. renderExpirationTime
  12060. );
  12061. } else {
  12062. // An update was scheduled on this fiber, but there are no new props
  12063. // nor legacy context. Set this to false. If an update queue or context
  12064. // consumer produces a changed value, it will set this to true. Otherwise,
  12065. // the component will assume the children have not changed and bail out.
  12066. didReceiveUpdate = false;
  12067. }
  12068. } else {
  12069. didReceiveUpdate = false;
  12070. } // Before entering the begin phase, clear pending update priority.
  12071. // TODO: This assumes that we're about to evaluate the component and process
  12072. // the update queue. However, there's an exception: SimpleMemoComponent
  12073. // sometimes bails out later in the begin phase. This indicates that we should
  12074. // move this assignment out of the common path and into each branch.
  12075. workInProgress.expirationTime = NoWork;
  12076. switch (workInProgress.tag) {
  12077. case IndeterminateComponent: {
  12078. return mountIndeterminateComponent(
  12079. current,
  12080. workInProgress,
  12081. workInProgress.type,
  12082. renderExpirationTime
  12083. );
  12084. }
  12085. case LazyComponent: {
  12086. var elementType = workInProgress.elementType;
  12087. return mountLazyComponent(
  12088. current,
  12089. workInProgress,
  12090. elementType,
  12091. updateExpirationTime,
  12092. renderExpirationTime
  12093. );
  12094. }
  12095. case FunctionComponent: {
  12096. var _Component = workInProgress.type;
  12097. var unresolvedProps = workInProgress.pendingProps;
  12098. var resolvedProps =
  12099. workInProgress.elementType === _Component
  12100. ? unresolvedProps
  12101. : resolveDefaultProps(_Component, unresolvedProps);
  12102. return updateFunctionComponent(
  12103. current,
  12104. workInProgress,
  12105. _Component,
  12106. resolvedProps,
  12107. renderExpirationTime
  12108. );
  12109. }
  12110. case ClassComponent: {
  12111. var _Component2 = workInProgress.type;
  12112. var _unresolvedProps = workInProgress.pendingProps;
  12113. var _resolvedProps =
  12114. workInProgress.elementType === _Component2
  12115. ? _unresolvedProps
  12116. : resolveDefaultProps(_Component2, _unresolvedProps);
  12117. return updateClassComponent(
  12118. current,
  12119. workInProgress,
  12120. _Component2,
  12121. _resolvedProps,
  12122. renderExpirationTime
  12123. );
  12124. }
  12125. case HostRoot:
  12126. return updateHostRoot(current, workInProgress, renderExpirationTime);
  12127. case HostComponent:
  12128. return updateHostComponent(current, workInProgress, renderExpirationTime);
  12129. case HostText:
  12130. return updateHostText();
  12131. case SuspenseComponent:
  12132. return updateSuspenseComponent(
  12133. current,
  12134. workInProgress,
  12135. renderExpirationTime
  12136. );
  12137. case HostPortal:
  12138. return updatePortalComponent(
  12139. current,
  12140. workInProgress,
  12141. renderExpirationTime
  12142. );
  12143. case ForwardRef: {
  12144. var type = workInProgress.type;
  12145. var _unresolvedProps2 = workInProgress.pendingProps;
  12146. var _resolvedProps2 =
  12147. workInProgress.elementType === type
  12148. ? _unresolvedProps2
  12149. : resolveDefaultProps(type, _unresolvedProps2);
  12150. return updateForwardRef(
  12151. current,
  12152. workInProgress,
  12153. type,
  12154. _resolvedProps2,
  12155. renderExpirationTime
  12156. );
  12157. }
  12158. case Fragment:
  12159. return updateFragment(current, workInProgress, renderExpirationTime);
  12160. case Mode:
  12161. return updateMode(current, workInProgress, renderExpirationTime);
  12162. case Profiler:
  12163. return updateProfiler(current, workInProgress, renderExpirationTime);
  12164. case ContextProvider:
  12165. return updateContextProvider(
  12166. current,
  12167. workInProgress,
  12168. renderExpirationTime
  12169. );
  12170. case ContextConsumer:
  12171. return updateContextConsumer(
  12172. current,
  12173. workInProgress,
  12174. renderExpirationTime
  12175. );
  12176. case MemoComponent: {
  12177. var _type2 = workInProgress.type;
  12178. var _unresolvedProps3 = workInProgress.pendingProps; // Resolve outer props first, then resolve inner props.
  12179. var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
  12180. {
  12181. if (workInProgress.type !== workInProgress.elementType) {
  12182. var outerPropTypes = _type2.propTypes;
  12183. if (outerPropTypes) {
  12184. checkPropTypes(
  12185. outerPropTypes,
  12186. _resolvedProps3, // Resolved for outer only
  12187. "prop",
  12188. getComponentName(_type2)
  12189. );
  12190. }
  12191. }
  12192. }
  12193. _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
  12194. return updateMemoComponent(
  12195. current,
  12196. workInProgress,
  12197. _type2,
  12198. _resolvedProps3,
  12199. updateExpirationTime,
  12200. renderExpirationTime
  12201. );
  12202. }
  12203. case SimpleMemoComponent: {
  12204. return updateSimpleMemoComponent(
  12205. current,
  12206. workInProgress,
  12207. workInProgress.type,
  12208. workInProgress.pendingProps,
  12209. updateExpirationTime,
  12210. renderExpirationTime
  12211. );
  12212. }
  12213. case IncompleteClassComponent: {
  12214. var _Component3 = workInProgress.type;
  12215. var _unresolvedProps4 = workInProgress.pendingProps;
  12216. var _resolvedProps4 =
  12217. workInProgress.elementType === _Component3
  12218. ? _unresolvedProps4
  12219. : resolveDefaultProps(_Component3, _unresolvedProps4);
  12220. return mountIncompleteClassComponent(
  12221. current,
  12222. workInProgress,
  12223. _Component3,
  12224. _resolvedProps4,
  12225. renderExpirationTime
  12226. );
  12227. }
  12228. case SuspenseListComponent: {
  12229. return updateSuspenseListComponent(
  12230. current,
  12231. workInProgress,
  12232. renderExpirationTime
  12233. );
  12234. }
  12235. }
  12236. {
  12237. throw Error(
  12238. "Unknown unit of work tag (" +
  12239. workInProgress.tag +
  12240. "). This error is likely caused by a bug in React. Please file an issue."
  12241. );
  12242. }
  12243. }
  12244. function markUpdate(workInProgress) {
  12245. // Tag the fiber with an update effect. This turns a Placement into
  12246. // a PlacementAndUpdate.
  12247. workInProgress.effectTag |= Update;
  12248. }
  12249. function markRef$1(workInProgress) {
  12250. workInProgress.effectTag |= Ref;
  12251. }
  12252. var appendAllChildren;
  12253. var updateHostContainer;
  12254. var updateHostComponent$1;
  12255. var updateHostText$1;
  12256. {
  12257. // Persistent host tree mode
  12258. appendAllChildren = function(
  12259. parent,
  12260. workInProgress,
  12261. needsVisibilityToggle,
  12262. isHidden
  12263. ) {
  12264. // We only have the top Fiber that was created but we need recurse down its
  12265. // children to find all the terminal nodes.
  12266. var node = workInProgress.child;
  12267. while (node !== null) {
  12268. // eslint-disable-next-line no-labels
  12269. if (node.tag === HostComponent) {
  12270. var instance = node.stateNode;
  12271. if (needsVisibilityToggle && isHidden) {
  12272. // This child is inside a timed out tree. Hide it.
  12273. var props = node.memoizedProps;
  12274. var type = node.type;
  12275. instance = cloneHiddenInstance(instance);
  12276. }
  12277. appendInitialChild(parent, instance);
  12278. } else if (node.tag === HostText) {
  12279. var _instance = node.stateNode;
  12280. if (needsVisibilityToggle && isHidden) {
  12281. // This child is inside a timed out tree. Hide it.
  12282. var text = node.memoizedProps;
  12283. _instance = cloneHiddenTextInstance();
  12284. }
  12285. appendInitialChild(parent, _instance);
  12286. } else if (node.tag === HostPortal);
  12287. else if (node.tag === SuspenseComponent) {
  12288. if ((node.effectTag & Update) !== NoEffect) {
  12289. // Need to toggle the visibility of the primary children.
  12290. var newIsHidden = node.memoizedState !== null;
  12291. if (newIsHidden) {
  12292. var primaryChildParent = node.child;
  12293. if (primaryChildParent !== null) {
  12294. if (primaryChildParent.child !== null) {
  12295. primaryChildParent.child.return = primaryChildParent;
  12296. appendAllChildren(
  12297. parent,
  12298. primaryChildParent,
  12299. true,
  12300. newIsHidden
  12301. );
  12302. }
  12303. var fallbackChildParent = primaryChildParent.sibling;
  12304. if (fallbackChildParent !== null) {
  12305. fallbackChildParent.return = node;
  12306. node = fallbackChildParent;
  12307. continue;
  12308. }
  12309. }
  12310. }
  12311. }
  12312. if (node.child !== null) {
  12313. // Continue traversing like normal
  12314. node.child.return = node;
  12315. node = node.child;
  12316. continue;
  12317. }
  12318. } else if (node.child !== null) {
  12319. node.child.return = node;
  12320. node = node.child;
  12321. continue;
  12322. } // $FlowFixMe This is correct but Flow is confused by the labeled break.
  12323. node = node;
  12324. if (node === workInProgress) {
  12325. return;
  12326. }
  12327. while (node.sibling === null) {
  12328. if (node.return === null || node.return === workInProgress) {
  12329. return;
  12330. }
  12331. node = node.return;
  12332. }
  12333. node.sibling.return = node.return;
  12334. node = node.sibling;
  12335. }
  12336. }; // An unfortunate fork of appendAllChildren because we have two different parent types.
  12337. var appendAllChildrenToContainer = function(
  12338. containerChildSet,
  12339. workInProgress,
  12340. needsVisibilityToggle,
  12341. isHidden
  12342. ) {
  12343. // We only have the top Fiber that was created but we need recurse down its
  12344. // children to find all the terminal nodes.
  12345. var node = workInProgress.child;
  12346. while (node !== null) {
  12347. // eslint-disable-next-line no-labels
  12348. if (node.tag === HostComponent) {
  12349. var instance = node.stateNode;
  12350. if (needsVisibilityToggle && isHidden) {
  12351. // This child is inside a timed out tree. Hide it.
  12352. var props = node.memoizedProps;
  12353. var type = node.type;
  12354. instance = cloneHiddenInstance(instance);
  12355. }
  12356. appendChildToContainerChildSet(containerChildSet, instance);
  12357. } else if (node.tag === HostText) {
  12358. var _instance3 = node.stateNode;
  12359. if (needsVisibilityToggle && isHidden) {
  12360. // This child is inside a timed out tree. Hide it.
  12361. var text = node.memoizedProps;
  12362. _instance3 = cloneHiddenTextInstance();
  12363. }
  12364. appendChildToContainerChildSet(containerChildSet, _instance3);
  12365. } else if (node.tag === HostPortal);
  12366. else if (node.tag === SuspenseComponent) {
  12367. if ((node.effectTag & Update) !== NoEffect) {
  12368. // Need to toggle the visibility of the primary children.
  12369. var newIsHidden = node.memoizedState !== null;
  12370. if (newIsHidden) {
  12371. var primaryChildParent = node.child;
  12372. if (primaryChildParent !== null) {
  12373. if (primaryChildParent.child !== null) {
  12374. primaryChildParent.child.return = primaryChildParent;
  12375. appendAllChildrenToContainer(
  12376. containerChildSet,
  12377. primaryChildParent,
  12378. true,
  12379. newIsHidden
  12380. );
  12381. }
  12382. var fallbackChildParent = primaryChildParent.sibling;
  12383. if (fallbackChildParent !== null) {
  12384. fallbackChildParent.return = node;
  12385. node = fallbackChildParent;
  12386. continue;
  12387. }
  12388. }
  12389. }
  12390. }
  12391. if (node.child !== null) {
  12392. // Continue traversing like normal
  12393. node.child.return = node;
  12394. node = node.child;
  12395. continue;
  12396. }
  12397. } else if (node.child !== null) {
  12398. node.child.return = node;
  12399. node = node.child;
  12400. continue;
  12401. } // $FlowFixMe This is correct but Flow is confused by the labeled break.
  12402. node = node;
  12403. if (node === workInProgress) {
  12404. return;
  12405. }
  12406. while (node.sibling === null) {
  12407. if (node.return === null || node.return === workInProgress) {
  12408. return;
  12409. }
  12410. node = node.return;
  12411. }
  12412. node.sibling.return = node.return;
  12413. node = node.sibling;
  12414. }
  12415. };
  12416. updateHostContainer = function(workInProgress) {
  12417. var portalOrRoot = workInProgress.stateNode;
  12418. var childrenUnchanged = workInProgress.firstEffect === null;
  12419. if (childrenUnchanged);
  12420. else {
  12421. var container = portalOrRoot.containerInfo;
  12422. var newChildSet = createContainerChildSet(container); // If children might have changed, we have to add them all to the set.
  12423. appendAllChildrenToContainer(newChildSet, workInProgress, false, false);
  12424. portalOrRoot.pendingChildren = newChildSet; // Schedule an update on the container to swap out the container.
  12425. markUpdate(workInProgress);
  12426. finalizeContainerChildren(container, newChildSet);
  12427. }
  12428. };
  12429. updateHostComponent$1 = function(
  12430. current,
  12431. workInProgress,
  12432. type,
  12433. newProps,
  12434. rootContainerInstance
  12435. ) {
  12436. var currentInstance = current.stateNode;
  12437. var oldProps = current.memoizedProps; // If there are no effects associated with this node, then none of our children had any updates.
  12438. // This guarantees that we can reuse all of them.
  12439. var childrenUnchanged = workInProgress.firstEffect === null;
  12440. if (childrenUnchanged && oldProps === newProps) {
  12441. // No changes, just reuse the existing instance.
  12442. // Note that this might release a previous clone.
  12443. workInProgress.stateNode = currentInstance;
  12444. return;
  12445. }
  12446. var recyclableInstance = workInProgress.stateNode;
  12447. var currentHostContext = getHostContext();
  12448. var updatePayload = null;
  12449. if (oldProps !== newProps) {
  12450. updatePayload = prepareUpdate(
  12451. recyclableInstance,
  12452. type,
  12453. oldProps,
  12454. newProps
  12455. );
  12456. }
  12457. if (childrenUnchanged && updatePayload === null) {
  12458. // No changes, just reuse the existing instance.
  12459. // Note that this might release a previous clone.
  12460. workInProgress.stateNode = currentInstance;
  12461. return;
  12462. }
  12463. var newInstance = cloneInstance(
  12464. currentInstance,
  12465. updatePayload,
  12466. type,
  12467. oldProps,
  12468. newProps,
  12469. workInProgress,
  12470. childrenUnchanged
  12471. );
  12472. workInProgress.stateNode = newInstance;
  12473. if (childrenUnchanged) {
  12474. // If there are no other effects in this tree, we need to flag this node as having one.
  12475. // Even though we're not going to use it for anything.
  12476. // Otherwise parents won't know that there are new children to propagate upwards.
  12477. markUpdate(workInProgress);
  12478. } else {
  12479. // If children might have changed, we have to add them all to the set.
  12480. appendAllChildren(newInstance, workInProgress, false, false);
  12481. }
  12482. };
  12483. updateHostText$1 = function(current, workInProgress, oldText, newText) {
  12484. if (oldText !== newText) {
  12485. // If the text content differs, we'll create a new text instance for it.
  12486. var rootContainerInstance = getRootHostContainer();
  12487. var currentHostContext = getHostContext();
  12488. workInProgress.stateNode = createTextInstance(
  12489. newText,
  12490. rootContainerInstance,
  12491. currentHostContext,
  12492. workInProgress
  12493. ); // We'll have to mark it as having an effect, even though we won't use the effect for anything.
  12494. // This lets the parents know that at least one of their children has changed.
  12495. markUpdate(workInProgress);
  12496. } else {
  12497. workInProgress.stateNode = current.stateNode;
  12498. }
  12499. };
  12500. }
  12501. function cutOffTailIfNeeded(renderState, hasRenderedATailFallback) {
  12502. switch (renderState.tailMode) {
  12503. case "hidden": {
  12504. // Any insertions at the end of the tail list after this point
  12505. // should be invisible. If there are already mounted boundaries
  12506. // anything before them are not considered for collapsing.
  12507. // Therefore we need to go through the whole tail to find if
  12508. // there are any.
  12509. var tailNode = renderState.tail;
  12510. var lastTailNode = null;
  12511. while (tailNode !== null) {
  12512. if (tailNode.alternate !== null) {
  12513. lastTailNode = tailNode;
  12514. }
  12515. tailNode = tailNode.sibling;
  12516. } // Next we're simply going to delete all insertions after the
  12517. // last rendered item.
  12518. if (lastTailNode === null) {
  12519. // All remaining items in the tail are insertions.
  12520. renderState.tail = null;
  12521. } else {
  12522. // Detach the insertion after the last node that was already
  12523. // inserted.
  12524. lastTailNode.sibling = null;
  12525. }
  12526. break;
  12527. }
  12528. case "collapsed": {
  12529. // Any insertions at the end of the tail list after this point
  12530. // should be invisible. If there are already mounted boundaries
  12531. // anything before them are not considered for collapsing.
  12532. // Therefore we need to go through the whole tail to find if
  12533. // there are any.
  12534. var _tailNode = renderState.tail;
  12535. var _lastTailNode = null;
  12536. while (_tailNode !== null) {
  12537. if (_tailNode.alternate !== null) {
  12538. _lastTailNode = _tailNode;
  12539. }
  12540. _tailNode = _tailNode.sibling;
  12541. } // Next we're simply going to delete all insertions after the
  12542. // last rendered item.
  12543. if (_lastTailNode === null) {
  12544. // All remaining items in the tail are insertions.
  12545. if (!hasRenderedATailFallback && renderState.tail !== null) {
  12546. // We suspended during the head. We want to show at least one
  12547. // row at the tail. So we'll keep on and cut off the rest.
  12548. renderState.tail.sibling = null;
  12549. } else {
  12550. renderState.tail = null;
  12551. }
  12552. } else {
  12553. // Detach the insertion after the last node that was already
  12554. // inserted.
  12555. _lastTailNode.sibling = null;
  12556. }
  12557. break;
  12558. }
  12559. }
  12560. }
  12561. function completeWork(current, workInProgress, renderExpirationTime) {
  12562. var newProps = workInProgress.pendingProps;
  12563. switch (workInProgress.tag) {
  12564. case IndeterminateComponent:
  12565. case LazyComponent:
  12566. case SimpleMemoComponent:
  12567. case FunctionComponent:
  12568. case ForwardRef:
  12569. case Fragment:
  12570. case Mode:
  12571. case Profiler:
  12572. case ContextConsumer:
  12573. case MemoComponent:
  12574. return null;
  12575. case ClassComponent: {
  12576. var Component = workInProgress.type;
  12577. if (isContextProvider(Component)) {
  12578. popContext(workInProgress);
  12579. }
  12580. return null;
  12581. }
  12582. case HostRoot: {
  12583. popHostContainer(workInProgress);
  12584. popTopLevelContextObject(workInProgress);
  12585. var fiberRoot = workInProgress.stateNode;
  12586. if (fiberRoot.pendingContext) {
  12587. fiberRoot.context = fiberRoot.pendingContext;
  12588. fiberRoot.pendingContext = null;
  12589. }
  12590. if (current === null || current.child === null) {
  12591. // If we hydrated, pop so that we can delete any remaining children
  12592. // that weren't hydrated.
  12593. var wasHydrated = popHydrationState();
  12594. if (wasHydrated) {
  12595. // If we hydrated, then we'll need to schedule an update for
  12596. // the commit side-effects on the root.
  12597. markUpdate(workInProgress);
  12598. }
  12599. }
  12600. updateHostContainer(workInProgress);
  12601. return null;
  12602. }
  12603. case HostComponent: {
  12604. popHostContext(workInProgress);
  12605. var rootContainerInstance = getRootHostContainer();
  12606. var type = workInProgress.type;
  12607. if (current !== null && workInProgress.stateNode != null) {
  12608. updateHostComponent$1(
  12609. current,
  12610. workInProgress,
  12611. type,
  12612. newProps,
  12613. rootContainerInstance
  12614. );
  12615. if (current.ref !== workInProgress.ref) {
  12616. markRef$1(workInProgress);
  12617. }
  12618. } else {
  12619. if (!newProps) {
  12620. if (!(workInProgress.stateNode !== null)) {
  12621. throw Error(
  12622. "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue."
  12623. );
  12624. } // This can happen when we abort work.
  12625. return null;
  12626. }
  12627. var currentHostContext = getHostContext(); // TODO: Move createInstance to beginWork and keep it on a context
  12628. // "stack" as the parent. Then append children as we go in beginWork
  12629. // or completeWork depending on whether we want to add them top->down or
  12630. // bottom->up. Top->down is faster in IE11.
  12631. var _wasHydrated = popHydrationState();
  12632. if (_wasHydrated) {
  12633. // TODO: Move this and createInstance step into the beginPhase
  12634. // to consolidate.
  12635. if (prepareToHydrateHostInstance()) {
  12636. // If changes to the hydrated node need to be applied at the
  12637. // commit-phase we mark this as such.
  12638. markUpdate(workInProgress);
  12639. }
  12640. } else {
  12641. var instance = createInstance(
  12642. type,
  12643. newProps,
  12644. rootContainerInstance,
  12645. currentHostContext,
  12646. workInProgress
  12647. );
  12648. appendAllChildren(instance, workInProgress, false, false); // This needs to be set before we mount Flare event listeners
  12649. workInProgress.stateNode = instance;
  12650. }
  12651. if (workInProgress.ref !== null) {
  12652. // If there is a ref on a host node we need to schedule a callback
  12653. markRef$1(workInProgress);
  12654. }
  12655. }
  12656. return null;
  12657. }
  12658. case HostText: {
  12659. var newText = newProps;
  12660. if (current && workInProgress.stateNode != null) {
  12661. var oldText = current.memoizedProps; // If we have an alternate, that means this is an update and we need
  12662. // to schedule a side-effect to do the updates.
  12663. updateHostText$1(current, workInProgress, oldText, newText);
  12664. } else {
  12665. if (typeof newText !== "string") {
  12666. if (!(workInProgress.stateNode !== null)) {
  12667. throw Error(
  12668. "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue."
  12669. );
  12670. } // This can happen when we abort work.
  12671. }
  12672. var _rootContainerInstance = getRootHostContainer();
  12673. var _currentHostContext = getHostContext();
  12674. var _wasHydrated2 = popHydrationState();
  12675. if (_wasHydrated2) {
  12676. if (prepareToHydrateHostTextInstance()) {
  12677. markUpdate(workInProgress);
  12678. }
  12679. } else {
  12680. workInProgress.stateNode = createTextInstance(
  12681. newText,
  12682. _rootContainerInstance,
  12683. _currentHostContext,
  12684. workInProgress
  12685. );
  12686. }
  12687. }
  12688. return null;
  12689. }
  12690. case SuspenseComponent: {
  12691. popSuspenseContext(workInProgress);
  12692. var nextState = workInProgress.memoizedState;
  12693. if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
  12694. // Something suspended. Re-render with the fallback children.
  12695. workInProgress.expirationTime = renderExpirationTime; // Do not reset the effect list.
  12696. return workInProgress;
  12697. }
  12698. var nextDidTimeout = nextState !== null;
  12699. var prevDidTimeout = false;
  12700. if (current === null) {
  12701. if (workInProgress.memoizedProps.fallback !== undefined);
  12702. } else {
  12703. var prevState = current.memoizedState;
  12704. prevDidTimeout = prevState !== null;
  12705. if (!nextDidTimeout && prevState !== null) {
  12706. // We just switched from the fallback to the normal children.
  12707. // Delete the fallback.
  12708. // TODO: Would it be better to store the fallback fragment on
  12709. // the stateNode during the begin phase?
  12710. var currentFallbackChild = current.child.sibling;
  12711. if (currentFallbackChild !== null) {
  12712. // Deletions go at the beginning of the return fiber's effect list
  12713. var first = workInProgress.firstEffect;
  12714. if (first !== null) {
  12715. workInProgress.firstEffect = currentFallbackChild;
  12716. currentFallbackChild.nextEffect = first;
  12717. } else {
  12718. workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
  12719. currentFallbackChild.nextEffect = null;
  12720. }
  12721. currentFallbackChild.effectTag = Deletion;
  12722. }
  12723. }
  12724. }
  12725. if (nextDidTimeout && !prevDidTimeout) {
  12726. // If this subtreee is running in blocking mode we can suspend,
  12727. // otherwise we won't suspend.
  12728. // TODO: This will still suspend a synchronous tree if anything
  12729. // in the concurrent tree already suspended during this render.
  12730. // This is a known bug.
  12731. if ((workInProgress.mode & BlockingMode) !== NoMode) {
  12732. // TODO: Move this back to throwException because this is too late
  12733. // if this is a large tree which is common for initial loads. We
  12734. // don't know if we should restart a render or not until we get
  12735. // this marker, and this is too late.
  12736. // If this render already had a ping or lower pri updates,
  12737. // and this is the first time we know we're going to suspend we
  12738. // should be able to immediately restart from within throwException.
  12739. var hasInvisibleChildContext =
  12740. current === null &&
  12741. workInProgress.memoizedProps.unstable_avoidThisFallback !== true;
  12742. if (
  12743. hasInvisibleChildContext ||
  12744. hasSuspenseContext(
  12745. suspenseStackCursor.current,
  12746. InvisibleParentSuspenseContext
  12747. )
  12748. ) {
  12749. // If this was in an invisible tree or a new render, then showing
  12750. // this boundary is ok.
  12751. renderDidSuspend();
  12752. } else {
  12753. // Otherwise, we're going to have to hide content so we should
  12754. // suspend for longer if possible.
  12755. renderDidSuspendDelayIfPossible();
  12756. }
  12757. }
  12758. }
  12759. {
  12760. // TODO: Only schedule updates if not prevDidTimeout.
  12761. if (nextDidTimeout) {
  12762. // If this boundary just timed out, schedule an effect to attach a
  12763. // retry listener to the promise. This flag is also used to hide the
  12764. // primary children.
  12765. workInProgress.effectTag |= Update;
  12766. }
  12767. }
  12768. return null;
  12769. }
  12770. case HostPortal:
  12771. popHostContainer(workInProgress);
  12772. updateHostContainer(workInProgress);
  12773. return null;
  12774. case ContextProvider:
  12775. // Pop provider fiber
  12776. popProvider(workInProgress);
  12777. return null;
  12778. case IncompleteClassComponent: {
  12779. // Same as class component case. I put it down here so that the tags are
  12780. // sequential to ensure this switch is compiled to a jump table.
  12781. var _Component = workInProgress.type;
  12782. if (isContextProvider(_Component)) {
  12783. popContext(workInProgress);
  12784. }
  12785. return null;
  12786. }
  12787. case SuspenseListComponent: {
  12788. popSuspenseContext(workInProgress);
  12789. var renderState = workInProgress.memoizedState;
  12790. if (renderState === null) {
  12791. // We're running in the default, "independent" mode.
  12792. // We don't do anything in this mode.
  12793. return null;
  12794. }
  12795. var didSuspendAlready =
  12796. (workInProgress.effectTag & DidCapture) !== NoEffect;
  12797. var renderedTail = renderState.rendering;
  12798. if (renderedTail === null) {
  12799. // We just rendered the head.
  12800. if (!didSuspendAlready) {
  12801. // This is the first pass. We need to figure out if anything is still
  12802. // suspended in the rendered set.
  12803. // If new content unsuspended, but there's still some content that
  12804. // didn't. Then we need to do a second pass that forces everything
  12805. // to keep showing their fallbacks.
  12806. // We might be suspended if something in this render pass suspended, or
  12807. // something in the previous committed pass suspended. Otherwise,
  12808. // there's no chance so we can skip the expensive call to
  12809. // findFirstSuspended.
  12810. var cannotBeSuspended =
  12811. renderHasNotSuspendedYet() &&
  12812. (current === null || (current.effectTag & DidCapture) === NoEffect);
  12813. if (!cannotBeSuspended) {
  12814. var row = workInProgress.child;
  12815. while (row !== null) {
  12816. var suspended = findFirstSuspended(row);
  12817. if (suspended !== null) {
  12818. didSuspendAlready = true;
  12819. workInProgress.effectTag |= DidCapture;
  12820. cutOffTailIfNeeded(renderState, false); // If this is a newly suspended tree, it might not get committed as
  12821. // part of the second pass. In that case nothing will subscribe to
  12822. // its thennables. Instead, we'll transfer its thennables to the
  12823. // SuspenseList so that it can retry if they resolve.
  12824. // There might be multiple of these in the list but since we're
  12825. // going to wait for all of them anyway, it doesn't really matter
  12826. // which ones gets to ping. In theory we could get clever and keep
  12827. // track of how many dependencies remain but it gets tricky because
  12828. // in the meantime, we can add/remove/change items and dependencies.
  12829. // We might bail out of the loop before finding any but that
  12830. // doesn't matter since that means that the other boundaries that
  12831. // we did find already has their listeners attached.
  12832. var newThennables = suspended.updateQueue;
  12833. if (newThennables !== null) {
  12834. workInProgress.updateQueue = newThennables;
  12835. workInProgress.effectTag |= Update;
  12836. } // Rerender the whole list, but this time, we'll force fallbacks
  12837. // to stay in place.
  12838. // Reset the effect list before doing the second pass since that's now invalid.
  12839. if (renderState.lastEffect === null) {
  12840. workInProgress.firstEffect = null;
  12841. }
  12842. workInProgress.lastEffect = renderState.lastEffect; // Reset the child fibers to their original state.
  12843. resetChildFibers(workInProgress, renderExpirationTime); // Set up the Suspense Context to force suspense and immediately
  12844. // rerender the children.
  12845. pushSuspenseContext(
  12846. workInProgress,
  12847. setShallowSuspenseContext(
  12848. suspenseStackCursor.current,
  12849. ForceSuspenseFallback
  12850. )
  12851. );
  12852. return workInProgress.child;
  12853. }
  12854. row = row.sibling;
  12855. }
  12856. }
  12857. } else {
  12858. cutOffTailIfNeeded(renderState, false);
  12859. } // Next we're going to render the tail.
  12860. } else {
  12861. // Append the rendered row to the child list.
  12862. if (!didSuspendAlready) {
  12863. var _suspended = findFirstSuspended(renderedTail);
  12864. if (_suspended !== null) {
  12865. workInProgress.effectTag |= DidCapture;
  12866. didSuspendAlready = true; // Ensure we transfer the update queue to the parent so that it doesn't
  12867. // get lost if this row ends up dropped during a second pass.
  12868. var _newThennables = _suspended.updateQueue;
  12869. if (_newThennables !== null) {
  12870. workInProgress.updateQueue = _newThennables;
  12871. workInProgress.effectTag |= Update;
  12872. }
  12873. cutOffTailIfNeeded(renderState, true); // This might have been modified.
  12874. if (
  12875. renderState.tail === null &&
  12876. renderState.tailMode === "hidden" &&
  12877. !renderedTail.alternate
  12878. ) {
  12879. // We need to delete the row we just rendered.
  12880. // Reset the effect list to what it was before we rendered this
  12881. // child. The nested children have already appended themselves.
  12882. var lastEffect = (workInProgress.lastEffect =
  12883. renderState.lastEffect); // Remove any effects that were appended after this point.
  12884. if (lastEffect !== null) {
  12885. lastEffect.nextEffect = null;
  12886. } // We're done.
  12887. return null;
  12888. }
  12889. } else if (
  12890. // The time it took to render last row is greater than time until
  12891. // the expiration.
  12892. now() * 2 - renderState.renderingStartTime >
  12893. renderState.tailExpiration &&
  12894. renderExpirationTime > Never
  12895. ) {
  12896. // We have now passed our CPU deadline and we'll just give up further
  12897. // attempts to render the main content and only render fallbacks.
  12898. // The assumption is that this is usually faster.
  12899. workInProgress.effectTag |= DidCapture;
  12900. didSuspendAlready = true;
  12901. cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
  12902. // to get it started back up to attempt the next item. If we can show
  12903. // them, then they really have the same priority as this render.
  12904. // So we'll pick it back up the very next render pass once we've had
  12905. // an opportunity to yield for paint.
  12906. var nextPriority = renderExpirationTime - 1;
  12907. workInProgress.expirationTime = workInProgress.childExpirationTime = nextPriority;
  12908. {
  12909. markSpawnedWork(nextPriority);
  12910. }
  12911. }
  12912. }
  12913. if (renderState.isBackwards) {
  12914. // The effect list of the backwards tail will have been added
  12915. // to the end. This breaks the guarantee that life-cycles fire in
  12916. // sibling order but that isn't a strong guarantee promised by React.
  12917. // Especially since these might also just pop in during future commits.
  12918. // Append to the beginning of the list.
  12919. renderedTail.sibling = workInProgress.child;
  12920. workInProgress.child = renderedTail;
  12921. } else {
  12922. var previousSibling = renderState.last;
  12923. if (previousSibling !== null) {
  12924. previousSibling.sibling = renderedTail;
  12925. } else {
  12926. workInProgress.child = renderedTail;
  12927. }
  12928. renderState.last = renderedTail;
  12929. }
  12930. }
  12931. if (renderState.tail !== null) {
  12932. // We still have tail rows to render.
  12933. if (renderState.tailExpiration === 0) {
  12934. // Heuristic for how long we're willing to spend rendering rows
  12935. // until we just give up and show what we have so far.
  12936. var TAIL_EXPIRATION_TIMEOUT_MS = 500;
  12937. renderState.tailExpiration = now() + TAIL_EXPIRATION_TIMEOUT_MS; // TODO: This is meant to mimic the train model or JND but this
  12938. // is a per component value. It should really be since the start
  12939. // of the total render or last commit. Consider using something like
  12940. // globalMostRecentFallbackTime. That doesn't account for being
  12941. // suspended for part of the time or when it's a new render.
  12942. // It should probably use a global start time value instead.
  12943. } // Pop a row.
  12944. var next = renderState.tail;
  12945. renderState.rendering = next;
  12946. renderState.tail = next.sibling;
  12947. renderState.lastEffect = workInProgress.lastEffect;
  12948. renderState.renderingStartTime = now();
  12949. next.sibling = null; // Restore the context.
  12950. // TODO: We can probably just avoid popping it instead and only
  12951. // setting it the first time we go from not suspended to suspended.
  12952. var suspenseContext = suspenseStackCursor.current;
  12953. if (didSuspendAlready) {
  12954. suspenseContext = setShallowSuspenseContext(
  12955. suspenseContext,
  12956. ForceSuspenseFallback
  12957. );
  12958. } else {
  12959. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  12960. }
  12961. pushSuspenseContext(workInProgress, suspenseContext); // Do a pass over the next row.
  12962. return next;
  12963. }
  12964. return null;
  12965. }
  12966. }
  12967. {
  12968. throw Error(
  12969. "Unknown unit of work tag (" +
  12970. workInProgress.tag +
  12971. "). This error is likely caused by a bug in React. Please file an issue."
  12972. );
  12973. }
  12974. }
  12975. function unwindWork(workInProgress, renderExpirationTime) {
  12976. switch (workInProgress.tag) {
  12977. case ClassComponent: {
  12978. var Component = workInProgress.type;
  12979. if (isContextProvider(Component)) {
  12980. popContext(workInProgress);
  12981. }
  12982. var effectTag = workInProgress.effectTag;
  12983. if (effectTag & ShouldCapture) {
  12984. workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture;
  12985. return workInProgress;
  12986. }
  12987. return null;
  12988. }
  12989. case HostRoot: {
  12990. popHostContainer(workInProgress);
  12991. popTopLevelContextObject(workInProgress);
  12992. var _effectTag = workInProgress.effectTag;
  12993. if (!((_effectTag & DidCapture) === NoEffect)) {
  12994. throw Error(
  12995. "The root failed to unmount after an error. This is likely a bug in React. Please file an issue."
  12996. );
  12997. }
  12998. workInProgress.effectTag = (_effectTag & ~ShouldCapture) | DidCapture;
  12999. return workInProgress;
  13000. }
  13001. case HostComponent: {
  13002. // TODO: popHydrationState
  13003. popHostContext(workInProgress);
  13004. return null;
  13005. }
  13006. case SuspenseComponent: {
  13007. popSuspenseContext(workInProgress);
  13008. var _effectTag2 = workInProgress.effectTag;
  13009. if (_effectTag2 & ShouldCapture) {
  13010. workInProgress.effectTag = (_effectTag2 & ~ShouldCapture) | DidCapture; // Captured a suspense effect. Re-render the boundary.
  13011. return workInProgress;
  13012. }
  13013. return null;
  13014. }
  13015. case SuspenseListComponent: {
  13016. popSuspenseContext(workInProgress); // SuspenseList doesn't actually catch anything. It should've been
  13017. // caught by a nested boundary. If not, it should bubble through.
  13018. return null;
  13019. }
  13020. case HostPortal:
  13021. popHostContainer(workInProgress);
  13022. return null;
  13023. case ContextProvider:
  13024. popProvider(workInProgress);
  13025. return null;
  13026. default:
  13027. return null;
  13028. }
  13029. }
  13030. function unwindInterruptedWork(interruptedWork) {
  13031. switch (interruptedWork.tag) {
  13032. case ClassComponent: {
  13033. var childContextTypes = interruptedWork.type.childContextTypes;
  13034. if (childContextTypes !== null && childContextTypes !== undefined) {
  13035. popContext(interruptedWork);
  13036. }
  13037. break;
  13038. }
  13039. case HostRoot: {
  13040. popHostContainer(interruptedWork);
  13041. popTopLevelContextObject(interruptedWork);
  13042. break;
  13043. }
  13044. case HostComponent: {
  13045. popHostContext(interruptedWork);
  13046. break;
  13047. }
  13048. case HostPortal:
  13049. popHostContainer(interruptedWork);
  13050. break;
  13051. case SuspenseComponent:
  13052. popSuspenseContext(interruptedWork);
  13053. break;
  13054. case SuspenseListComponent:
  13055. popSuspenseContext(interruptedWork);
  13056. break;
  13057. case ContextProvider:
  13058. popProvider(interruptedWork);
  13059. break;
  13060. }
  13061. }
  13062. function createCapturedValue(value, source) {
  13063. // If the value is an error, call this function immediately after it is thrown
  13064. // so the stack is accurate.
  13065. return {
  13066. value: value,
  13067. source: source,
  13068. stack: getStackByFiberInDevAndProd(source)
  13069. };
  13070. }
  13071. // Module provided by RN:
  13072. if (
  13073. !(
  13074. typeof ReactNativePrivateInterface.ReactFiberErrorDialog.showErrorDialog ===
  13075. "function"
  13076. )
  13077. ) {
  13078. throw Error(
  13079. "Expected ReactFiberErrorDialog.showErrorDialog to be a function."
  13080. );
  13081. }
  13082. function showErrorDialog(capturedError) {
  13083. return ReactNativePrivateInterface.ReactFiberErrorDialog.showErrorDialog(
  13084. capturedError
  13085. );
  13086. }
  13087. function logCapturedError(capturedError) {
  13088. var logError = showErrorDialog(capturedError); // Allow injected showErrorDialog() to prevent default console.error logging.
  13089. // This enables renderers like ReactNative to better manage redbox behavior.
  13090. if (logError === false) {
  13091. return;
  13092. }
  13093. var error = capturedError.error;
  13094. {
  13095. var componentName = capturedError.componentName,
  13096. componentStack = capturedError.componentStack,
  13097. errorBoundaryName = capturedError.errorBoundaryName,
  13098. errorBoundaryFound = capturedError.errorBoundaryFound,
  13099. willRetry = capturedError.willRetry; // Browsers support silencing uncaught errors by calling
  13100. // `preventDefault()` in window `error` handler.
  13101. // We record this information as an expando on the error.
  13102. if (error != null && error._suppressLogging) {
  13103. if (errorBoundaryFound && willRetry) {
  13104. // The error is recoverable and was silenced.
  13105. // Ignore it and don't print the stack addendum.
  13106. // This is handy for testing error boundaries without noise.
  13107. return;
  13108. } // The error is fatal. Since the silencing might have
  13109. // been accidental, we'll surface it anyway.
  13110. // However, the browser would have silenced the original error
  13111. // so we'll print it first, and then print the stack addendum.
  13112. console["error"](error); // Don't transform to our wrapper
  13113. // For a more detailed description of this block, see:
  13114. // https://github.com/facebook/react/pull/13384
  13115. }
  13116. var componentNameMessage = componentName
  13117. ? "The above error occurred in the <" + componentName + "> component:"
  13118. : "The above error occurred in one of your React components:";
  13119. var errorBoundaryMessage; // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
  13120. if (errorBoundaryFound && errorBoundaryName) {
  13121. if (willRetry) {
  13122. errorBoundaryMessage =
  13123. "React will try to recreate this component tree from scratch " +
  13124. ("using the error boundary you provided, " + errorBoundaryName + ".");
  13125. } else {
  13126. errorBoundaryMessage =
  13127. "This error was initially handled by the error boundary " +
  13128. errorBoundaryName +
  13129. ".\n" +
  13130. "Recreating the tree from scratch failed so React will unmount the tree.";
  13131. }
  13132. } else {
  13133. errorBoundaryMessage =
  13134. "Consider adding an error boundary to your tree to customize error handling behavior.\n" +
  13135. "Visit https://fb.me/react-error-boundaries to learn more about error boundaries.";
  13136. }
  13137. var combinedMessage =
  13138. "" +
  13139. componentNameMessage +
  13140. componentStack +
  13141. "\n\n" +
  13142. ("" + errorBoundaryMessage); // In development, we provide our own message with just the component stack.
  13143. // We don't include the original error message and JS stack because the browser
  13144. // has already printed it. Even if the application swallows the error, it is still
  13145. // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
  13146. console["error"](combinedMessage); // Don't transform to our wrapper
  13147. }
  13148. }
  13149. var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
  13150. {
  13151. didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
  13152. }
  13153. var PossiblyWeakSet = typeof WeakSet === "function" ? WeakSet : Set;
  13154. function logError(boundary, errorInfo) {
  13155. var source = errorInfo.source;
  13156. var stack = errorInfo.stack;
  13157. if (stack === null && source !== null) {
  13158. stack = getStackByFiberInDevAndProd(source);
  13159. }
  13160. var capturedError = {
  13161. componentName: source !== null ? getComponentName(source.type) : null,
  13162. componentStack: stack !== null ? stack : "",
  13163. error: errorInfo.value,
  13164. errorBoundary: null,
  13165. errorBoundaryName: null,
  13166. errorBoundaryFound: false,
  13167. willRetry: false
  13168. };
  13169. if (boundary !== null && boundary.tag === ClassComponent) {
  13170. capturedError.errorBoundary = boundary.stateNode;
  13171. capturedError.errorBoundaryName = getComponentName(boundary.type);
  13172. capturedError.errorBoundaryFound = true;
  13173. capturedError.willRetry = true;
  13174. }
  13175. try {
  13176. logCapturedError(capturedError);
  13177. } catch (e) {
  13178. // This method must not throw, or React internal state will get messed up.
  13179. // If console.error is overridden, or logCapturedError() shows a dialog that throws,
  13180. // we want to report this error outside of the normal stack as a last resort.
  13181. // https://github.com/facebook/react/issues/13188
  13182. setTimeout(function() {
  13183. throw e;
  13184. });
  13185. }
  13186. }
  13187. var callComponentWillUnmountWithTimer = function(current, instance) {
  13188. startPhaseTimer(current, "componentWillUnmount");
  13189. instance.props = current.memoizedProps;
  13190. instance.state = current.memoizedState;
  13191. {
  13192. instance.componentWillUnmount();
  13193. }
  13194. stopPhaseTimer();
  13195. }; // Capture errors so they don't interrupt unmounting.
  13196. function safelyCallComponentWillUnmount(current, instance) {
  13197. {
  13198. invokeGuardedCallback(
  13199. null,
  13200. callComponentWillUnmountWithTimer,
  13201. null,
  13202. current,
  13203. instance
  13204. );
  13205. if (hasCaughtError()) {
  13206. var unmountError = clearCaughtError();
  13207. captureCommitPhaseError(current, unmountError);
  13208. }
  13209. }
  13210. }
  13211. function safelyDetachRef(current) {
  13212. var ref = current.ref;
  13213. if (ref !== null) {
  13214. if (typeof ref === "function") {
  13215. {
  13216. invokeGuardedCallback(null, ref, null, null);
  13217. if (hasCaughtError()) {
  13218. var refError = clearCaughtError();
  13219. captureCommitPhaseError(current, refError);
  13220. }
  13221. }
  13222. } else {
  13223. ref.current = null;
  13224. }
  13225. }
  13226. }
  13227. function safelyCallDestroy(current, destroy) {
  13228. {
  13229. invokeGuardedCallback(null, destroy, null);
  13230. if (hasCaughtError()) {
  13231. var error = clearCaughtError();
  13232. captureCommitPhaseError(current, error);
  13233. }
  13234. }
  13235. }
  13236. function commitBeforeMutationLifeCycles(current, finishedWork) {
  13237. switch (finishedWork.tag) {
  13238. case FunctionComponent:
  13239. case ForwardRef:
  13240. case SimpleMemoComponent:
  13241. case Block: {
  13242. return;
  13243. }
  13244. case ClassComponent: {
  13245. if (finishedWork.effectTag & Snapshot) {
  13246. if (current !== null) {
  13247. var prevProps = current.memoizedProps;
  13248. var prevState = current.memoizedState;
  13249. startPhaseTimer(finishedWork, "getSnapshotBeforeUpdate");
  13250. var instance = finishedWork.stateNode; // We could update instance props and state here,
  13251. // but instead we rely on them being set during last render.
  13252. // TODO: revisit this when we implement resuming.
  13253. {
  13254. if (
  13255. finishedWork.type === finishedWork.elementType &&
  13256. !didWarnAboutReassigningProps
  13257. ) {
  13258. if (instance.props !== finishedWork.memoizedProps) {
  13259. error(
  13260. "Expected %s props to match memoized props before " +
  13261. "getSnapshotBeforeUpdate. " +
  13262. "This might either be because of a bug in React, or because " +
  13263. "a component reassigns its own `this.props`. " +
  13264. "Please file an issue.",
  13265. getComponentName(finishedWork.type) || "instance"
  13266. );
  13267. }
  13268. if (instance.state !== finishedWork.memoizedState) {
  13269. error(
  13270. "Expected %s state to match memoized state before " +
  13271. "getSnapshotBeforeUpdate. " +
  13272. "This might either be because of a bug in React, or because " +
  13273. "a component reassigns its own `this.state`. " +
  13274. "Please file an issue.",
  13275. getComponentName(finishedWork.type) || "instance"
  13276. );
  13277. }
  13278. }
  13279. }
  13280. var snapshot = instance.getSnapshotBeforeUpdate(
  13281. finishedWork.elementType === finishedWork.type
  13282. ? prevProps
  13283. : resolveDefaultProps(finishedWork.type, prevProps),
  13284. prevState
  13285. );
  13286. {
  13287. var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
  13288. if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
  13289. didWarnSet.add(finishedWork.type);
  13290. error(
  13291. "%s.getSnapshotBeforeUpdate(): A snapshot value (or null) " +
  13292. "must be returned. You have returned undefined.",
  13293. getComponentName(finishedWork.type)
  13294. );
  13295. }
  13296. }
  13297. instance.__reactInternalSnapshotBeforeUpdate = snapshot;
  13298. stopPhaseTimer();
  13299. }
  13300. }
  13301. return;
  13302. }
  13303. case HostRoot:
  13304. case HostComponent:
  13305. case HostText:
  13306. case HostPortal:
  13307. case IncompleteClassComponent:
  13308. // Nothing to do for these component types
  13309. return;
  13310. }
  13311. {
  13312. throw Error(
  13313. "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."
  13314. );
  13315. }
  13316. }
  13317. function commitHookEffectListUnmount(tag, finishedWork) {
  13318. var updateQueue = finishedWork.updateQueue;
  13319. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  13320. if (lastEffect !== null) {
  13321. var firstEffect = lastEffect.next;
  13322. var effect = firstEffect;
  13323. do {
  13324. if ((effect.tag & tag) === tag) {
  13325. // Unmount
  13326. var destroy = effect.destroy;
  13327. effect.destroy = undefined;
  13328. if (destroy !== undefined) {
  13329. destroy();
  13330. }
  13331. }
  13332. effect = effect.next;
  13333. } while (effect !== firstEffect);
  13334. }
  13335. }
  13336. function commitHookEffectListMount(tag, finishedWork) {
  13337. var updateQueue = finishedWork.updateQueue;
  13338. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  13339. if (lastEffect !== null) {
  13340. var firstEffect = lastEffect.next;
  13341. var effect = firstEffect;
  13342. do {
  13343. if ((effect.tag & tag) === tag) {
  13344. // Mount
  13345. var create = effect.create;
  13346. effect.destroy = create();
  13347. {
  13348. var destroy = effect.destroy;
  13349. if (destroy !== undefined && typeof destroy !== "function") {
  13350. var addendum = void 0;
  13351. if (destroy === null) {
  13352. addendum =
  13353. " You returned null. If your effect does not require clean " +
  13354. "up, return undefined (or nothing).";
  13355. } else if (typeof destroy.then === "function") {
  13356. addendum =
  13357. "\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. " +
  13358. "Instead, write the async function inside your effect " +
  13359. "and call it immediately:\n\n" +
  13360. "useEffect(() => {\n" +
  13361. " async function fetchData() {\n" +
  13362. " // You can await here\n" +
  13363. " const response = await MyAPI.getData(someId);\n" +
  13364. " // ...\n" +
  13365. " }\n" +
  13366. " fetchData();\n" +
  13367. "}, [someId]); // Or [] if effect doesn't need props or state\n\n" +
  13368. "Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching";
  13369. } else {
  13370. addendum = " You returned: " + destroy;
  13371. }
  13372. error(
  13373. "An effect function must not return anything besides a function, " +
  13374. "which is used for clean-up.%s%s",
  13375. addendum,
  13376. getStackByFiberInDevAndProd(finishedWork)
  13377. );
  13378. }
  13379. }
  13380. }
  13381. effect = effect.next;
  13382. } while (effect !== firstEffect);
  13383. }
  13384. }
  13385. function commitPassiveHookEffects(finishedWork) {
  13386. if ((finishedWork.effectTag & Passive) !== NoEffect) {
  13387. switch (finishedWork.tag) {
  13388. case FunctionComponent:
  13389. case ForwardRef:
  13390. case SimpleMemoComponent:
  13391. case Block: {
  13392. // TODO (#17945) We should call all passive destroy functions (for all fibers)
  13393. // before calling any create functions. The current approach only serializes
  13394. // these for a single fiber.
  13395. {
  13396. commitHookEffectListUnmount(Passive$1 | HasEffect, finishedWork);
  13397. commitHookEffectListMount(Passive$1 | HasEffect, finishedWork);
  13398. }
  13399. break;
  13400. }
  13401. }
  13402. }
  13403. }
  13404. function commitLifeCycles(
  13405. finishedRoot,
  13406. current,
  13407. finishedWork,
  13408. committedExpirationTime
  13409. ) {
  13410. switch (finishedWork.tag) {
  13411. case FunctionComponent:
  13412. case ForwardRef:
  13413. case SimpleMemoComponent:
  13414. case Block: {
  13415. // At this point layout effects have already been destroyed (during mutation phase).
  13416. // This is done to prevent sibling component effects from interfering with each other,
  13417. // e.g. a destroy function in one component should never override a ref set
  13418. // by a create function in another component during the same commit.
  13419. {
  13420. commitHookEffectListMount(Layout | HasEffect, finishedWork);
  13421. }
  13422. return;
  13423. }
  13424. case ClassComponent: {
  13425. var instance = finishedWork.stateNode;
  13426. if (finishedWork.effectTag & Update) {
  13427. if (current === null) {
  13428. startPhaseTimer(finishedWork, "componentDidMount"); // We could update instance props and state here,
  13429. // but instead we rely on them being set during last render.
  13430. // TODO: revisit this when we implement resuming.
  13431. {
  13432. if (
  13433. finishedWork.type === finishedWork.elementType &&
  13434. !didWarnAboutReassigningProps
  13435. ) {
  13436. if (instance.props !== finishedWork.memoizedProps) {
  13437. error(
  13438. "Expected %s props to match memoized props before " +
  13439. "componentDidMount. " +
  13440. "This might either be because of a bug in React, or because " +
  13441. "a component reassigns its own `this.props`. " +
  13442. "Please file an issue.",
  13443. getComponentName(finishedWork.type) || "instance"
  13444. );
  13445. }
  13446. if (instance.state !== finishedWork.memoizedState) {
  13447. error(
  13448. "Expected %s state to match memoized state before " +
  13449. "componentDidMount. " +
  13450. "This might either be because of a bug in React, or because " +
  13451. "a component reassigns its own `this.state`. " +
  13452. "Please file an issue.",
  13453. getComponentName(finishedWork.type) || "instance"
  13454. );
  13455. }
  13456. }
  13457. }
  13458. {
  13459. instance.componentDidMount();
  13460. }
  13461. stopPhaseTimer();
  13462. } else {
  13463. var prevProps =
  13464. finishedWork.elementType === finishedWork.type
  13465. ? current.memoizedProps
  13466. : resolveDefaultProps(finishedWork.type, current.memoizedProps);
  13467. var prevState = current.memoizedState;
  13468. startPhaseTimer(finishedWork, "componentDidUpdate"); // We could update instance props and state here,
  13469. // but instead we rely on them being set during last render.
  13470. // TODO: revisit this when we implement resuming.
  13471. {
  13472. if (
  13473. finishedWork.type === finishedWork.elementType &&
  13474. !didWarnAboutReassigningProps
  13475. ) {
  13476. if (instance.props !== finishedWork.memoizedProps) {
  13477. error(
  13478. "Expected %s props to match memoized props before " +
  13479. "componentDidUpdate. " +
  13480. "This might either be because of a bug in React, or because " +
  13481. "a component reassigns its own `this.props`. " +
  13482. "Please file an issue.",
  13483. getComponentName(finishedWork.type) || "instance"
  13484. );
  13485. }
  13486. if (instance.state !== finishedWork.memoizedState) {
  13487. error(
  13488. "Expected %s state to match memoized state before " +
  13489. "componentDidUpdate. " +
  13490. "This might either be because of a bug in React, or because " +
  13491. "a component reassigns its own `this.state`. " +
  13492. "Please file an issue.",
  13493. getComponentName(finishedWork.type) || "instance"
  13494. );
  13495. }
  13496. }
  13497. }
  13498. {
  13499. instance.componentDidUpdate(
  13500. prevProps,
  13501. prevState,
  13502. instance.__reactInternalSnapshotBeforeUpdate
  13503. );
  13504. }
  13505. stopPhaseTimer();
  13506. }
  13507. }
  13508. var updateQueue = finishedWork.updateQueue;
  13509. if (updateQueue !== null) {
  13510. {
  13511. if (
  13512. finishedWork.type === finishedWork.elementType &&
  13513. !didWarnAboutReassigningProps
  13514. ) {
  13515. if (instance.props !== finishedWork.memoizedProps) {
  13516. error(
  13517. "Expected %s props to match memoized props before " +
  13518. "processing the update queue. " +
  13519. "This might either be because of a bug in React, or because " +
  13520. "a component reassigns its own `this.props`. " +
  13521. "Please file an issue.",
  13522. getComponentName(finishedWork.type) || "instance"
  13523. );
  13524. }
  13525. if (instance.state !== finishedWork.memoizedState) {
  13526. error(
  13527. "Expected %s state to match memoized state before " +
  13528. "processing the update queue. " +
  13529. "This might either be because of a bug in React, or because " +
  13530. "a component reassigns its own `this.state`. " +
  13531. "Please file an issue.",
  13532. getComponentName(finishedWork.type) || "instance"
  13533. );
  13534. }
  13535. }
  13536. } // We could update instance props and state here,
  13537. // but instead we rely on them being set during last render.
  13538. // TODO: revisit this when we implement resuming.
  13539. commitUpdateQueue(finishedWork, updateQueue, instance);
  13540. }
  13541. return;
  13542. }
  13543. case HostRoot: {
  13544. var _updateQueue = finishedWork.updateQueue;
  13545. if (_updateQueue !== null) {
  13546. var _instance = null;
  13547. if (finishedWork.child !== null) {
  13548. switch (finishedWork.child.tag) {
  13549. case HostComponent:
  13550. _instance = getPublicInstance(finishedWork.child.stateNode);
  13551. break;
  13552. case ClassComponent:
  13553. _instance = finishedWork.child.stateNode;
  13554. break;
  13555. }
  13556. }
  13557. commitUpdateQueue(finishedWork, _updateQueue, _instance);
  13558. }
  13559. return;
  13560. }
  13561. case HostComponent: {
  13562. var _instance2 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted
  13563. // (eg DOM renderer may schedule auto-focus for inputs and form controls).
  13564. // These effects should only be committed when components are first mounted,
  13565. // aka when there is no current/alternate.
  13566. if (current === null && finishedWork.effectTag & Update) {
  13567. var type = finishedWork.type;
  13568. var props = finishedWork.memoizedProps;
  13569. commitMount();
  13570. }
  13571. return;
  13572. }
  13573. case HostText: {
  13574. // We have no life-cycles associated with text.
  13575. return;
  13576. }
  13577. case HostPortal: {
  13578. // We have no life-cycles associated with portals.
  13579. return;
  13580. }
  13581. case Profiler: {
  13582. {
  13583. var _finishedWork$memoize2 = finishedWork.memoizedProps,
  13584. onCommit = _finishedWork$memoize2.onCommit,
  13585. onRender = _finishedWork$memoize2.onRender;
  13586. var effectDuration = finishedWork.stateNode.effectDuration;
  13587. var commitTime = getCommitTime();
  13588. if (typeof onRender === "function") {
  13589. {
  13590. onRender(
  13591. finishedWork.memoizedProps.id,
  13592. current === null ? "mount" : "update",
  13593. finishedWork.actualDuration,
  13594. finishedWork.treeBaseDuration,
  13595. finishedWork.actualStartTime,
  13596. commitTime,
  13597. finishedRoot.memoizedInteractions
  13598. );
  13599. }
  13600. }
  13601. }
  13602. return;
  13603. }
  13604. case SuspenseComponent: {
  13605. return;
  13606. }
  13607. case SuspenseListComponent:
  13608. case IncompleteClassComponent:
  13609. case FundamentalComponent:
  13610. case ScopeComponent:
  13611. return;
  13612. }
  13613. {
  13614. throw Error(
  13615. "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."
  13616. );
  13617. }
  13618. }
  13619. function commitAttachRef(finishedWork) {
  13620. var ref = finishedWork.ref;
  13621. if (ref !== null) {
  13622. var instance = finishedWork.stateNode;
  13623. var instanceToUse;
  13624. switch (finishedWork.tag) {
  13625. case HostComponent:
  13626. instanceToUse = getPublicInstance(instance);
  13627. break;
  13628. default:
  13629. instanceToUse = instance;
  13630. } // Moved outside to ensure DCE works with this flag
  13631. if (typeof ref === "function") {
  13632. ref(instanceToUse);
  13633. } else {
  13634. {
  13635. if (!ref.hasOwnProperty("current")) {
  13636. error(
  13637. "Unexpected ref object provided for %s. " +
  13638. "Use either a ref-setter function or React.createRef().%s",
  13639. getComponentName(finishedWork.type),
  13640. getStackByFiberInDevAndProd(finishedWork)
  13641. );
  13642. }
  13643. }
  13644. ref.current = instanceToUse;
  13645. }
  13646. }
  13647. }
  13648. function commitDetachRef(current) {
  13649. var currentRef = current.ref;
  13650. if (currentRef !== null) {
  13651. if (typeof currentRef === "function") {
  13652. currentRef(null);
  13653. } else {
  13654. currentRef.current = null;
  13655. }
  13656. }
  13657. } // User-originating errors (lifecycles and refs) should not interrupt
  13658. // deletion, so don't let them throw. Host-originating errors should
  13659. // interrupt deletion, so it's okay
  13660. function commitUnmount(finishedRoot, current, renderPriorityLevel) {
  13661. onCommitUnmount(current);
  13662. switch (current.tag) {
  13663. case FunctionComponent:
  13664. case ForwardRef:
  13665. case MemoComponent:
  13666. case SimpleMemoComponent:
  13667. case Block: {
  13668. var updateQueue = current.updateQueue;
  13669. if (updateQueue !== null) {
  13670. var lastEffect = updateQueue.lastEffect;
  13671. if (lastEffect !== null) {
  13672. var firstEffect = lastEffect.next;
  13673. {
  13674. // When the owner fiber is deleted, the destroy function of a passive
  13675. // effect hook is called during the synchronous commit phase. This is
  13676. // a concession to implementation complexity. Calling it in the
  13677. // passive effect phase (like they usually are, when dependencies
  13678. // change during an update) would require either traversing the
  13679. // children of the deleted fiber again, or including unmount effects
  13680. // as part of the fiber effect list.
  13681. //
  13682. // Because this is during the sync commit phase, we need to change
  13683. // the priority.
  13684. //
  13685. // TODO: Reconsider this implementation trade off.
  13686. var priorityLevel =
  13687. renderPriorityLevel > NormalPriority
  13688. ? NormalPriority
  13689. : renderPriorityLevel;
  13690. runWithPriority(priorityLevel, function() {
  13691. var effect = firstEffect;
  13692. do {
  13693. var _effect3 = effect,
  13694. _destroy = _effect3.destroy,
  13695. _tag = _effect3.tag;
  13696. if (_destroy !== undefined) {
  13697. {
  13698. safelyCallDestroy(current, _destroy);
  13699. }
  13700. }
  13701. effect = effect.next;
  13702. } while (effect !== firstEffect);
  13703. });
  13704. }
  13705. }
  13706. }
  13707. return;
  13708. }
  13709. case ClassComponent: {
  13710. safelyDetachRef(current);
  13711. var instance = current.stateNode;
  13712. if (typeof instance.componentWillUnmount === "function") {
  13713. safelyCallComponentWillUnmount(current, instance);
  13714. }
  13715. return;
  13716. }
  13717. case HostComponent: {
  13718. safelyDetachRef(current);
  13719. return;
  13720. }
  13721. case HostPortal: {
  13722. // TODO: this is recursive.
  13723. // We are also not using this parent because
  13724. // the portal will get pushed immediately.
  13725. {
  13726. emptyPortalContainer(current);
  13727. }
  13728. return;
  13729. }
  13730. case FundamentalComponent: {
  13731. return;
  13732. }
  13733. case DehydratedFragment: {
  13734. return;
  13735. }
  13736. case ScopeComponent: {
  13737. return;
  13738. }
  13739. }
  13740. }
  13741. function commitNestedUnmounts(finishedRoot, root, renderPriorityLevel) {
  13742. // While we're inside a removed host node we don't want to call
  13743. // removeChild on the inner nodes because they're removed by the top
  13744. // call anyway. We also want to call componentWillUnmount on all
  13745. // composites before this host node is removed from the tree. Therefore
  13746. // we do an inner loop while we're still inside the host node.
  13747. var node = root;
  13748. while (true) {
  13749. commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes.
  13750. // Skip portals because commitUnmount() currently visits them recursively.
  13751. if (
  13752. node.child !== null && // If we use mutation we drill down into portals using commitUnmount above.
  13753. // If we don't use mutation we drill down into portals here instead.
  13754. !supportsMutation
  13755. ) {
  13756. node.child.return = node;
  13757. node = node.child;
  13758. continue;
  13759. }
  13760. if (node === root) {
  13761. return;
  13762. }
  13763. while (node.sibling === null) {
  13764. if (node.return === null || node.return === root) {
  13765. return;
  13766. }
  13767. node = node.return;
  13768. }
  13769. node.sibling.return = node.return;
  13770. node = node.sibling;
  13771. }
  13772. }
  13773. function detachFiber(current) {
  13774. var alternate = current.alternate; // Cut off the return pointers to disconnect it from the tree. Ideally, we
  13775. // should clear the child pointer of the parent alternate to let this
  13776. // get GC:ed but we don't know which for sure which parent is the current
  13777. // one so we'll settle for GC:ing the subtree of this child. This child
  13778. // itself will be GC:ed when the parent updates the next time.
  13779. current.return = null;
  13780. current.child = null;
  13781. current.memoizedState = null;
  13782. current.updateQueue = null;
  13783. current.dependencies = null;
  13784. current.alternate = null;
  13785. current.firstEffect = null;
  13786. current.lastEffect = null;
  13787. current.pendingProps = null;
  13788. current.memoizedProps = null;
  13789. current.stateNode = null;
  13790. if (alternate !== null) {
  13791. detachFiber(alternate);
  13792. }
  13793. }
  13794. function emptyPortalContainer(current) {
  13795. var portal = current.stateNode;
  13796. var containerInfo = portal.containerInfo;
  13797. var emptyChildSet = createContainerChildSet(containerInfo);
  13798. }
  13799. function commitContainer(finishedWork) {
  13800. switch (finishedWork.tag) {
  13801. case ClassComponent:
  13802. case HostComponent:
  13803. case HostText:
  13804. case FundamentalComponent: {
  13805. return;
  13806. }
  13807. case HostRoot:
  13808. case HostPortal: {
  13809. var portalOrRoot = finishedWork.stateNode;
  13810. var containerInfo = portalOrRoot.containerInfo,
  13811. pendingChildren = portalOrRoot.pendingChildren;
  13812. return;
  13813. }
  13814. }
  13815. {
  13816. throw Error(
  13817. "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."
  13818. );
  13819. }
  13820. }
  13821. function commitDeletion(finishedRoot, current, renderPriorityLevel) {
  13822. {
  13823. // Detach refs and call componentWillUnmount() on the whole subtree.
  13824. commitNestedUnmounts(finishedRoot, current, renderPriorityLevel);
  13825. }
  13826. detachFiber(current);
  13827. }
  13828. function commitWork(current, finishedWork) {
  13829. {
  13830. switch (finishedWork.tag) {
  13831. case FunctionComponent:
  13832. case ForwardRef:
  13833. case MemoComponent:
  13834. case SimpleMemoComponent:
  13835. case Block: {
  13836. // Layout effects are destroyed during the mutation phase so that all
  13837. // destroy functions for all fibers are called before any create functions.
  13838. // This prevents sibling component effects from interfering with each other,
  13839. // e.g. a destroy function in one component should never override a ref set
  13840. // by a create function in another component during the same commit.
  13841. {
  13842. commitHookEffectListUnmount(Layout | HasEffect, finishedWork);
  13843. }
  13844. return;
  13845. }
  13846. case Profiler: {
  13847. return;
  13848. }
  13849. case SuspenseComponent: {
  13850. commitSuspenseComponent(finishedWork);
  13851. attachSuspenseRetryListeners(finishedWork);
  13852. return;
  13853. }
  13854. case SuspenseListComponent: {
  13855. attachSuspenseRetryListeners(finishedWork);
  13856. return;
  13857. }
  13858. }
  13859. commitContainer(finishedWork);
  13860. return;
  13861. }
  13862. }
  13863. function commitSuspenseComponent(finishedWork) {
  13864. var newState = finishedWork.memoizedState;
  13865. var primaryChildParent = finishedWork;
  13866. if (newState === null);
  13867. else {
  13868. primaryChildParent = finishedWork.child;
  13869. markCommitTimeOfFallback();
  13870. }
  13871. }
  13872. function attachSuspenseRetryListeners(finishedWork) {
  13873. // If this boundary just timed out, then it will have a set of thenables.
  13874. // For each thenable, attach a listener so that when it resolves, React
  13875. // attempts to re-render the boundary in the primary (pre-timeout) state.
  13876. var thenables = finishedWork.updateQueue;
  13877. if (thenables !== null) {
  13878. finishedWork.updateQueue = null;
  13879. var retryCache = finishedWork.stateNode;
  13880. if (retryCache === null) {
  13881. retryCache = finishedWork.stateNode = new PossiblyWeakSet();
  13882. }
  13883. thenables.forEach(function(thenable) {
  13884. // Memoize using the boundary fiber to prevent redundant listeners.
  13885. var retry = resolveRetryThenable.bind(null, finishedWork, thenable);
  13886. if (!retryCache.has(thenable)) {
  13887. {
  13888. if (thenable.__reactDoNotTraceInteractions !== true) {
  13889. retry = tracing.unstable_wrap(retry);
  13890. }
  13891. }
  13892. retryCache.add(thenable);
  13893. thenable.then(retry, retry);
  13894. }
  13895. });
  13896. }
  13897. }
  13898. var PossiblyWeakMap = typeof WeakMap === "function" ? WeakMap : Map;
  13899. function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
  13900. var update = createUpdate(expirationTime, null); // Unmount the root by rendering null.
  13901. update.tag = CaptureUpdate; // Caution: React DevTools currently depends on this property
  13902. // being called "element".
  13903. update.payload = {
  13904. element: null
  13905. };
  13906. var error = errorInfo.value;
  13907. update.callback = function() {
  13908. onUncaughtError(error);
  13909. logError(fiber, errorInfo);
  13910. };
  13911. return update;
  13912. }
  13913. function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
  13914. var update = createUpdate(expirationTime, null);
  13915. update.tag = CaptureUpdate;
  13916. var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
  13917. if (typeof getDerivedStateFromError === "function") {
  13918. var error$1 = errorInfo.value;
  13919. update.payload = function() {
  13920. logError(fiber, errorInfo);
  13921. return getDerivedStateFromError(error$1);
  13922. };
  13923. }
  13924. var inst = fiber.stateNode;
  13925. if (inst !== null && typeof inst.componentDidCatch === "function") {
  13926. update.callback = function callback() {
  13927. {
  13928. markFailedErrorBoundaryForHotReloading(fiber);
  13929. }
  13930. if (typeof getDerivedStateFromError !== "function") {
  13931. // To preserve the preexisting retry behavior of error boundaries,
  13932. // we keep track of which ones already failed during this batch.
  13933. // This gets reset before we yield back to the browser.
  13934. // TODO: Warn in strict mode if getDerivedStateFromError is
  13935. // not defined.
  13936. markLegacyErrorBoundaryAsFailed(this); // Only log here if componentDidCatch is the only error boundary method defined
  13937. logError(fiber, errorInfo);
  13938. }
  13939. var error$1 = errorInfo.value;
  13940. var stack = errorInfo.stack;
  13941. this.componentDidCatch(error$1, {
  13942. componentStack: stack !== null ? stack : ""
  13943. });
  13944. {
  13945. if (typeof getDerivedStateFromError !== "function") {
  13946. // If componentDidCatch is the only error boundary method defined,
  13947. // then it needs to call setState to recover from errors.
  13948. // If no state update is scheduled then the boundary will swallow the error.
  13949. if (fiber.expirationTime !== Sync) {
  13950. error(
  13951. "%s: Error boundaries should implement getDerivedStateFromError(). " +
  13952. "In that method, return a state update to display an error message or fallback UI.",
  13953. getComponentName(fiber.type) || "Unknown"
  13954. );
  13955. }
  13956. }
  13957. }
  13958. };
  13959. } else {
  13960. update.callback = function() {
  13961. markFailedErrorBoundaryForHotReloading(fiber);
  13962. };
  13963. }
  13964. return update;
  13965. }
  13966. function attachPingListener(root, renderExpirationTime, thenable) {
  13967. // Attach a listener to the promise to "ping" the root and retry. But
  13968. // only if one does not already exist for the current render expiration
  13969. // time (which acts like a "thread ID" here).
  13970. var pingCache = root.pingCache;
  13971. var threadIDs;
  13972. if (pingCache === null) {
  13973. pingCache = root.pingCache = new PossiblyWeakMap();
  13974. threadIDs = new Set();
  13975. pingCache.set(thenable, threadIDs);
  13976. } else {
  13977. threadIDs = pingCache.get(thenable);
  13978. if (threadIDs === undefined) {
  13979. threadIDs = new Set();
  13980. pingCache.set(thenable, threadIDs);
  13981. }
  13982. }
  13983. if (!threadIDs.has(renderExpirationTime)) {
  13984. // Memoize using the thread ID to prevent redundant listeners.
  13985. threadIDs.add(renderExpirationTime);
  13986. var ping = pingSuspendedRoot.bind(
  13987. null,
  13988. root,
  13989. thenable,
  13990. renderExpirationTime
  13991. );
  13992. thenable.then(ping, ping);
  13993. }
  13994. }
  13995. function throwException(
  13996. root,
  13997. returnFiber,
  13998. sourceFiber,
  13999. value,
  14000. renderExpirationTime
  14001. ) {
  14002. // The source fiber did not complete.
  14003. sourceFiber.effectTag |= Incomplete; // Its effect list is no longer valid.
  14004. sourceFiber.firstEffect = sourceFiber.lastEffect = null;
  14005. if (
  14006. value !== null &&
  14007. typeof value === "object" &&
  14008. typeof value.then === "function"
  14009. ) {
  14010. // This is a thenable.
  14011. var thenable = value;
  14012. if ((sourceFiber.mode & BlockingMode) === NoMode) {
  14013. // Reset the memoizedState to what it was before we attempted
  14014. // to render it.
  14015. var currentSource = sourceFiber.alternate;
  14016. if (currentSource) {
  14017. sourceFiber.updateQueue = currentSource.updateQueue;
  14018. sourceFiber.memoizedState = currentSource.memoizedState;
  14019. sourceFiber.expirationTime = currentSource.expirationTime;
  14020. } else {
  14021. sourceFiber.updateQueue = null;
  14022. sourceFiber.memoizedState = null;
  14023. }
  14024. }
  14025. var hasInvisibleParentBoundary = hasSuspenseContext(
  14026. suspenseStackCursor.current,
  14027. InvisibleParentSuspenseContext
  14028. ); // Schedule the nearest Suspense to re-render the timed out view.
  14029. var _workInProgress = returnFiber;
  14030. do {
  14031. if (
  14032. _workInProgress.tag === SuspenseComponent &&
  14033. shouldCaptureSuspense(_workInProgress, hasInvisibleParentBoundary)
  14034. ) {
  14035. // Found the nearest boundary.
  14036. // Stash the promise on the boundary fiber. If the boundary times out, we'll
  14037. // attach another listener to flip the boundary back to its normal state.
  14038. var thenables = _workInProgress.updateQueue;
  14039. if (thenables === null) {
  14040. var updateQueue = new Set();
  14041. updateQueue.add(thenable);
  14042. _workInProgress.updateQueue = updateQueue;
  14043. } else {
  14044. thenables.add(thenable);
  14045. } // If the boundary is outside of blocking mode, we should *not*
  14046. // suspend the commit. Pretend as if the suspended component rendered
  14047. // null and keep rendering. In the commit phase, we'll schedule a
  14048. // subsequent synchronous update to re-render the Suspense.
  14049. //
  14050. // Note: It doesn't matter whether the component that suspended was
  14051. // inside a blocking mode tree. If the Suspense is outside of it, we
  14052. // should *not* suspend the commit.
  14053. if ((_workInProgress.mode & BlockingMode) === NoMode) {
  14054. _workInProgress.effectTag |= DidCapture; // We're going to commit this fiber even though it didn't complete.
  14055. // But we shouldn't call any lifecycle methods or callbacks. Remove
  14056. // all lifecycle effect tags.
  14057. sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
  14058. if (sourceFiber.tag === ClassComponent) {
  14059. var currentSourceFiber = sourceFiber.alternate;
  14060. if (currentSourceFiber === null) {
  14061. // This is a new mount. Change the tag so it's not mistaken for a
  14062. // completed class component. For example, we should not call
  14063. // componentWillUnmount if it is deleted.
  14064. sourceFiber.tag = IncompleteClassComponent;
  14065. } else {
  14066. // When we try rendering again, we should not reuse the current fiber,
  14067. // since it's known to be in an inconsistent state. Use a force update to
  14068. // prevent a bail out.
  14069. var update = createUpdate(Sync, null);
  14070. update.tag = ForceUpdate;
  14071. enqueueUpdate(sourceFiber, update);
  14072. }
  14073. } // The source fiber did not complete. Mark it with Sync priority to
  14074. // indicate that it still has pending work.
  14075. sourceFiber.expirationTime = Sync; // Exit without suspending.
  14076. return;
  14077. } // Confirmed that the boundary is in a concurrent mode tree. Continue
  14078. // with the normal suspend path.
  14079. //
  14080. // After this we'll use a set of heuristics to determine whether this
  14081. // render pass will run to completion or restart or "suspend" the commit.
  14082. // The actual logic for this is spread out in different places.
  14083. //
  14084. // This first principle is that if we're going to suspend when we complete
  14085. // a root, then we should also restart if we get an update or ping that
  14086. // might unsuspend it, and vice versa. The only reason to suspend is
  14087. // because you think you might want to restart before committing. However,
  14088. // it doesn't make sense to restart only while in the period we're suspended.
  14089. //
  14090. // Restarting too aggressively is also not good because it starves out any
  14091. // intermediate loading state. So we use heuristics to determine when.
  14092. // Suspense Heuristics
  14093. //
  14094. // If nothing threw a Promise or all the same fallbacks are already showing,
  14095. // then don't suspend/restart.
  14096. //
  14097. // If this is an initial render of a new tree of Suspense boundaries and
  14098. // those trigger a fallback, then don't suspend/restart. We want to ensure
  14099. // that we can show the initial loading state as quickly as possible.
  14100. //
  14101. // If we hit a "Delayed" case, such as when we'd switch from content back into
  14102. // a fallback, then we should always suspend/restart. SuspenseConfig applies to
  14103. // this case. If none is defined, JND is used instead.
  14104. //
  14105. // If we're already showing a fallback and it gets "retried", allowing us to show
  14106. // another level, but there's still an inner boundary that would show a fallback,
  14107. // then we suspend/restart for 500ms since the last time we showed a fallback
  14108. // anywhere in the tree. This effectively throttles progressive loading into a
  14109. // consistent train of commits. This also gives us an opportunity to restart to
  14110. // get to the completed state slightly earlier.
  14111. //
  14112. // If there's ambiguity due to batching it's resolved in preference of:
  14113. // 1) "delayed", 2) "initial render", 3) "retry".
  14114. //
  14115. // We want to ensure that a "busy" state doesn't get force committed. We want to
  14116. // ensure that new initial loading states can commit as soon as possible.
  14117. attachPingListener(root, renderExpirationTime, thenable);
  14118. _workInProgress.effectTag |= ShouldCapture;
  14119. _workInProgress.expirationTime = renderExpirationTime;
  14120. return;
  14121. } // This boundary already captured during this render. Continue to the next
  14122. // boundary.
  14123. _workInProgress = _workInProgress.return;
  14124. } while (_workInProgress !== null); // No boundary was found. Fallthrough to error mode.
  14125. // TODO: Use invariant so the message is stripped in prod?
  14126. value = new Error(
  14127. (getComponentName(sourceFiber.type) || "A React component") +
  14128. " suspended while rendering, but no fallback UI was specified.\n" +
  14129. "\n" +
  14130. "Add a <Suspense fallback=...> component higher in the tree to " +
  14131. "provide a loading indicator or placeholder to display." +
  14132. getStackByFiberInDevAndProd(sourceFiber)
  14133. );
  14134. } // We didn't find a boundary that could handle this type of exception. Start
  14135. // over and traverse parent path again, this time treating the exception
  14136. // as an error.
  14137. renderDidError();
  14138. value = createCapturedValue(value, sourceFiber);
  14139. var workInProgress = returnFiber;
  14140. do {
  14141. switch (workInProgress.tag) {
  14142. case HostRoot: {
  14143. var _errorInfo = value;
  14144. workInProgress.effectTag |= ShouldCapture;
  14145. workInProgress.expirationTime = renderExpirationTime;
  14146. var _update = createRootErrorUpdate(
  14147. workInProgress,
  14148. _errorInfo,
  14149. renderExpirationTime
  14150. );
  14151. enqueueCapturedUpdate(workInProgress, _update);
  14152. return;
  14153. }
  14154. case ClassComponent:
  14155. // Capture and retry
  14156. var errorInfo = value;
  14157. var ctor = workInProgress.type;
  14158. var instance = workInProgress.stateNode;
  14159. if (
  14160. (workInProgress.effectTag & DidCapture) === NoEffect &&
  14161. (typeof ctor.getDerivedStateFromError === "function" ||
  14162. (instance !== null &&
  14163. typeof instance.componentDidCatch === "function" &&
  14164. !isAlreadyFailedLegacyErrorBoundary(instance)))
  14165. ) {
  14166. workInProgress.effectTag |= ShouldCapture;
  14167. workInProgress.expirationTime = renderExpirationTime; // Schedule the error boundary to re-render using updated state
  14168. var _update2 = createClassErrorUpdate(
  14169. workInProgress,
  14170. errorInfo,
  14171. renderExpirationTime
  14172. );
  14173. enqueueCapturedUpdate(workInProgress, _update2);
  14174. return;
  14175. }
  14176. break;
  14177. }
  14178. workInProgress = workInProgress.return;
  14179. } while (workInProgress !== null);
  14180. }
  14181. var ceil = Math.ceil;
  14182. var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher,
  14183. ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner,
  14184. IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing;
  14185. var NoContext =
  14186. /* */
  14187. 0;
  14188. var BatchedContext =
  14189. /* */
  14190. 1;
  14191. var DiscreteEventContext =
  14192. /* */
  14193. 4;
  14194. var LegacyUnbatchedContext =
  14195. /* */
  14196. 8;
  14197. var RenderContext =
  14198. /* */
  14199. 16;
  14200. var CommitContext =
  14201. /* */
  14202. 32;
  14203. var RootIncomplete = 0;
  14204. var RootFatalErrored = 1;
  14205. var RootErrored = 2;
  14206. var RootSuspended = 3;
  14207. var RootSuspendedWithDelay = 4;
  14208. var RootCompleted = 5;
  14209. // Describes where we are in the React execution stack
  14210. var executionContext = NoContext; // The root we're working on
  14211. var workInProgressRoot = null; // The fiber we're working on
  14212. var workInProgress = null; // The expiration time we're rendering
  14213. var renderExpirationTime$1 = NoWork; // Whether to root completed, errored, suspended, etc.
  14214. var workInProgressRootExitStatus = RootIncomplete; // A fatal error, if one is thrown
  14215. var workInProgressRootFatalError = null; // Most recent event time among processed updates during this render.
  14216. // This is conceptually a time stamp but expressed in terms of an ExpirationTime
  14217. // because we deal mostly with expiration times in the hot path, so this avoids
  14218. // the conversion happening in the hot path.
  14219. var workInProgressRootLatestProcessedExpirationTime = Sync;
  14220. var workInProgressRootLatestSuspenseTimeout = Sync;
  14221. var workInProgressRootCanSuspendUsingConfig = null; // The work left over by components that were visited during this render. Only
  14222. // includes unprocessed updates, not work in bailed out children.
  14223. var workInProgressRootNextUnprocessedUpdateTime = NoWork; // If we're pinged while rendering we don't always restart immediately.
  14224. // This flag determines if it might be worthwhile to restart if an opportunity
  14225. // happens latere.
  14226. var workInProgressRootHasPendingPing = false; // The most recent time we committed a fallback. This lets us ensure a train
  14227. // model where we don't commit new loading states in too quick succession.
  14228. var globalMostRecentFallbackTime = 0;
  14229. var FALLBACK_THROTTLE_MS = 500;
  14230. var nextEffect = null;
  14231. var hasUncaughtError = false;
  14232. var firstUncaughtError = null;
  14233. var legacyErrorBoundariesThatAlreadyFailed = null;
  14234. var rootDoesHavePassiveEffects = false;
  14235. var rootWithPendingPassiveEffects = null;
  14236. var pendingPassiveEffectsRenderPriority = NoPriority;
  14237. var pendingPassiveEffectsExpirationTime = NoWork;
  14238. var rootsWithPendingDiscreteUpdates = null; // Use these to prevent an infinite loop of nested updates
  14239. var NESTED_UPDATE_LIMIT = 50;
  14240. var nestedUpdateCount = 0;
  14241. var rootWithNestedUpdates = null;
  14242. var NESTED_PASSIVE_UPDATE_LIMIT = 50;
  14243. var nestedPassiveUpdateCount = 0;
  14244. var interruptedBy = null; // Marks the need to reschedule pending interactions at these expiration times
  14245. // during the commit phase. This enables them to be traced across components
  14246. // that spawn new work during render. E.g. hidden boundaries, suspended SSR
  14247. // hydration or SuspenseList.
  14248. var spawnedWorkDuringRender = null; // Expiration times are computed by adding to the current time (the start
  14249. // time). However, if two updates are scheduled within the same event, we
  14250. // should treat their start times as simultaneous, even if the actual clock
  14251. // time has advanced between the first and second call.
  14252. // In other words, because expiration times determine how updates are batched,
  14253. // we want all updates of like priority that occur within the same event to
  14254. // receive the same expiration time. Otherwise we get tearing.
  14255. var currentEventTime = NoWork;
  14256. function requestCurrentTimeForUpdate() {
  14257. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  14258. // We're inside React, so it's fine to read the actual time.
  14259. return msToExpirationTime(now());
  14260. } // We're not inside React, so we may be in the middle of a browser event.
  14261. if (currentEventTime !== NoWork) {
  14262. // Use the same start time for all updates until we enter React again.
  14263. return currentEventTime;
  14264. } // This is the first update since React yielded. Compute a new start time.
  14265. currentEventTime = msToExpirationTime(now());
  14266. return currentEventTime;
  14267. }
  14268. function getCurrentTime() {
  14269. return msToExpirationTime(now());
  14270. }
  14271. function computeExpirationForFiber(currentTime, fiber, suspenseConfig) {
  14272. var mode = fiber.mode;
  14273. if ((mode & BlockingMode) === NoMode) {
  14274. return Sync;
  14275. }
  14276. var priorityLevel = getCurrentPriorityLevel();
  14277. if ((mode & ConcurrentMode) === NoMode) {
  14278. return priorityLevel === ImmediatePriority ? Sync : Batched;
  14279. }
  14280. if ((executionContext & RenderContext) !== NoContext) {
  14281. // Use whatever time we're already rendering
  14282. // TODO: Should there be a way to opt out, like with `runWithPriority`?
  14283. return renderExpirationTime$1;
  14284. }
  14285. var expirationTime;
  14286. if (suspenseConfig !== null) {
  14287. // Compute an expiration time based on the Suspense timeout.
  14288. expirationTime = computeSuspenseExpiration(
  14289. currentTime,
  14290. suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION
  14291. );
  14292. } else {
  14293. // Compute an expiration time based on the Scheduler priority.
  14294. switch (priorityLevel) {
  14295. case ImmediatePriority:
  14296. expirationTime = Sync;
  14297. break;
  14298. case UserBlockingPriority:
  14299. // TODO: Rename this to computeUserBlockingExpiration
  14300. expirationTime = computeInteractiveExpiration(currentTime);
  14301. break;
  14302. case NormalPriority:
  14303. case LowPriority:
  14304. // TODO: Handle LowPriority
  14305. // TODO: Rename this to... something better.
  14306. expirationTime = computeAsyncExpiration(currentTime);
  14307. break;
  14308. case IdlePriority:
  14309. expirationTime = Idle;
  14310. break;
  14311. default: {
  14312. throw Error("Expected a valid priority level");
  14313. }
  14314. }
  14315. } // If we're in the middle of rendering a tree, do not update at the same
  14316. // expiration time that is already rendering.
  14317. // TODO: We shouldn't have to do this if the update is on a different root.
  14318. // Refactor computeExpirationForFiber + scheduleUpdate so we have access to
  14319. // the root when we check for this condition.
  14320. if (
  14321. workInProgressRoot !== null &&
  14322. expirationTime === renderExpirationTime$1
  14323. ) {
  14324. // This is a trick to move this update into a separate batch
  14325. expirationTime -= 1;
  14326. }
  14327. return expirationTime;
  14328. }
  14329. function scheduleUpdateOnFiber(fiber, expirationTime) {
  14330. checkForNestedUpdates();
  14331. warnAboutRenderPhaseUpdatesInDEV(fiber);
  14332. var root = markUpdateTimeFromFiberToRoot(fiber, expirationTime);
  14333. if (root === null) {
  14334. warnAboutUpdateOnUnmountedFiberInDEV(fiber);
  14335. return;
  14336. }
  14337. checkForInterruption(fiber, expirationTime);
  14338. recordScheduleUpdate(); // TODO: computeExpirationForFiber also reads the priority. Pass the
  14339. // priority as an argument to that function and this one.
  14340. var priorityLevel = getCurrentPriorityLevel();
  14341. if (expirationTime === Sync) {
  14342. if (
  14343. // Check if we're inside unbatchedUpdates
  14344. (executionContext & LegacyUnbatchedContext) !== NoContext && // Check if we're not already rendering
  14345. (executionContext & (RenderContext | CommitContext)) === NoContext
  14346. ) {
  14347. // Register pending interactions on the root to avoid losing traced interaction data.
  14348. schedulePendingInteractions(root, expirationTime); // This is a legacy edge case. The initial mount of a ReactDOM.render-ed
  14349. // root inside of batchedUpdates should be synchronous, but layout updates
  14350. // should be deferred until the end of the batch.
  14351. performSyncWorkOnRoot(root);
  14352. } else {
  14353. ensureRootIsScheduled(root);
  14354. schedulePendingInteractions(root, expirationTime);
  14355. if (executionContext === NoContext) {
  14356. // Flush the synchronous work now, unless we're already working or inside
  14357. // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
  14358. // scheduleCallbackForFiber to preserve the ability to schedule a callback
  14359. // without immediately flushing it. We only do this for user-initiated
  14360. // updates, to preserve historical behavior of legacy mode.
  14361. flushSyncCallbackQueue();
  14362. }
  14363. }
  14364. } else {
  14365. ensureRootIsScheduled(root);
  14366. schedulePendingInteractions(root, expirationTime);
  14367. }
  14368. if (
  14369. (executionContext & DiscreteEventContext) !== NoContext && // Only updates at user-blocking priority or greater are considered
  14370. // discrete, even inside a discrete event.
  14371. (priorityLevel === UserBlockingPriority ||
  14372. priorityLevel === ImmediatePriority)
  14373. ) {
  14374. // This is the result of a discrete event. Track the lowest priority
  14375. // discrete update per root so we can flush them early, if needed.
  14376. if (rootsWithPendingDiscreteUpdates === null) {
  14377. rootsWithPendingDiscreteUpdates = new Map([[root, expirationTime]]);
  14378. } else {
  14379. var lastDiscreteTime = rootsWithPendingDiscreteUpdates.get(root);
  14380. if (lastDiscreteTime === undefined || lastDiscreteTime > expirationTime) {
  14381. rootsWithPendingDiscreteUpdates.set(root, expirationTime);
  14382. }
  14383. }
  14384. }
  14385. }
  14386. var scheduleWork = scheduleUpdateOnFiber; // This is split into a separate function so we can mark a fiber with pending
  14387. // work without treating it as a typical update that originates from an event;
  14388. // e.g. retrying a Suspense boundary isn't an update, but it does schedule work
  14389. // on a fiber.
  14390. function markUpdateTimeFromFiberToRoot(fiber, expirationTime) {
  14391. // Update the source fiber's expiration time
  14392. if (fiber.expirationTime < expirationTime) {
  14393. fiber.expirationTime = expirationTime;
  14394. }
  14395. var alternate = fiber.alternate;
  14396. if (alternate !== null && alternate.expirationTime < expirationTime) {
  14397. alternate.expirationTime = expirationTime;
  14398. } // Walk the parent path to the root and update the child expiration time.
  14399. var node = fiber.return;
  14400. var root = null;
  14401. if (node === null && fiber.tag === HostRoot) {
  14402. root = fiber.stateNode;
  14403. } else {
  14404. while (node !== null) {
  14405. alternate = node.alternate;
  14406. if (node.childExpirationTime < expirationTime) {
  14407. node.childExpirationTime = expirationTime;
  14408. if (
  14409. alternate !== null &&
  14410. alternate.childExpirationTime < expirationTime
  14411. ) {
  14412. alternate.childExpirationTime = expirationTime;
  14413. }
  14414. } else if (
  14415. alternate !== null &&
  14416. alternate.childExpirationTime < expirationTime
  14417. ) {
  14418. alternate.childExpirationTime = expirationTime;
  14419. }
  14420. if (node.return === null && node.tag === HostRoot) {
  14421. root = node.stateNode;
  14422. break;
  14423. }
  14424. node = node.return;
  14425. }
  14426. }
  14427. if (root !== null) {
  14428. if (workInProgressRoot === root) {
  14429. // Received an update to a tree that's in the middle of rendering. Mark
  14430. // that's unprocessed work on this root.
  14431. markUnprocessedUpdateTime(expirationTime);
  14432. if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
  14433. // The root already suspended with a delay, which means this render
  14434. // definitely won't finish. Since we have a new update, let's mark it as
  14435. // suspended now, right before marking the incoming update. This has the
  14436. // effect of interrupting the current render and switching to the update.
  14437. // TODO: This happens to work when receiving an update during the render
  14438. // phase, because of the trick inside computeExpirationForFiber to
  14439. // subtract 1 from `renderExpirationTime` to move it into a
  14440. // separate bucket. But we should probably model it with an exception,
  14441. // using the same mechanism we use to force hydration of a subtree.
  14442. // TODO: This does not account for low pri updates that were already
  14443. // scheduled before the root started rendering. Need to track the next
  14444. // pending expiration time (perhaps by backtracking the return path) and
  14445. // then trigger a restart in the `renderDidSuspendDelayIfPossible` path.
  14446. markRootSuspendedAtTime(root, renderExpirationTime$1);
  14447. }
  14448. } // Mark that the root has a pending update.
  14449. markRootUpdatedAtTime(root, expirationTime);
  14450. }
  14451. return root;
  14452. }
  14453. function getNextRootExpirationTimeToWorkOn(root) {
  14454. // Determines the next expiration time that the root should render, taking
  14455. // into account levels that may be suspended, or levels that may have
  14456. // received a ping.
  14457. var lastExpiredTime = root.lastExpiredTime;
  14458. if (lastExpiredTime !== NoWork) {
  14459. return lastExpiredTime;
  14460. } // "Pending" refers to any update that hasn't committed yet, including if it
  14461. // suspended. The "suspended" range is therefore a subset.
  14462. var firstPendingTime = root.firstPendingTime;
  14463. if (!isRootSuspendedAtTime(root, firstPendingTime)) {
  14464. // The highest priority pending time is not suspended. Let's work on that.
  14465. return firstPendingTime;
  14466. } // If the first pending time is suspended, check if there's a lower priority
  14467. // pending level that we know about. Or check if we received a ping. Work
  14468. // on whichever is higher priority.
  14469. var lastPingedTime = root.lastPingedTime;
  14470. var nextKnownPendingLevel = root.nextKnownPendingLevel;
  14471. var nextLevel =
  14472. lastPingedTime > nextKnownPendingLevel
  14473. ? lastPingedTime
  14474. : nextKnownPendingLevel;
  14475. if (nextLevel <= Idle && firstPendingTime !== nextLevel) {
  14476. // Don't work on Idle/Never priority unless everything else is committed.
  14477. return NoWork;
  14478. }
  14479. return nextLevel;
  14480. } // Use this function to schedule a task for a root. There's only one task per
  14481. // root; if a task was already scheduled, we'll check to make sure the
  14482. // expiration time of the existing task is the same as the expiration time of
  14483. // the next level that the root has work on. This function is called on every
  14484. // update, and right before exiting a task.
  14485. function ensureRootIsScheduled(root) {
  14486. var lastExpiredTime = root.lastExpiredTime;
  14487. if (lastExpiredTime !== NoWork) {
  14488. // Special case: Expired work should flush synchronously.
  14489. root.callbackExpirationTime = Sync;
  14490. root.callbackPriority = ImmediatePriority;
  14491. root.callbackNode = scheduleSyncCallback(
  14492. performSyncWorkOnRoot.bind(null, root)
  14493. );
  14494. return;
  14495. }
  14496. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  14497. var existingCallbackNode = root.callbackNode;
  14498. if (expirationTime === NoWork) {
  14499. // There's nothing to work on.
  14500. if (existingCallbackNode !== null) {
  14501. root.callbackNode = null;
  14502. root.callbackExpirationTime = NoWork;
  14503. root.callbackPriority = NoPriority;
  14504. }
  14505. return;
  14506. } // TODO: If this is an update, we already read the current time. Pass the
  14507. // time as an argument.
  14508. var currentTime = requestCurrentTimeForUpdate();
  14509. var priorityLevel = inferPriorityFromExpirationTime(
  14510. currentTime,
  14511. expirationTime
  14512. ); // If there's an existing render task, confirm it has the correct priority and
  14513. // expiration time. Otherwise, we'll cancel it and schedule a new one.
  14514. if (existingCallbackNode !== null) {
  14515. var existingCallbackPriority = root.callbackPriority;
  14516. var existingCallbackExpirationTime = root.callbackExpirationTime;
  14517. if (
  14518. // Callback must have the exact same expiration time.
  14519. existingCallbackExpirationTime === expirationTime && // Callback must have greater or equal priority.
  14520. existingCallbackPriority >= priorityLevel
  14521. ) {
  14522. // Existing callback is sufficient.
  14523. return;
  14524. } // Need to schedule a new task.
  14525. // TODO: Instead of scheduling a new task, we should be able to change the
  14526. // priority of the existing one.
  14527. cancelCallback(existingCallbackNode);
  14528. }
  14529. root.callbackExpirationTime = expirationTime;
  14530. root.callbackPriority = priorityLevel;
  14531. var callbackNode;
  14532. if (expirationTime === Sync) {
  14533. // Sync React callbacks are scheduled on a special internal queue
  14534. callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
  14535. } else {
  14536. callbackNode = scheduleCallback(
  14537. priorityLevel,
  14538. performConcurrentWorkOnRoot.bind(null, root), // Compute a task timeout based on the expiration time. This also affects
  14539. // ordering because tasks are processed in timeout order.
  14540. {
  14541. timeout: expirationTimeToMs(expirationTime) - now()
  14542. }
  14543. );
  14544. }
  14545. root.callbackNode = callbackNode;
  14546. } // This is the entry point for every concurrent task, i.e. anything that
  14547. // goes through Scheduler.
  14548. function performConcurrentWorkOnRoot(root, didTimeout) {
  14549. // Since we know we're in a React event, we can clear the current
  14550. // event time. The next update will compute a new event time.
  14551. currentEventTime = NoWork; // Check if the render expired.
  14552. if (didTimeout) {
  14553. // The render task took too long to complete. Mark the current time as
  14554. // expired to synchronously render all expired work in a single batch.
  14555. var currentTime = requestCurrentTimeForUpdate();
  14556. markRootExpiredAtTime(root, currentTime); // This will schedule a synchronous callback.
  14557. ensureRootIsScheduled(root);
  14558. return null;
  14559. } // Determine the next expiration time to work on, using the fields stored
  14560. // on the root.
  14561. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  14562. if (expirationTime === NoWork) {
  14563. return null;
  14564. }
  14565. var originalCallbackNode = root.callbackNode;
  14566. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  14567. throw Error("Should not already be working.");
  14568. }
  14569. flushPassiveEffects();
  14570. var exitStatus = renderRootConcurrent(root, expirationTime);
  14571. if (exitStatus !== RootIncomplete) {
  14572. if (exitStatus === RootErrored) {
  14573. // If something threw an error, try rendering one more time. We'll
  14574. // render synchronously to block concurrent data mutations, and we'll
  14575. // render at Idle (or lower) so that all pending updates are included.
  14576. // If it still fails after the second attempt, we'll give up and commit
  14577. // the resulting tree.
  14578. expirationTime = expirationTime > Idle ? Idle : expirationTime;
  14579. exitStatus = renderRootSync(root, expirationTime);
  14580. }
  14581. if (exitStatus === RootFatalErrored) {
  14582. var fatalError = workInProgressRootFatalError;
  14583. prepareFreshStack(root, expirationTime);
  14584. markRootSuspendedAtTime(root, expirationTime);
  14585. ensureRootIsScheduled(root);
  14586. throw fatalError;
  14587. } // We now have a consistent tree. The next step is either to commit it,
  14588. // or, if something suspended, wait to commit it after a timeout.
  14589. var finishedWork = (root.finishedWork = root.current.alternate);
  14590. root.finishedExpirationTime = expirationTime;
  14591. finishConcurrentRender(root, finishedWork, exitStatus, expirationTime);
  14592. }
  14593. ensureRootIsScheduled(root);
  14594. if (root.callbackNode === originalCallbackNode) {
  14595. // The task node scheduled for this root is the same one that's
  14596. // currently executed. Need to return a continuation.
  14597. return performConcurrentWorkOnRoot.bind(null, root);
  14598. }
  14599. return null;
  14600. }
  14601. function finishConcurrentRender(
  14602. root,
  14603. finishedWork,
  14604. exitStatus,
  14605. expirationTime
  14606. ) {
  14607. switch (exitStatus) {
  14608. case RootIncomplete:
  14609. case RootFatalErrored: {
  14610. {
  14611. throw Error("Root did not complete. This is a bug in React.");
  14612. }
  14613. }
  14614. // Flow knows about invariant, so it complains if I add a break
  14615. // statement, but eslint doesn't know about invariant, so it complains
  14616. // if I do. eslint-disable-next-line no-fallthrough
  14617. case RootErrored: {
  14618. // We should have already attempted to retry this tree. If we reached
  14619. // this point, it errored again. Commit it.
  14620. commitRoot(root);
  14621. break;
  14622. }
  14623. case RootSuspended: {
  14624. markRootSuspendedAtTime(root, expirationTime);
  14625. var lastSuspendedTime = root.lastSuspendedTime;
  14626. if (expirationTime === lastSuspendedTime) {
  14627. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  14628. } // We have an acceptable loading state. We need to figure out if we
  14629. // should immediately commit it or wait a bit.
  14630. // If we have processed new updates during this render, we may now
  14631. // have a new loading state ready. We want to ensure that we commit
  14632. // that as soon as possible.
  14633. var hasNotProcessedNewUpdates =
  14634. workInProgressRootLatestProcessedExpirationTime === Sync;
  14635. if (
  14636. hasNotProcessedNewUpdates && // do not delay if we're inside an act() scope
  14637. !IsThisRendererActing.current
  14638. ) {
  14639. // If we have not processed any new updates during this pass, then
  14640. // this is either a retry of an existing fallback state or a
  14641. // hidden tree. Hidden trees shouldn't be batched with other work
  14642. // and after that's fixed it can only be a retry. We're going to
  14643. // throttle committing retries so that we don't show too many
  14644. // loading states too quickly.
  14645. var msUntilTimeout =
  14646. globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now(); // Don't bother with a very short suspense time.
  14647. if (msUntilTimeout > 10) {
  14648. if (workInProgressRootHasPendingPing) {
  14649. var lastPingedTime = root.lastPingedTime;
  14650. if (lastPingedTime === NoWork || lastPingedTime >= expirationTime) {
  14651. // This render was pinged but we didn't get to restart
  14652. // earlier so try restarting now instead.
  14653. root.lastPingedTime = expirationTime;
  14654. prepareFreshStack(root, expirationTime);
  14655. break;
  14656. }
  14657. }
  14658. var nextTime = getNextRootExpirationTimeToWorkOn(root);
  14659. if (nextTime !== NoWork && nextTime !== expirationTime) {
  14660. // There's additional work on this root.
  14661. break;
  14662. }
  14663. if (
  14664. lastSuspendedTime !== NoWork &&
  14665. lastSuspendedTime !== expirationTime
  14666. ) {
  14667. // We should prefer to render the fallback of at the last
  14668. // suspended level. Ping the last suspended level to try
  14669. // rendering it again.
  14670. root.lastPingedTime = lastSuspendedTime;
  14671. break;
  14672. } // The render is suspended, it hasn't timed out, and there's no
  14673. // lower priority work to do. Instead of committing the fallback
  14674. // immediately, wait for more data to arrive.
  14675. root.timeoutHandle = scheduleTimeout(
  14676. commitRoot.bind(null, root),
  14677. msUntilTimeout
  14678. );
  14679. break;
  14680. }
  14681. } // The work expired. Commit immediately.
  14682. commitRoot(root);
  14683. break;
  14684. }
  14685. case RootSuspendedWithDelay: {
  14686. markRootSuspendedAtTime(root, expirationTime);
  14687. var _lastSuspendedTime = root.lastSuspendedTime;
  14688. if (expirationTime === _lastSuspendedTime) {
  14689. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  14690. }
  14691. {
  14692. // We're suspended in a state that should be avoided. We'll try to
  14693. // avoid committing it for as long as the timeouts let us.
  14694. if (workInProgressRootHasPendingPing) {
  14695. var _lastPingedTime = root.lastPingedTime;
  14696. if (_lastPingedTime === NoWork || _lastPingedTime >= expirationTime) {
  14697. // This render was pinged but we didn't get to restart earlier
  14698. // so try restarting now instead.
  14699. root.lastPingedTime = expirationTime;
  14700. prepareFreshStack(root, expirationTime);
  14701. break;
  14702. }
  14703. }
  14704. var _nextTime = getNextRootExpirationTimeToWorkOn(root);
  14705. if (_nextTime !== NoWork && _nextTime !== expirationTime) {
  14706. // There's additional work on this root.
  14707. break;
  14708. }
  14709. if (
  14710. _lastSuspendedTime !== NoWork &&
  14711. _lastSuspendedTime !== expirationTime
  14712. ) {
  14713. // We should prefer to render the fallback of at the last
  14714. // suspended level. Ping the last suspended level to try
  14715. // rendering it again.
  14716. root.lastPingedTime = _lastSuspendedTime;
  14717. break;
  14718. }
  14719. var _msUntilTimeout;
  14720. if (workInProgressRootLatestSuspenseTimeout !== Sync) {
  14721. // We have processed a suspense config whose expiration time we
  14722. // can use as the timeout.
  14723. _msUntilTimeout =
  14724. expirationTimeToMs(workInProgressRootLatestSuspenseTimeout) - now();
  14725. } else if (workInProgressRootLatestProcessedExpirationTime === Sync) {
  14726. // This should never normally happen because only new updates
  14727. // cause delayed states, so we should have processed something.
  14728. // However, this could also happen in an offscreen tree.
  14729. _msUntilTimeout = 0;
  14730. } else {
  14731. // If we don't have a suspense config, we're going to use a
  14732. // heuristic to determine how long we can suspend.
  14733. var eventTimeMs = inferTimeFromExpirationTime(
  14734. workInProgressRootLatestProcessedExpirationTime
  14735. );
  14736. var currentTimeMs = now();
  14737. var timeUntilExpirationMs =
  14738. expirationTimeToMs(expirationTime) - currentTimeMs;
  14739. var timeElapsed = currentTimeMs - eventTimeMs;
  14740. if (timeElapsed < 0) {
  14741. // We get this wrong some time since we estimate the time.
  14742. timeElapsed = 0;
  14743. }
  14744. _msUntilTimeout = jnd(timeElapsed) - timeElapsed; // Clamp the timeout to the expiration time. TODO: Once the
  14745. // event time is exact instead of inferred from expiration time
  14746. // we don't need this.
  14747. if (timeUntilExpirationMs < _msUntilTimeout) {
  14748. _msUntilTimeout = timeUntilExpirationMs;
  14749. }
  14750. } // Don't bother with a very short suspense time.
  14751. if (_msUntilTimeout > 10) {
  14752. // The render is suspended, it hasn't timed out, and there's no
  14753. // lower priority work to do. Instead of committing the fallback
  14754. // immediately, wait for more data to arrive.
  14755. root.timeoutHandle = scheduleTimeout(
  14756. commitRoot.bind(null, root),
  14757. _msUntilTimeout
  14758. );
  14759. break;
  14760. }
  14761. } // The work expired. Commit immediately.
  14762. commitRoot(root);
  14763. break;
  14764. }
  14765. case RootCompleted: {
  14766. // The work completed. Ready to commit.
  14767. if (
  14768. // do not delay if we're inside an act() scope
  14769. workInProgressRootLatestProcessedExpirationTime !== Sync &&
  14770. workInProgressRootCanSuspendUsingConfig !== null
  14771. ) {
  14772. // If we have exceeded the minimum loading delay, which probably
  14773. // means we have shown a spinner already, we might have to suspend
  14774. // a bit longer to ensure that the spinner is shown for
  14775. // enough time.
  14776. var _msUntilTimeout2 = computeMsUntilSuspenseLoadingDelay(
  14777. workInProgressRootLatestProcessedExpirationTime,
  14778. expirationTime,
  14779. workInProgressRootCanSuspendUsingConfig
  14780. );
  14781. if (_msUntilTimeout2 > 10) {
  14782. markRootSuspendedAtTime(root, expirationTime);
  14783. root.timeoutHandle = scheduleTimeout(
  14784. commitRoot.bind(null, root),
  14785. _msUntilTimeout2
  14786. );
  14787. break;
  14788. }
  14789. }
  14790. commitRoot(root);
  14791. break;
  14792. }
  14793. default: {
  14794. {
  14795. throw Error("Unknown root exit status.");
  14796. }
  14797. }
  14798. }
  14799. } // This is the entry point for synchronous tasks that don't go
  14800. // through Scheduler
  14801. function performSyncWorkOnRoot(root) {
  14802. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  14803. throw Error("Should not already be working.");
  14804. }
  14805. flushPassiveEffects();
  14806. var lastExpiredTime = root.lastExpiredTime;
  14807. var expirationTime;
  14808. if (lastExpiredTime !== NoWork) {
  14809. // There's expired work on this root. Check if we have a partial tree
  14810. // that we can reuse.
  14811. if (
  14812. root === workInProgressRoot &&
  14813. renderExpirationTime$1 >= lastExpiredTime
  14814. ) {
  14815. // There's a partial tree with equal or greater than priority than the
  14816. // expired level. Finish rendering it before rendering the rest of the
  14817. // expired work.
  14818. expirationTime = renderExpirationTime$1;
  14819. } else {
  14820. // Start a fresh tree.
  14821. expirationTime = lastExpiredTime;
  14822. }
  14823. } else {
  14824. // There's no expired work. This must be a new, synchronous render.
  14825. expirationTime = Sync;
  14826. }
  14827. var exitStatus = renderRootSync(root, expirationTime);
  14828. if (root.tag !== LegacyRoot && exitStatus === RootErrored) {
  14829. // If something threw an error, try rendering one more time. We'll
  14830. // render synchronously to block concurrent data mutations, and we'll
  14831. // render at Idle (or lower) so that all pending updates are included.
  14832. // If it still fails after the second attempt, we'll give up and commit
  14833. // the resulting tree.
  14834. expirationTime = expirationTime > Idle ? Idle : expirationTime;
  14835. exitStatus = renderRootSync(root, expirationTime);
  14836. }
  14837. if (exitStatus === RootFatalErrored) {
  14838. var fatalError = workInProgressRootFatalError;
  14839. prepareFreshStack(root, expirationTime);
  14840. markRootSuspendedAtTime(root, expirationTime);
  14841. ensureRootIsScheduled(root);
  14842. throw fatalError;
  14843. } // We now have a consistent tree. Because this is a sync render, we
  14844. // will commit it even if something suspended.
  14845. root.finishedWork = root.current.alternate;
  14846. root.finishedExpirationTime = expirationTime;
  14847. commitRoot(root); // Before exiting, make sure there's a callback scheduled for the next
  14848. // pending level.
  14849. ensureRootIsScheduled(root);
  14850. return null;
  14851. }
  14852. function syncUpdates(fn, a, b, c) {
  14853. return runWithPriority(ImmediatePriority, fn.bind(null, a, b, c));
  14854. }
  14855. function batchedUpdates$1(fn, a) {
  14856. var prevExecutionContext = executionContext;
  14857. executionContext |= BatchedContext;
  14858. try {
  14859. return fn(a);
  14860. } finally {
  14861. executionContext = prevExecutionContext;
  14862. if (executionContext === NoContext) {
  14863. // Flush the immediate callbacks that were scheduled during this batch
  14864. flushSyncCallbackQueue();
  14865. }
  14866. }
  14867. }
  14868. function flushSync(fn, a) {
  14869. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  14870. {
  14871. throw Error(
  14872. "flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering."
  14873. );
  14874. }
  14875. }
  14876. var prevExecutionContext = executionContext;
  14877. executionContext |= BatchedContext;
  14878. try {
  14879. return runWithPriority(ImmediatePriority, fn.bind(null, a));
  14880. } finally {
  14881. executionContext = prevExecutionContext; // Flush the immediate callbacks that were scheduled during this batch.
  14882. // Note that this will happen even if batchedUpdates is higher up
  14883. // the stack.
  14884. flushSyncCallbackQueue();
  14885. }
  14886. }
  14887. function prepareFreshStack(root, expirationTime) {
  14888. root.finishedWork = null;
  14889. root.finishedExpirationTime = NoWork;
  14890. var timeoutHandle = root.timeoutHandle;
  14891. if (timeoutHandle !== noTimeout) {
  14892. // The root previous suspended and scheduled a timeout to commit a fallback
  14893. // state. Now that we have additional work, cancel the timeout.
  14894. root.timeoutHandle = noTimeout; // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
  14895. cancelTimeout(timeoutHandle);
  14896. }
  14897. if (workInProgress !== null) {
  14898. var interruptedWork = workInProgress.return;
  14899. while (interruptedWork !== null) {
  14900. unwindInterruptedWork(interruptedWork);
  14901. interruptedWork = interruptedWork.return;
  14902. }
  14903. }
  14904. workInProgressRoot = root;
  14905. workInProgress = createWorkInProgress(root.current, null);
  14906. renderExpirationTime$1 = expirationTime;
  14907. workInProgressRootExitStatus = RootIncomplete;
  14908. workInProgressRootFatalError = null;
  14909. workInProgressRootLatestProcessedExpirationTime = Sync;
  14910. workInProgressRootLatestSuspenseTimeout = Sync;
  14911. workInProgressRootCanSuspendUsingConfig = null;
  14912. workInProgressRootNextUnprocessedUpdateTime = NoWork;
  14913. workInProgressRootHasPendingPing = false;
  14914. {
  14915. spawnedWorkDuringRender = null;
  14916. }
  14917. {
  14918. ReactStrictModeWarnings.discardPendingWarnings();
  14919. }
  14920. }
  14921. function handleError(root, thrownValue) {
  14922. do {
  14923. try {
  14924. // Reset module-level state that was set during the render phase.
  14925. resetContextDependencies();
  14926. resetHooksAfterThrow();
  14927. resetCurrentFiber();
  14928. if (workInProgress === null || workInProgress.return === null) {
  14929. // Expected to be working on a non-root fiber. This is a fatal error
  14930. // because there's no ancestor that can handle it; the root is
  14931. // supposed to capture all errors that weren't caught by an error
  14932. // boundary.
  14933. workInProgressRootExitStatus = RootFatalErrored;
  14934. workInProgressRootFatalError = thrownValue; // Set `workInProgress` to null. This represents advancing to the next
  14935. // sibling, or the parent if there are no siblings. But since the root
  14936. // has no siblings nor a parent, we set it to null. Usually this is
  14937. // handled by `completeUnitOfWork` or `unwindWork`, but since we're
  14938. // interntionally not calling those, we need set it here.
  14939. // TODO: Consider calling `unwindWork` to pop the contexts.
  14940. workInProgress = null;
  14941. return null;
  14942. }
  14943. if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
  14944. // Record the time spent rendering before an error was thrown. This
  14945. // avoids inaccurate Profiler durations in the case of a
  14946. // suspended render.
  14947. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
  14948. }
  14949. throwException(
  14950. root,
  14951. workInProgress.return,
  14952. workInProgress,
  14953. thrownValue,
  14954. renderExpirationTime$1
  14955. );
  14956. workInProgress = completeUnitOfWork(workInProgress);
  14957. } catch (yetAnotherThrownValue) {
  14958. // Something in the return path also threw.
  14959. thrownValue = yetAnotherThrownValue;
  14960. continue;
  14961. } // Return to the normal work loop.
  14962. return;
  14963. } while (true);
  14964. }
  14965. function pushDispatcher(root) {
  14966. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14967. ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
  14968. if (prevDispatcher === null) {
  14969. // The React isomorphic package does not include a default dispatcher.
  14970. // Instead the first renderer will lazily attach one, in order to give
  14971. // nicer error messages.
  14972. return ContextOnlyDispatcher;
  14973. } else {
  14974. return prevDispatcher;
  14975. }
  14976. }
  14977. function popDispatcher(prevDispatcher) {
  14978. ReactCurrentDispatcher$1.current = prevDispatcher;
  14979. }
  14980. function pushInteractions(root) {
  14981. {
  14982. var prevInteractions = tracing.__interactionsRef.current;
  14983. tracing.__interactionsRef.current = root.memoizedInteractions;
  14984. return prevInteractions;
  14985. }
  14986. }
  14987. function popInteractions(prevInteractions) {
  14988. {
  14989. tracing.__interactionsRef.current = prevInteractions;
  14990. }
  14991. }
  14992. function markCommitTimeOfFallback() {
  14993. globalMostRecentFallbackTime = now();
  14994. }
  14995. function markRenderEventTimeAndConfig(expirationTime, suspenseConfig) {
  14996. if (
  14997. expirationTime < workInProgressRootLatestProcessedExpirationTime &&
  14998. expirationTime > Idle
  14999. ) {
  15000. workInProgressRootLatestProcessedExpirationTime = expirationTime;
  15001. }
  15002. if (suspenseConfig !== null) {
  15003. if (
  15004. expirationTime < workInProgressRootLatestSuspenseTimeout &&
  15005. expirationTime > Idle
  15006. ) {
  15007. workInProgressRootLatestSuspenseTimeout = expirationTime; // Most of the time we only have one config and getting wrong is not bad.
  15008. workInProgressRootCanSuspendUsingConfig = suspenseConfig;
  15009. }
  15010. }
  15011. }
  15012. function markUnprocessedUpdateTime(expirationTime) {
  15013. if (expirationTime > workInProgressRootNextUnprocessedUpdateTime) {
  15014. workInProgressRootNextUnprocessedUpdateTime = expirationTime;
  15015. }
  15016. }
  15017. function renderDidSuspend() {
  15018. if (workInProgressRootExitStatus === RootIncomplete) {
  15019. workInProgressRootExitStatus = RootSuspended;
  15020. }
  15021. }
  15022. function renderDidSuspendDelayIfPossible() {
  15023. if (
  15024. workInProgressRootExitStatus === RootIncomplete ||
  15025. workInProgressRootExitStatus === RootSuspended
  15026. ) {
  15027. workInProgressRootExitStatus = RootSuspendedWithDelay;
  15028. } // Check if there's a lower priority update somewhere else in the tree.
  15029. if (
  15030. workInProgressRootNextUnprocessedUpdateTime !== NoWork &&
  15031. workInProgressRoot !== null
  15032. ) {
  15033. // Mark the current render as suspended, and then mark that there's a
  15034. // pending update.
  15035. // TODO: This should immediately interrupt the current render, instead
  15036. // of waiting until the next time we yield.
  15037. markRootSuspendedAtTime(workInProgressRoot, renderExpirationTime$1);
  15038. markRootUpdatedAtTime(
  15039. workInProgressRoot,
  15040. workInProgressRootNextUnprocessedUpdateTime
  15041. );
  15042. }
  15043. }
  15044. function renderDidError() {
  15045. if (workInProgressRootExitStatus !== RootCompleted) {
  15046. workInProgressRootExitStatus = RootErrored;
  15047. }
  15048. } // Called during render to determine if anything has suspended.
  15049. // Returns false if we're not sure.
  15050. function renderHasNotSuspendedYet() {
  15051. // If something errored or completed, we can't really be sure,
  15052. // so those are false.
  15053. return workInProgressRootExitStatus === RootIncomplete;
  15054. }
  15055. function inferTimeFromExpirationTime(expirationTime) {
  15056. // We don't know exactly when the update was scheduled, but we can infer an
  15057. // approximate start time from the expiration time.
  15058. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  15059. return earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
  15060. }
  15061. function inferTimeFromExpirationTimeWithSuspenseConfig(
  15062. expirationTime,
  15063. suspenseConfig
  15064. ) {
  15065. // We don't know exactly when the update was scheduled, but we can infer an
  15066. // approximate start time from the expiration time by subtracting the timeout
  15067. // that was added to the event time.
  15068. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  15069. return (
  15070. earliestExpirationTimeMs -
  15071. (suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION)
  15072. );
  15073. }
  15074. function renderRootSync(root, expirationTime) {
  15075. var prevExecutionContext = executionContext;
  15076. executionContext |= RenderContext;
  15077. var prevDispatcher = pushDispatcher(); // If the root or expiration time have changed, throw out the existing stack
  15078. // and prepare a fresh one. Otherwise we'll continue where we left off.
  15079. if (
  15080. root !== workInProgressRoot ||
  15081. expirationTime !== renderExpirationTime$1
  15082. ) {
  15083. prepareFreshStack(root, expirationTime);
  15084. startWorkOnPendingInteractions(root, expirationTime);
  15085. }
  15086. var prevInteractions = pushInteractions(root);
  15087. startWorkLoopTimer(workInProgress);
  15088. do {
  15089. try {
  15090. workLoopSync();
  15091. break;
  15092. } catch (thrownValue) {
  15093. handleError(root, thrownValue);
  15094. }
  15095. } while (true);
  15096. resetContextDependencies();
  15097. {
  15098. popInteractions(prevInteractions);
  15099. }
  15100. executionContext = prevExecutionContext;
  15101. popDispatcher(prevDispatcher);
  15102. if (workInProgress !== null) {
  15103. // This is a sync render, so we should have finished the whole tree.
  15104. {
  15105. throw Error(
  15106. "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue."
  15107. );
  15108. }
  15109. }
  15110. stopFinishedWorkLoopTimer(); // Set this to null to indicate there's no in-progress render.
  15111. workInProgressRoot = null;
  15112. return workInProgressRootExitStatus;
  15113. } // The work loop is an extremely hot path. Tell Closure not to inline it.
  15114. /** @noinline */
  15115. function workLoopSync() {
  15116. // Already timed out, so perform work without checking if we need to yield.
  15117. while (workInProgress !== null) {
  15118. workInProgress = performUnitOfWork(workInProgress);
  15119. }
  15120. }
  15121. function renderRootConcurrent(root, expirationTime) {
  15122. var prevExecutionContext = executionContext;
  15123. executionContext |= RenderContext;
  15124. var prevDispatcher = pushDispatcher(); // If the root or expiration time have changed, throw out the existing stack
  15125. // and prepare a fresh one. Otherwise we'll continue where we left off.
  15126. if (
  15127. root !== workInProgressRoot ||
  15128. expirationTime !== renderExpirationTime$1
  15129. ) {
  15130. prepareFreshStack(root, expirationTime);
  15131. startWorkOnPendingInteractions(root, expirationTime);
  15132. }
  15133. var prevInteractions = pushInteractions(root);
  15134. startWorkLoopTimer(workInProgress);
  15135. do {
  15136. try {
  15137. workLoopConcurrent();
  15138. break;
  15139. } catch (thrownValue) {
  15140. handleError(root, thrownValue);
  15141. }
  15142. } while (true);
  15143. resetContextDependencies();
  15144. {
  15145. popInteractions(prevInteractions);
  15146. }
  15147. popDispatcher(prevDispatcher);
  15148. executionContext = prevExecutionContext; // Check if the tree has completed.
  15149. if (workInProgress !== null) {
  15150. // Still work remaining.
  15151. stopInterruptedWorkLoopTimer();
  15152. return RootIncomplete;
  15153. } else {
  15154. // Completed the tree.
  15155. stopFinishedWorkLoopTimer(); // Set this to null to indicate there's no in-progress render.
  15156. workInProgressRoot = null; // Return the final exit status.
  15157. return workInProgressRootExitStatus;
  15158. }
  15159. }
  15160. /** @noinline */
  15161. function workLoopConcurrent() {
  15162. // Perform work until Scheduler asks us to yield
  15163. while (workInProgress !== null && !shouldYield()) {
  15164. workInProgress = performUnitOfWork(workInProgress);
  15165. }
  15166. }
  15167. function performUnitOfWork(unitOfWork) {
  15168. // The current, flushed, state of this fiber is the alternate. Ideally
  15169. // nothing should rely on this, but relying on it here means that we don't
  15170. // need an additional field on the work in progress.
  15171. var current = unitOfWork.alternate;
  15172. startWorkTimer(unitOfWork);
  15173. setCurrentFiber(unitOfWork);
  15174. var next;
  15175. if ((unitOfWork.mode & ProfileMode) !== NoMode) {
  15176. startProfilerTimer(unitOfWork);
  15177. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  15178. stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, true);
  15179. } else {
  15180. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  15181. }
  15182. resetCurrentFiber();
  15183. unitOfWork.memoizedProps = unitOfWork.pendingProps;
  15184. if (next === null) {
  15185. // If this doesn't spawn new work, complete the current work.
  15186. next = completeUnitOfWork(unitOfWork);
  15187. }
  15188. ReactCurrentOwner$2.current = null;
  15189. return next;
  15190. }
  15191. function completeUnitOfWork(unitOfWork) {
  15192. // Attempt to complete the current unit of work, then move to the next
  15193. // sibling. If there are no more siblings, return to the parent fiber.
  15194. workInProgress = unitOfWork;
  15195. do {
  15196. // The current, flushed, state of this fiber is the alternate. Ideally
  15197. // nothing should rely on this, but relying on it here means that we don't
  15198. // need an additional field on the work in progress.
  15199. var current = workInProgress.alternate;
  15200. var returnFiber = workInProgress.return; // Check if the work completed or if something threw.
  15201. if ((workInProgress.effectTag & Incomplete) === NoEffect) {
  15202. setCurrentFiber(workInProgress);
  15203. var next = void 0;
  15204. if ((workInProgress.mode & ProfileMode) === NoMode) {
  15205. next = completeWork(current, workInProgress, renderExpirationTime$1);
  15206. } else {
  15207. startProfilerTimer(workInProgress);
  15208. next = completeWork(current, workInProgress, renderExpirationTime$1); // Update render duration assuming we didn't error.
  15209. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
  15210. }
  15211. stopWorkTimer(workInProgress);
  15212. resetCurrentFiber();
  15213. resetChildExpirationTime(workInProgress);
  15214. if (next !== null) {
  15215. // Completing this fiber spawned new work. Work on that next.
  15216. return next;
  15217. }
  15218. if (
  15219. returnFiber !== null && // Do not append effects to parents if a sibling failed to complete
  15220. (returnFiber.effectTag & Incomplete) === NoEffect
  15221. ) {
  15222. // Append all the effects of the subtree and this fiber onto the effect
  15223. // list of the parent. The completion order of the children affects the
  15224. // side-effect order.
  15225. if (returnFiber.firstEffect === null) {
  15226. returnFiber.firstEffect = workInProgress.firstEffect;
  15227. }
  15228. if (workInProgress.lastEffect !== null) {
  15229. if (returnFiber.lastEffect !== null) {
  15230. returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
  15231. }
  15232. returnFiber.lastEffect = workInProgress.lastEffect;
  15233. } // If this fiber had side-effects, we append it AFTER the children's
  15234. // side-effects. We can perform certain side-effects earlier if needed,
  15235. // by doing multiple passes over the effect list. We don't want to
  15236. // schedule our own side-effect on our own list because if end up
  15237. // reusing children we'll schedule this effect onto itself since we're
  15238. // at the end.
  15239. var effectTag = workInProgress.effectTag; // Skip both NoWork and PerformedWork tags when creating the effect
  15240. // list. PerformedWork effect is read by React DevTools but shouldn't be
  15241. // committed.
  15242. if (effectTag > PerformedWork) {
  15243. if (returnFiber.lastEffect !== null) {
  15244. returnFiber.lastEffect.nextEffect = workInProgress;
  15245. } else {
  15246. returnFiber.firstEffect = workInProgress;
  15247. }
  15248. returnFiber.lastEffect = workInProgress;
  15249. }
  15250. }
  15251. } else {
  15252. // This fiber did not complete because something threw. Pop values off
  15253. // the stack without entering the complete phase. If this is a boundary,
  15254. // capture values if possible.
  15255. var _next = unwindWork(workInProgress); // Because this fiber did not complete, don't reset its expiration time.
  15256. if ((workInProgress.mode & ProfileMode) !== NoMode) {
  15257. // Record the render duration for the fiber that errored.
  15258. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false); // Include the time spent working on failed children before continuing.
  15259. var actualDuration = workInProgress.actualDuration;
  15260. var child = workInProgress.child;
  15261. while (child !== null) {
  15262. actualDuration += child.actualDuration;
  15263. child = child.sibling;
  15264. }
  15265. workInProgress.actualDuration = actualDuration;
  15266. }
  15267. if (_next !== null) {
  15268. // If completing this work spawned new work, do that next. We'll come
  15269. // back here again.
  15270. // Since we're restarting, remove anything that is not a host effect
  15271. // from the effect tag.
  15272. // TODO: The name stopFailedWorkTimer is misleading because Suspense
  15273. // also captures and restarts.
  15274. stopFailedWorkTimer(workInProgress);
  15275. _next.effectTag &= HostEffectMask;
  15276. return _next;
  15277. }
  15278. stopWorkTimer(workInProgress);
  15279. if (returnFiber !== null) {
  15280. // Mark the parent fiber as incomplete and clear its effect list.
  15281. returnFiber.firstEffect = returnFiber.lastEffect = null;
  15282. returnFiber.effectTag |= Incomplete;
  15283. }
  15284. }
  15285. var siblingFiber = workInProgress.sibling;
  15286. if (siblingFiber !== null) {
  15287. // If there is more work to do in this returnFiber, do that next.
  15288. return siblingFiber;
  15289. } // Otherwise, return to the parent
  15290. workInProgress = returnFiber;
  15291. } while (workInProgress !== null); // We've reached the root.
  15292. if (workInProgressRootExitStatus === RootIncomplete) {
  15293. workInProgressRootExitStatus = RootCompleted;
  15294. }
  15295. return null;
  15296. }
  15297. function getRemainingExpirationTime(fiber) {
  15298. var updateExpirationTime = fiber.expirationTime;
  15299. var childExpirationTime = fiber.childExpirationTime;
  15300. return updateExpirationTime > childExpirationTime
  15301. ? updateExpirationTime
  15302. : childExpirationTime;
  15303. }
  15304. function resetChildExpirationTime(completedWork) {
  15305. if (
  15306. renderExpirationTime$1 !== Never &&
  15307. completedWork.childExpirationTime === Never
  15308. ) {
  15309. // The children of this component are hidden. Don't bubble their
  15310. // expiration times.
  15311. return;
  15312. }
  15313. var newChildExpirationTime = NoWork; // Bubble up the earliest expiration time.
  15314. if ((completedWork.mode & ProfileMode) !== NoMode) {
  15315. // In profiling mode, resetChildExpirationTime is also used to reset
  15316. // profiler durations.
  15317. var actualDuration = completedWork.actualDuration;
  15318. var treeBaseDuration = completedWork.selfBaseDuration; // When a fiber is cloned, its actualDuration is reset to 0. This value will
  15319. // only be updated if work is done on the fiber (i.e. it doesn't bailout).
  15320. // When work is done, it should bubble to the parent's actualDuration. If
  15321. // the fiber has not been cloned though, (meaning no work was done), then
  15322. // this value will reflect the amount of time spent working on a previous
  15323. // render. In that case it should not bubble. We determine whether it was
  15324. // cloned by comparing the child pointer.
  15325. var shouldBubbleActualDurations =
  15326. completedWork.alternate === null ||
  15327. completedWork.child !== completedWork.alternate.child;
  15328. var child = completedWork.child;
  15329. while (child !== null) {
  15330. var childUpdateExpirationTime = child.expirationTime;
  15331. var childChildExpirationTime = child.childExpirationTime;
  15332. if (childUpdateExpirationTime > newChildExpirationTime) {
  15333. newChildExpirationTime = childUpdateExpirationTime;
  15334. }
  15335. if (childChildExpirationTime > newChildExpirationTime) {
  15336. newChildExpirationTime = childChildExpirationTime;
  15337. }
  15338. if (shouldBubbleActualDurations) {
  15339. actualDuration += child.actualDuration;
  15340. }
  15341. treeBaseDuration += child.treeBaseDuration;
  15342. child = child.sibling;
  15343. }
  15344. completedWork.actualDuration = actualDuration;
  15345. completedWork.treeBaseDuration = treeBaseDuration;
  15346. } else {
  15347. var _child = completedWork.child;
  15348. while (_child !== null) {
  15349. var _childUpdateExpirationTime = _child.expirationTime;
  15350. var _childChildExpirationTime = _child.childExpirationTime;
  15351. if (_childUpdateExpirationTime > newChildExpirationTime) {
  15352. newChildExpirationTime = _childUpdateExpirationTime;
  15353. }
  15354. if (_childChildExpirationTime > newChildExpirationTime) {
  15355. newChildExpirationTime = _childChildExpirationTime;
  15356. }
  15357. _child = _child.sibling;
  15358. }
  15359. }
  15360. completedWork.childExpirationTime = newChildExpirationTime;
  15361. }
  15362. function commitRoot(root) {
  15363. var renderPriorityLevel = getCurrentPriorityLevel();
  15364. runWithPriority(
  15365. ImmediatePriority,
  15366. commitRootImpl.bind(null, root, renderPriorityLevel)
  15367. );
  15368. return null;
  15369. }
  15370. function commitRootImpl(root, renderPriorityLevel) {
  15371. do {
  15372. // `flushPassiveEffects` will call `flushSyncUpdateQueue` at the end, which
  15373. // means `flushPassiveEffects` will sometimes result in additional
  15374. // passive effects. So we need to keep flushing in a loop until there are
  15375. // no more pending effects.
  15376. // TODO: Might be better if `flushPassiveEffects` did not automatically
  15377. // flush synchronous work at the end, to avoid factoring hazards like this.
  15378. flushPassiveEffects();
  15379. } while (rootWithPendingPassiveEffects !== null);
  15380. flushRenderPhaseStrictModeWarningsInDEV();
  15381. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  15382. throw Error("Should not already be working.");
  15383. }
  15384. var finishedWork = root.finishedWork;
  15385. var expirationTime = root.finishedExpirationTime;
  15386. if (finishedWork === null) {
  15387. return null;
  15388. }
  15389. root.finishedWork = null;
  15390. root.finishedExpirationTime = NoWork;
  15391. if (!(finishedWork !== root.current)) {
  15392. throw Error(
  15393. "Cannot commit the same tree as before. This error is likely caused by a bug in React. Please file an issue."
  15394. );
  15395. } // commitRoot never returns a continuation; it always finishes synchronously.
  15396. // So we can clear these now to allow a new callback to be scheduled.
  15397. root.callbackNode = null;
  15398. root.callbackExpirationTime = NoWork;
  15399. root.callbackPriority = NoPriority;
  15400. root.nextKnownPendingLevel = NoWork;
  15401. startCommitTimer(); // Update the first and last pending times on this root. The new first
  15402. // pending time is whatever is left on the root fiber.
  15403. var remainingExpirationTimeBeforeCommit = getRemainingExpirationTime(
  15404. finishedWork
  15405. );
  15406. markRootFinishedAtTime(
  15407. root,
  15408. expirationTime,
  15409. remainingExpirationTimeBeforeCommit
  15410. );
  15411. if (root === workInProgressRoot) {
  15412. // We can reset these now that they are finished.
  15413. workInProgressRoot = null;
  15414. workInProgress = null;
  15415. renderExpirationTime$1 = NoWork;
  15416. } // This indicates that the last root we worked on is not the same one that
  15417. // we're committing now. This most commonly happens when a suspended root
  15418. // times out.
  15419. // Get the list of effects.
  15420. var firstEffect;
  15421. if (finishedWork.effectTag > PerformedWork) {
  15422. // A fiber's effect list consists only of its children, not itself. So if
  15423. // the root has an effect, we need to add it to the end of the list. The
  15424. // resulting list is the set that would belong to the root's parent, if it
  15425. // had one; that is, all the effects in the tree including the root.
  15426. if (finishedWork.lastEffect !== null) {
  15427. finishedWork.lastEffect.nextEffect = finishedWork;
  15428. firstEffect = finishedWork.firstEffect;
  15429. } else {
  15430. firstEffect = finishedWork;
  15431. }
  15432. } else {
  15433. // There is no effect on the root.
  15434. firstEffect = finishedWork.firstEffect;
  15435. }
  15436. if (firstEffect !== null) {
  15437. var prevExecutionContext = executionContext;
  15438. executionContext |= CommitContext;
  15439. var prevInteractions = pushInteractions(root); // Reset this to null before calling lifecycles
  15440. ReactCurrentOwner$2.current = null; // The commit phase is broken into several sub-phases. We do a separate pass
  15441. // of the effect list for each phase: all mutation effects come before all
  15442. // layout effects, and so on.
  15443. // The first phase a "before mutation" phase. We use this phase to read the
  15444. // state of the host tree right before we mutate it. This is where
  15445. // getSnapshotBeforeUpdate is called.
  15446. startCommitSnapshotEffectsTimer();
  15447. prepareForCommit(root.containerInfo);
  15448. nextEffect = firstEffect;
  15449. do {
  15450. {
  15451. invokeGuardedCallback(null, commitBeforeMutationEffects, null);
  15452. if (hasCaughtError()) {
  15453. if (!(nextEffect !== null)) {
  15454. throw Error("Should be working on an effect.");
  15455. }
  15456. var error = clearCaughtError();
  15457. captureCommitPhaseError(nextEffect, error);
  15458. nextEffect = nextEffect.nextEffect;
  15459. }
  15460. }
  15461. } while (nextEffect !== null);
  15462. stopCommitSnapshotEffectsTimer();
  15463. {
  15464. // Mark the current commit time to be shared by all Profilers in this
  15465. // batch. This enables them to be grouped later.
  15466. recordCommitTime();
  15467. } // The next phase is the mutation phase, where we mutate the host tree.
  15468. startCommitHostEffectsTimer();
  15469. nextEffect = firstEffect;
  15470. do {
  15471. {
  15472. invokeGuardedCallback(
  15473. null,
  15474. commitMutationEffects,
  15475. null,
  15476. root,
  15477. renderPriorityLevel
  15478. );
  15479. if (hasCaughtError()) {
  15480. if (!(nextEffect !== null)) {
  15481. throw Error("Should be working on an effect.");
  15482. }
  15483. var _error = clearCaughtError();
  15484. captureCommitPhaseError(nextEffect, _error);
  15485. nextEffect = nextEffect.nextEffect;
  15486. }
  15487. }
  15488. } while (nextEffect !== null);
  15489. stopCommitHostEffectsTimer();
  15490. resetAfterCommit(root.containerInfo); // The work-in-progress tree is now the current tree. This must come after
  15491. // the mutation phase, so that the previous tree is still current during
  15492. // componentWillUnmount, but before the layout phase, so that the finished
  15493. // work is current during componentDidMount/Update.
  15494. root.current = finishedWork; // The next phase is the layout phase, where we call effects that read
  15495. // the host tree after it's been mutated. The idiomatic use case for this is
  15496. // layout, but class component lifecycles also fire here for legacy reasons.
  15497. startCommitLifeCyclesTimer();
  15498. nextEffect = firstEffect;
  15499. do {
  15500. {
  15501. invokeGuardedCallback(
  15502. null,
  15503. commitLayoutEffects,
  15504. null,
  15505. root,
  15506. expirationTime
  15507. );
  15508. if (hasCaughtError()) {
  15509. if (!(nextEffect !== null)) {
  15510. throw Error("Should be working on an effect.");
  15511. }
  15512. var _error2 = clearCaughtError();
  15513. captureCommitPhaseError(nextEffect, _error2);
  15514. nextEffect = nextEffect.nextEffect;
  15515. }
  15516. }
  15517. } while (nextEffect !== null);
  15518. stopCommitLifeCyclesTimer();
  15519. nextEffect = null; // Tell Scheduler to yield at the end of the frame, so the browser has an
  15520. // opportunity to paint.
  15521. requestPaint();
  15522. {
  15523. popInteractions(prevInteractions);
  15524. }
  15525. executionContext = prevExecutionContext;
  15526. } else {
  15527. // No effects.
  15528. root.current = finishedWork; // Measure these anyway so the flamegraph explicitly shows that there were
  15529. // no effects.
  15530. // TODO: Maybe there's a better way to report this.
  15531. startCommitSnapshotEffectsTimer();
  15532. stopCommitSnapshotEffectsTimer();
  15533. {
  15534. recordCommitTime();
  15535. }
  15536. startCommitHostEffectsTimer();
  15537. stopCommitHostEffectsTimer();
  15538. startCommitLifeCyclesTimer();
  15539. stopCommitLifeCyclesTimer();
  15540. }
  15541. stopCommitTimer();
  15542. var rootDidHavePassiveEffects = rootDoesHavePassiveEffects;
  15543. if (rootDoesHavePassiveEffects) {
  15544. // This commit has passive effects. Stash a reference to them. But don't
  15545. // schedule a callback until after flushing layout work.
  15546. rootDoesHavePassiveEffects = false;
  15547. rootWithPendingPassiveEffects = root;
  15548. pendingPassiveEffectsExpirationTime = expirationTime;
  15549. pendingPassiveEffectsRenderPriority = renderPriorityLevel;
  15550. } else {
  15551. // We are done with the effect chain at this point so let's clear the
  15552. // nextEffect pointers to assist with GC. If we have passive effects, we'll
  15553. // clear this in flushPassiveEffects.
  15554. nextEffect = firstEffect;
  15555. while (nextEffect !== null) {
  15556. var nextNextEffect = nextEffect.nextEffect;
  15557. nextEffect.nextEffect = null;
  15558. nextEffect = nextNextEffect;
  15559. }
  15560. } // Check if there's remaining work on this root
  15561. var remainingExpirationTime = root.firstPendingTime;
  15562. if (remainingExpirationTime !== NoWork) {
  15563. {
  15564. if (spawnedWorkDuringRender !== null) {
  15565. var expirationTimes = spawnedWorkDuringRender;
  15566. spawnedWorkDuringRender = null;
  15567. for (var i = 0; i < expirationTimes.length; i++) {
  15568. scheduleInteractions(
  15569. root,
  15570. expirationTimes[i],
  15571. root.memoizedInteractions
  15572. );
  15573. }
  15574. }
  15575. schedulePendingInteractions(root, remainingExpirationTime);
  15576. }
  15577. } else {
  15578. // If there's no remaining work, we can clear the set of already failed
  15579. // error boundaries.
  15580. legacyErrorBoundariesThatAlreadyFailed = null;
  15581. }
  15582. {
  15583. if (!rootDidHavePassiveEffects) {
  15584. // If there are no passive effects, then we can complete the pending interactions.
  15585. // Otherwise, we'll wait until after the passive effects are flushed.
  15586. // Wait to do this until after remaining work has been scheduled,
  15587. // so that we don't prematurely signal complete for interactions when there's e.g. hidden work.
  15588. finishPendingInteractions(root, expirationTime);
  15589. }
  15590. }
  15591. if (remainingExpirationTime === Sync) {
  15592. // Count the number of times the root synchronously re-renders without
  15593. // finishing. If there are too many, it indicates an infinite update loop.
  15594. if (root === rootWithNestedUpdates) {
  15595. nestedUpdateCount++;
  15596. } else {
  15597. nestedUpdateCount = 0;
  15598. rootWithNestedUpdates = root;
  15599. }
  15600. } else {
  15601. nestedUpdateCount = 0;
  15602. }
  15603. onCommitRoot(finishedWork.stateNode, expirationTime); // Always call this before exiting `commitRoot`, to ensure that any
  15604. // additional work on this root is scheduled.
  15605. ensureRootIsScheduled(root);
  15606. if (hasUncaughtError) {
  15607. hasUncaughtError = false;
  15608. var _error3 = firstUncaughtError;
  15609. firstUncaughtError = null;
  15610. throw _error3;
  15611. }
  15612. if ((executionContext & LegacyUnbatchedContext) !== NoContext) {
  15613. // This is a legacy edge case. We just committed the initial mount of
  15614. // a ReactDOM.render-ed root inside of batchedUpdates. The commit fired
  15615. // synchronously, but layout updates should be deferred until the end
  15616. // of the batch.
  15617. return null;
  15618. } // If layout work was scheduled, flush it now.
  15619. flushSyncCallbackQueue();
  15620. return null;
  15621. }
  15622. function commitBeforeMutationEffects() {
  15623. while (nextEffect !== null) {
  15624. var effectTag = nextEffect.effectTag;
  15625. if ((effectTag & Snapshot) !== NoEffect) {
  15626. setCurrentFiber(nextEffect);
  15627. recordEffect();
  15628. var current = nextEffect.alternate;
  15629. commitBeforeMutationLifeCycles(current, nextEffect);
  15630. resetCurrentFiber();
  15631. }
  15632. if ((effectTag & Passive) !== NoEffect) {
  15633. // If there are passive effects, schedule a callback to flush at
  15634. // the earliest opportunity.
  15635. if (!rootDoesHavePassiveEffects) {
  15636. rootDoesHavePassiveEffects = true;
  15637. scheduleCallback(NormalPriority, function() {
  15638. flushPassiveEffects();
  15639. return null;
  15640. });
  15641. }
  15642. }
  15643. nextEffect = nextEffect.nextEffect;
  15644. }
  15645. }
  15646. function commitMutationEffects(root, renderPriorityLevel) {
  15647. // TODO: Should probably move the bulk of this function to commitWork.
  15648. while (nextEffect !== null) {
  15649. setCurrentFiber(nextEffect);
  15650. var effectTag = nextEffect.effectTag;
  15651. if (effectTag & Ref) {
  15652. var current = nextEffect.alternate;
  15653. if (current !== null) {
  15654. commitDetachRef(current);
  15655. }
  15656. } // The following switch statement is only concerned about placement,
  15657. // updates, and deletions. To avoid needing to add a case for every possible
  15658. // bitmap value, we remove the secondary effects from the effect tag and
  15659. // switch on that value.
  15660. var primaryEffectTag =
  15661. effectTag & (Placement | Update | Deletion | Hydrating);
  15662. switch (primaryEffectTag) {
  15663. case Placement: {
  15664. // inserted, before any life-cycles like componentDidMount gets called.
  15665. // TODO: findDOMNode doesn't rely on this any more but isMounted does
  15666. // and isMounted is deprecated anyway so we should be able to kill this.
  15667. nextEffect.effectTag &= ~Placement;
  15668. break;
  15669. }
  15670. case PlacementAndUpdate: {
  15671. // inserted, before any life-cycles like componentDidMount gets called.
  15672. nextEffect.effectTag &= ~Placement; // Update
  15673. var _current = nextEffect.alternate;
  15674. commitWork(_current, nextEffect);
  15675. break;
  15676. }
  15677. case Hydrating: {
  15678. nextEffect.effectTag &= ~Hydrating;
  15679. break;
  15680. }
  15681. case HydratingAndUpdate: {
  15682. nextEffect.effectTag &= ~Hydrating; // Update
  15683. var _current2 = nextEffect.alternate;
  15684. commitWork(_current2, nextEffect);
  15685. break;
  15686. }
  15687. case Update: {
  15688. var _current3 = nextEffect.alternate;
  15689. commitWork(_current3, nextEffect);
  15690. break;
  15691. }
  15692. case Deletion: {
  15693. commitDeletion(root, nextEffect, renderPriorityLevel);
  15694. break;
  15695. }
  15696. } // TODO: Only record a mutation effect if primaryEffectTag is non-zero.
  15697. recordEffect();
  15698. resetCurrentFiber();
  15699. nextEffect = nextEffect.nextEffect;
  15700. }
  15701. }
  15702. function commitLayoutEffects(root, committedExpirationTime) {
  15703. // TODO: Should probably move the bulk of this function to commitWork.
  15704. while (nextEffect !== null) {
  15705. setCurrentFiber(nextEffect);
  15706. var effectTag = nextEffect.effectTag;
  15707. if (effectTag & (Update | Callback)) {
  15708. recordEffect();
  15709. var current = nextEffect.alternate;
  15710. commitLifeCycles(root, current, nextEffect);
  15711. }
  15712. if (effectTag & Ref) {
  15713. recordEffect();
  15714. commitAttachRef(nextEffect);
  15715. }
  15716. resetCurrentFiber();
  15717. nextEffect = nextEffect.nextEffect;
  15718. }
  15719. }
  15720. function flushPassiveEffects() {
  15721. if (pendingPassiveEffectsRenderPriority !== NoPriority) {
  15722. var priorityLevel =
  15723. pendingPassiveEffectsRenderPriority > NormalPriority
  15724. ? NormalPriority
  15725. : pendingPassiveEffectsRenderPriority;
  15726. pendingPassiveEffectsRenderPriority = NoPriority;
  15727. return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
  15728. }
  15729. }
  15730. function flushPassiveEffectsImpl() {
  15731. if (rootWithPendingPassiveEffects === null) {
  15732. return false;
  15733. }
  15734. var root = rootWithPendingPassiveEffects;
  15735. var expirationTime = pendingPassiveEffectsExpirationTime;
  15736. rootWithPendingPassiveEffects = null;
  15737. pendingPassiveEffectsExpirationTime = NoWork;
  15738. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  15739. throw Error("Cannot flush passive effects while already rendering.");
  15740. }
  15741. var prevExecutionContext = executionContext;
  15742. executionContext |= CommitContext;
  15743. var prevInteractions = pushInteractions(root);
  15744. {
  15745. // Note: This currently assumes there are no passive effects on the root fiber
  15746. // because the root is not part of its own effect list.
  15747. // This could change in the future.
  15748. var _effect2 = root.current.firstEffect;
  15749. while (_effect2 !== null) {
  15750. {
  15751. setCurrentFiber(_effect2);
  15752. invokeGuardedCallback(null, commitPassiveHookEffects, null, _effect2);
  15753. if (hasCaughtError()) {
  15754. if (!(_effect2 !== null)) {
  15755. throw Error("Should be working on an effect.");
  15756. }
  15757. var _error5 = clearCaughtError();
  15758. captureCommitPhaseError(_effect2, _error5);
  15759. }
  15760. resetCurrentFiber();
  15761. }
  15762. var nextNextEffect = _effect2.nextEffect; // Remove nextEffect pointer to assist GC
  15763. _effect2.nextEffect = null;
  15764. _effect2 = nextNextEffect;
  15765. }
  15766. }
  15767. {
  15768. popInteractions(prevInteractions);
  15769. finishPendingInteractions(root, expirationTime);
  15770. }
  15771. executionContext = prevExecutionContext;
  15772. flushSyncCallbackQueue(); // If additional passive effects were scheduled, increment a counter. If this
  15773. // exceeds the limit, we'll fire a warning.
  15774. nestedPassiveUpdateCount =
  15775. rootWithPendingPassiveEffects === null ? 0 : nestedPassiveUpdateCount + 1;
  15776. return true;
  15777. }
  15778. function isAlreadyFailedLegacyErrorBoundary(instance) {
  15779. return (
  15780. legacyErrorBoundariesThatAlreadyFailed !== null &&
  15781. legacyErrorBoundariesThatAlreadyFailed.has(instance)
  15782. );
  15783. }
  15784. function markLegacyErrorBoundaryAsFailed(instance) {
  15785. if (legacyErrorBoundariesThatAlreadyFailed === null) {
  15786. legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
  15787. } else {
  15788. legacyErrorBoundariesThatAlreadyFailed.add(instance);
  15789. }
  15790. }
  15791. function prepareToThrowUncaughtError(error) {
  15792. if (!hasUncaughtError) {
  15793. hasUncaughtError = true;
  15794. firstUncaughtError = error;
  15795. }
  15796. }
  15797. var onUncaughtError = prepareToThrowUncaughtError;
  15798. function captureCommitPhaseErrorOnRoot(rootFiber, sourceFiber, error) {
  15799. var errorInfo = createCapturedValue(error, sourceFiber);
  15800. var update = createRootErrorUpdate(rootFiber, errorInfo, Sync);
  15801. enqueueUpdate(rootFiber, update);
  15802. var root = markUpdateTimeFromFiberToRoot(rootFiber, Sync);
  15803. if (root !== null) {
  15804. ensureRootIsScheduled(root);
  15805. schedulePendingInteractions(root, Sync);
  15806. }
  15807. }
  15808. function captureCommitPhaseError(sourceFiber, error) {
  15809. if (sourceFiber.tag === HostRoot) {
  15810. // Error was thrown at the root. There is no parent, so the root
  15811. // itself should capture it.
  15812. captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error);
  15813. return;
  15814. }
  15815. var fiber = sourceFiber.return;
  15816. while (fiber !== null) {
  15817. if (fiber.tag === HostRoot) {
  15818. captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
  15819. return;
  15820. } else if (fiber.tag === ClassComponent) {
  15821. var ctor = fiber.type;
  15822. var instance = fiber.stateNode;
  15823. if (
  15824. typeof ctor.getDerivedStateFromError === "function" ||
  15825. (typeof instance.componentDidCatch === "function" &&
  15826. !isAlreadyFailedLegacyErrorBoundary(instance))
  15827. ) {
  15828. var errorInfo = createCapturedValue(error, sourceFiber);
  15829. var update = createClassErrorUpdate(
  15830. fiber,
  15831. errorInfo, // TODO: This is always sync
  15832. Sync
  15833. );
  15834. enqueueUpdate(fiber, update);
  15835. var root = markUpdateTimeFromFiberToRoot(fiber, Sync);
  15836. if (root !== null) {
  15837. ensureRootIsScheduled(root);
  15838. schedulePendingInteractions(root, Sync);
  15839. }
  15840. return;
  15841. }
  15842. }
  15843. fiber = fiber.return;
  15844. }
  15845. }
  15846. function pingSuspendedRoot(root, thenable, suspendedTime) {
  15847. var pingCache = root.pingCache;
  15848. if (pingCache !== null) {
  15849. // The thenable resolved, so we no longer need to memoize, because it will
  15850. // never be thrown again.
  15851. pingCache.delete(thenable);
  15852. }
  15853. if (workInProgressRoot === root && renderExpirationTime$1 === suspendedTime) {
  15854. // Received a ping at the same priority level at which we're currently
  15855. // rendering. We might want to restart this render. This should mirror
  15856. // the logic of whether or not a root suspends once it completes.
  15857. // TODO: If we're rendering sync either due to Sync, Batched or expired,
  15858. // we should probably never restart.
  15859. // If we're suspended with delay, we'll always suspend so we can always
  15860. // restart. If we're suspended without any updates, it might be a retry.
  15861. // If it's early in the retry we can restart. We can't know for sure
  15862. // whether we'll eventually process an update during this render pass,
  15863. // but it's somewhat unlikely that we get to a ping before that, since
  15864. // getting to the root most update is usually very fast.
  15865. if (
  15866. workInProgressRootExitStatus === RootSuspendedWithDelay ||
  15867. (workInProgressRootExitStatus === RootSuspended &&
  15868. workInProgressRootLatestProcessedExpirationTime === Sync &&
  15869. now() - globalMostRecentFallbackTime < FALLBACK_THROTTLE_MS)
  15870. ) {
  15871. // Restart from the root. Don't need to schedule a ping because
  15872. // we're already working on this tree.
  15873. prepareFreshStack(root, renderExpirationTime$1);
  15874. } else {
  15875. // Even though we can't restart right now, we might get an
  15876. // opportunity later. So we mark this render as having a ping.
  15877. workInProgressRootHasPendingPing = true;
  15878. }
  15879. return;
  15880. }
  15881. if (!isRootSuspendedAtTime(root, suspendedTime)) {
  15882. // The root is no longer suspended at this time.
  15883. return;
  15884. }
  15885. var lastPingedTime = root.lastPingedTime;
  15886. if (lastPingedTime !== NoWork && lastPingedTime < suspendedTime) {
  15887. // There's already a lower priority ping scheduled.
  15888. return;
  15889. } // Mark the time at which this ping was scheduled.
  15890. root.lastPingedTime = suspendedTime;
  15891. ensureRootIsScheduled(root);
  15892. schedulePendingInteractions(root, suspendedTime);
  15893. }
  15894. function retryTimedOutBoundary(boundaryFiber, retryTime) {
  15895. // The boundary fiber (a Suspense component or SuspenseList component)
  15896. // previously was rendered in its fallback state. One of the promises that
  15897. // suspended it has resolved, which means at least part of the tree was
  15898. // likely unblocked. Try rendering again, at a new expiration time.
  15899. if (retryTime === NoWork) {
  15900. var suspenseConfig = null; // Retries don't carry over the already committed update.
  15901. var currentTime = requestCurrentTimeForUpdate();
  15902. retryTime = computeExpirationForFiber(
  15903. currentTime,
  15904. boundaryFiber,
  15905. suspenseConfig
  15906. );
  15907. } // TODO: Special case idle priority?
  15908. var root = markUpdateTimeFromFiberToRoot(boundaryFiber, retryTime);
  15909. if (root !== null) {
  15910. ensureRootIsScheduled(root);
  15911. schedulePendingInteractions(root, retryTime);
  15912. }
  15913. }
  15914. function resolveRetryThenable(boundaryFiber, thenable) {
  15915. var retryTime = NoWork; // Default
  15916. var retryCache;
  15917. {
  15918. retryCache = boundaryFiber.stateNode;
  15919. }
  15920. if (retryCache !== null) {
  15921. // The thenable resolved, so we no longer need to memoize, because it will
  15922. // never be thrown again.
  15923. retryCache.delete(thenable);
  15924. }
  15925. retryTimedOutBoundary(boundaryFiber, retryTime);
  15926. } // Computes the next Just Noticeable Difference (JND) boundary.
  15927. // The theory is that a person can't tell the difference between small differences in time.
  15928. // Therefore, if we wait a bit longer than necessary that won't translate to a noticeable
  15929. // difference in the experience. However, waiting for longer might mean that we can avoid
  15930. // showing an intermediate loading state. The longer we have already waited, the harder it
  15931. // is to tell small differences in time. Therefore, the longer we've already waited,
  15932. // the longer we can wait additionally. At some point we have to give up though.
  15933. // We pick a train model where the next boundary commits at a consistent schedule.
  15934. // These particular numbers are vague estimates. We expect to adjust them based on research.
  15935. function jnd(timeElapsed) {
  15936. return timeElapsed < 120
  15937. ? 120
  15938. : timeElapsed < 480
  15939. ? 480
  15940. : timeElapsed < 1080
  15941. ? 1080
  15942. : timeElapsed < 1920
  15943. ? 1920
  15944. : timeElapsed < 3000
  15945. ? 3000
  15946. : timeElapsed < 4320
  15947. ? 4320
  15948. : ceil(timeElapsed / 1960) * 1960;
  15949. }
  15950. function computeMsUntilSuspenseLoadingDelay(
  15951. mostRecentEventTime,
  15952. committedExpirationTime,
  15953. suspenseConfig
  15954. ) {
  15955. var busyMinDurationMs = suspenseConfig.busyMinDurationMs | 0;
  15956. if (busyMinDurationMs <= 0) {
  15957. return 0;
  15958. }
  15959. var busyDelayMs = suspenseConfig.busyDelayMs | 0; // Compute the time until this render pass would expire.
  15960. var currentTimeMs = now();
  15961. var eventTimeMs = inferTimeFromExpirationTimeWithSuspenseConfig(
  15962. mostRecentEventTime,
  15963. suspenseConfig
  15964. );
  15965. var timeElapsed = currentTimeMs - eventTimeMs;
  15966. if (timeElapsed <= busyDelayMs) {
  15967. // If we haven't yet waited longer than the initial delay, we don't
  15968. // have to wait any additional time.
  15969. return 0;
  15970. }
  15971. var msUntilTimeout = busyDelayMs + busyMinDurationMs - timeElapsed; // This is the value that is passed to `setTimeout`.
  15972. return msUntilTimeout;
  15973. }
  15974. function checkForNestedUpdates() {
  15975. if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
  15976. nestedUpdateCount = 0;
  15977. rootWithNestedUpdates = null;
  15978. {
  15979. throw Error(
  15980. "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."
  15981. );
  15982. }
  15983. }
  15984. {
  15985. if (nestedPassiveUpdateCount > NESTED_PASSIVE_UPDATE_LIMIT) {
  15986. nestedPassiveUpdateCount = 0;
  15987. error(
  15988. "Maximum update depth exceeded. This can happen when a component " +
  15989. "calls setState inside useEffect, but useEffect either doesn't " +
  15990. "have a dependency array, or one of the dependencies changes on " +
  15991. "every render."
  15992. );
  15993. }
  15994. }
  15995. }
  15996. function flushRenderPhaseStrictModeWarningsInDEV() {
  15997. {
  15998. ReactStrictModeWarnings.flushLegacyContextWarning();
  15999. {
  16000. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
  16001. }
  16002. }
  16003. }
  16004. function stopFinishedWorkLoopTimer() {
  16005. var didCompleteRoot = true;
  16006. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  16007. interruptedBy = null;
  16008. }
  16009. function stopInterruptedWorkLoopTimer() {
  16010. // TODO: Track which fiber caused the interruption.
  16011. var didCompleteRoot = false;
  16012. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  16013. interruptedBy = null;
  16014. }
  16015. function checkForInterruption(fiberThatReceivedUpdate, updateExpirationTime) {
  16016. if (
  16017. workInProgressRoot !== null &&
  16018. updateExpirationTime > renderExpirationTime$1
  16019. ) {
  16020. interruptedBy = fiberThatReceivedUpdate;
  16021. }
  16022. }
  16023. var didWarnStateUpdateForUnmountedComponent = null;
  16024. function warnAboutUpdateOnUnmountedFiberInDEV(fiber) {
  16025. {
  16026. var tag = fiber.tag;
  16027. if (
  16028. tag !== HostRoot &&
  16029. tag !== ClassComponent &&
  16030. tag !== FunctionComponent &&
  16031. tag !== ForwardRef &&
  16032. tag !== MemoComponent &&
  16033. tag !== SimpleMemoComponent &&
  16034. tag !== Block
  16035. ) {
  16036. // Only warn for user-defined components, not internal ones like Suspense.
  16037. return;
  16038. }
  16039. // the problematic code almost always lies inside that component.
  16040. var componentName = getComponentName(fiber.type) || "ReactComponent";
  16041. if (didWarnStateUpdateForUnmountedComponent !== null) {
  16042. if (didWarnStateUpdateForUnmountedComponent.has(componentName)) {
  16043. return;
  16044. }
  16045. didWarnStateUpdateForUnmountedComponent.add(componentName);
  16046. } else {
  16047. didWarnStateUpdateForUnmountedComponent = new Set([componentName]);
  16048. }
  16049. error(
  16050. "Can't perform a React state update on an unmounted component. This " +
  16051. "is a no-op, but it indicates a memory leak in your application. To " +
  16052. "fix, cancel all subscriptions and asynchronous tasks in %s.%s",
  16053. tag === ClassComponent
  16054. ? "the componentWillUnmount method"
  16055. : "a useEffect cleanup function",
  16056. getStackByFiberInDevAndProd(fiber)
  16057. );
  16058. }
  16059. }
  16060. var beginWork$1;
  16061. {
  16062. var dummyFiber = null;
  16063. beginWork$1 = function(current, unitOfWork, expirationTime) {
  16064. // If a component throws an error, we replay it again in a synchronously
  16065. // dispatched event, so that the debugger will treat it as an uncaught
  16066. // error See ReactErrorUtils for more information.
  16067. // Before entering the begin phase, copy the work-in-progress onto a dummy
  16068. // fiber. If beginWork throws, we'll use this to reset the state.
  16069. var originalWorkInProgressCopy = assignFiberPropertiesInDEV(
  16070. dummyFiber,
  16071. unitOfWork
  16072. );
  16073. try {
  16074. return beginWork(current, unitOfWork, expirationTime);
  16075. } catch (originalError) {
  16076. if (
  16077. originalError !== null &&
  16078. typeof originalError === "object" &&
  16079. typeof originalError.then === "function"
  16080. ) {
  16081. // Don't replay promises. Treat everything else like an error.
  16082. throw originalError;
  16083. } // Keep this code in sync with handleError; any changes here must have
  16084. // corresponding changes there.
  16085. resetContextDependencies();
  16086. resetHooksAfterThrow(); // Don't reset current debug fiber, since we're about to work on the
  16087. // same fiber again.
  16088. // Unwind the failed stack frame
  16089. unwindInterruptedWork(unitOfWork); // Restore the original properties of the fiber.
  16090. assignFiberPropertiesInDEV(unitOfWork, originalWorkInProgressCopy);
  16091. if (unitOfWork.mode & ProfileMode) {
  16092. // Reset the profiler timer.
  16093. startProfilerTimer(unitOfWork);
  16094. } // Run beginWork again.
  16095. invokeGuardedCallback(
  16096. null,
  16097. beginWork,
  16098. null,
  16099. current,
  16100. unitOfWork,
  16101. expirationTime
  16102. );
  16103. if (hasCaughtError()) {
  16104. var replayError = clearCaughtError(); // `invokeGuardedCallback` sometimes sets an expando `_suppressLogging`.
  16105. // Rethrow this error instead of the original one.
  16106. throw replayError;
  16107. } else {
  16108. // This branch is reachable if the render phase is impure.
  16109. throw originalError;
  16110. }
  16111. }
  16112. };
  16113. }
  16114. var didWarnAboutUpdateInRender = false;
  16115. function warnAboutRenderPhaseUpdatesInDEV(fiber) {
  16116. {
  16117. if ((executionContext & RenderContext) !== NoContext) {
  16118. switch (fiber.tag) {
  16119. case FunctionComponent:
  16120. case ForwardRef:
  16121. case SimpleMemoComponent: {
  16122. error(
  16123. "Cannot update a component from inside the function body of a " +
  16124. "different component."
  16125. );
  16126. break;
  16127. }
  16128. case ClassComponent: {
  16129. if (isRendering && !didWarnAboutUpdateInRender) {
  16130. error(
  16131. "Cannot update during an existing state transition (such as " +
  16132. "within `render`). Render methods should be a pure " +
  16133. "function of props and state."
  16134. );
  16135. didWarnAboutUpdateInRender = true;
  16136. break;
  16137. }
  16138. }
  16139. }
  16140. }
  16141. }
  16142. } // a 'shared' variable that changes when act() opens/closes in tests.
  16143. var IsThisRendererActing = {
  16144. current: false
  16145. };
  16146. var didWarnAboutUnmockedScheduler = false; // TODO Before we release concurrent mode, revisit this and decide whether a mocked
  16147. // scheduler is the actual recommendation. The alternative could be a testing build,
  16148. // a new lib, or whatever; we dunno just yet. This message is for early adopters
  16149. // to get their tests right.
  16150. function warnIfUnmockedScheduler(fiber) {
  16151. {
  16152. if (
  16153. didWarnAboutUnmockedScheduler === false &&
  16154. Scheduler.unstable_flushAllWithoutAsserting === undefined
  16155. ) {
  16156. if (fiber.mode & BlockingMode || fiber.mode & ConcurrentMode) {
  16157. didWarnAboutUnmockedScheduler = true;
  16158. error(
  16159. 'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
  16160. "to guarantee consistent behaviour across tests and browsers. " +
  16161. "For example, with jest: \n" + // Break up requires to avoid accidentally parsing them as dependencies.
  16162. "jest.mock('scheduler', () => require" +
  16163. "('scheduler/unstable_mock'));\n\n" +
  16164. "For more info, visit https://fb.me/react-mock-scheduler"
  16165. );
  16166. } else {
  16167. didWarnAboutUnmockedScheduler = true;
  16168. error(
  16169. 'Starting from React v17, the "scheduler" module will need to be mocked ' +
  16170. "to guarantee consistent behaviour across tests and browsers. " +
  16171. "For example, with jest: \n" + // Break up requires to avoid accidentally parsing them as dependencies.
  16172. "jest.mock('scheduler', () => require" +
  16173. "('scheduler/unstable_mock'));\n\n" +
  16174. "For more info, visit https://fb.me/react-mock-scheduler"
  16175. );
  16176. }
  16177. }
  16178. }
  16179. }
  16180. function computeThreadID(root, expirationTime) {
  16181. // Interaction threads are unique per root and expiration time.
  16182. return expirationTime * 1000 + root.interactionThreadID;
  16183. }
  16184. function markSpawnedWork(expirationTime) {
  16185. if (spawnedWorkDuringRender === null) {
  16186. spawnedWorkDuringRender = [expirationTime];
  16187. } else {
  16188. spawnedWorkDuringRender.push(expirationTime);
  16189. }
  16190. }
  16191. function scheduleInteractions(root, expirationTime, interactions) {
  16192. if (interactions.size > 0) {
  16193. var pendingInteractionMap = root.pendingInteractionMap;
  16194. var pendingInteractions = pendingInteractionMap.get(expirationTime);
  16195. if (pendingInteractions != null) {
  16196. interactions.forEach(function(interaction) {
  16197. if (!pendingInteractions.has(interaction)) {
  16198. // Update the pending async work count for previously unscheduled interaction.
  16199. interaction.__count++;
  16200. }
  16201. pendingInteractions.add(interaction);
  16202. });
  16203. } else {
  16204. pendingInteractionMap.set(expirationTime, new Set(interactions)); // Update the pending async work count for the current interactions.
  16205. interactions.forEach(function(interaction) {
  16206. interaction.__count++;
  16207. });
  16208. }
  16209. var subscriber = tracing.__subscriberRef.current;
  16210. if (subscriber !== null) {
  16211. var threadID = computeThreadID(root, expirationTime);
  16212. subscriber.onWorkScheduled(interactions, threadID);
  16213. }
  16214. }
  16215. }
  16216. function schedulePendingInteractions(root, expirationTime) {
  16217. scheduleInteractions(root, expirationTime, tracing.__interactionsRef.current);
  16218. }
  16219. function startWorkOnPendingInteractions(root, expirationTime) {
  16220. // we can accurately attribute time spent working on it, And so that cascading
  16221. // work triggered during the render phase will be associated with it.
  16222. var interactions = new Set();
  16223. root.pendingInteractionMap.forEach(function(
  16224. scheduledInteractions,
  16225. scheduledExpirationTime
  16226. ) {
  16227. if (scheduledExpirationTime >= expirationTime) {
  16228. scheduledInteractions.forEach(function(interaction) {
  16229. return interactions.add(interaction);
  16230. });
  16231. }
  16232. }); // Store the current set of interactions on the FiberRoot for a few reasons:
  16233. // We can re-use it in hot functions like performConcurrentWorkOnRoot()
  16234. // without having to recalculate it. We will also use it in commitWork() to
  16235. // pass to any Profiler onRender() hooks. This also provides DevTools with a
  16236. // way to access it when the onCommitRoot() hook is called.
  16237. root.memoizedInteractions = interactions;
  16238. if (interactions.size > 0) {
  16239. var subscriber = tracing.__subscriberRef.current;
  16240. if (subscriber !== null) {
  16241. var threadID = computeThreadID(root, expirationTime);
  16242. try {
  16243. subscriber.onWorkStarted(interactions, threadID);
  16244. } catch (error) {
  16245. // If the subscriber throws, rethrow it in a separate task
  16246. scheduleCallback(ImmediatePriority, function() {
  16247. throw error;
  16248. });
  16249. }
  16250. }
  16251. }
  16252. }
  16253. function finishPendingInteractions(root, committedExpirationTime) {
  16254. var earliestRemainingTimeAfterCommit = root.firstPendingTime;
  16255. var subscriber;
  16256. try {
  16257. subscriber = tracing.__subscriberRef.current;
  16258. if (subscriber !== null && root.memoizedInteractions.size > 0) {
  16259. var threadID = computeThreadID(root, committedExpirationTime);
  16260. subscriber.onWorkStopped(root.memoizedInteractions, threadID);
  16261. }
  16262. } catch (error) {
  16263. // If the subscriber throws, rethrow it in a separate task
  16264. scheduleCallback(ImmediatePriority, function() {
  16265. throw error;
  16266. });
  16267. } finally {
  16268. // Clear completed interactions from the pending Map.
  16269. // Unless the render was suspended or cascading work was scheduled,
  16270. // In which case– leave pending interactions until the subsequent render.
  16271. var pendingInteractionMap = root.pendingInteractionMap;
  16272. pendingInteractionMap.forEach(function(
  16273. scheduledInteractions,
  16274. scheduledExpirationTime
  16275. ) {
  16276. // Only decrement the pending interaction count if we're done.
  16277. // If there's still work at the current priority,
  16278. // That indicates that we are waiting for suspense data.
  16279. if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
  16280. pendingInteractionMap.delete(scheduledExpirationTime);
  16281. scheduledInteractions.forEach(function(interaction) {
  16282. interaction.__count--;
  16283. if (subscriber !== null && interaction.__count === 0) {
  16284. try {
  16285. subscriber.onInteractionScheduledWorkCompleted(interaction);
  16286. } catch (error) {
  16287. // If the subscriber throws, rethrow it in a separate task
  16288. scheduleCallback(ImmediatePriority, function() {
  16289. throw error;
  16290. });
  16291. }
  16292. }
  16293. });
  16294. }
  16295. });
  16296. }
  16297. }
  16298. var onScheduleFiberRoot = null;
  16299. var onCommitFiberRoot = null;
  16300. var onCommitFiberUnmount = null;
  16301. var hasLoggedError = false;
  16302. var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined";
  16303. function injectInternals(internals) {
  16304. if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === "undefined") {
  16305. // No DevTools
  16306. return false;
  16307. }
  16308. var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
  16309. if (hook.isDisabled) {
  16310. // This isn't a real property on the hook, but it can be set to opt out
  16311. // of DevTools integration and associated warnings and logs.
  16312. // https://github.com/facebook/react/issues/3877
  16313. return true;
  16314. }
  16315. if (!hook.supportsFiber) {
  16316. {
  16317. error(
  16318. "The installed version of React DevTools is too old and will not work " +
  16319. "with the current version of React. Please update React DevTools. " +
  16320. "https://fb.me/react-devtools"
  16321. );
  16322. } // DevTools exists, even though it doesn't support Fiber.
  16323. return true;
  16324. }
  16325. try {
  16326. var rendererID = hook.inject(internals); // We have successfully injected, so now it is safe to set up hooks.
  16327. if (true) {
  16328. // Only used by Fast Refresh
  16329. if (typeof hook.onScheduleFiberRoot === "function") {
  16330. onScheduleFiberRoot = function(root, children) {
  16331. try {
  16332. hook.onScheduleFiberRoot(rendererID, root, children);
  16333. } catch (err) {
  16334. if (true && !hasLoggedError) {
  16335. hasLoggedError = true;
  16336. error("React instrumentation encountered an error: %s", err);
  16337. }
  16338. }
  16339. };
  16340. }
  16341. }
  16342. onCommitFiberRoot = function(root, expirationTime) {
  16343. try {
  16344. var didError = (root.current.effectTag & DidCapture) === DidCapture;
  16345. if (enableProfilerTimer) {
  16346. var currentTime = getCurrentTime();
  16347. var priorityLevel = inferPriorityFromExpirationTime(
  16348. currentTime,
  16349. expirationTime
  16350. );
  16351. hook.onCommitFiberRoot(rendererID, root, priorityLevel, didError);
  16352. } else {
  16353. hook.onCommitFiberRoot(rendererID, root, undefined, didError);
  16354. }
  16355. } catch (err) {
  16356. if (true) {
  16357. if (!hasLoggedError) {
  16358. hasLoggedError = true;
  16359. error("React instrumentation encountered an error: %s", err);
  16360. }
  16361. }
  16362. }
  16363. };
  16364. onCommitFiberUnmount = function(fiber) {
  16365. try {
  16366. hook.onCommitFiberUnmount(rendererID, fiber);
  16367. } catch (err) {
  16368. if (true) {
  16369. if (!hasLoggedError) {
  16370. hasLoggedError = true;
  16371. error("React instrumentation encountered an error: %s", err);
  16372. }
  16373. }
  16374. }
  16375. };
  16376. } catch (err) {
  16377. // Catch all errors because it is unsafe to throw during initialization.
  16378. {
  16379. error("React instrumentation encountered an error: %s.", err);
  16380. }
  16381. } // DevTools exists
  16382. return true;
  16383. }
  16384. function onScheduleRoot(root, children) {
  16385. if (typeof onScheduleFiberRoot === "function") {
  16386. onScheduleFiberRoot(root, children);
  16387. }
  16388. }
  16389. function onCommitRoot(root, expirationTime) {
  16390. if (typeof onCommitFiberRoot === "function") {
  16391. onCommitFiberRoot(root, expirationTime);
  16392. }
  16393. }
  16394. function onCommitUnmount(fiber) {
  16395. if (typeof onCommitFiberUnmount === "function") {
  16396. onCommitFiberUnmount(fiber);
  16397. }
  16398. }
  16399. var hasBadMapPolyfill;
  16400. {
  16401. hasBadMapPolyfill = false;
  16402. try {
  16403. var nonExtensibleObject = Object.preventExtensions({});
  16404. var testMap = new Map([[nonExtensibleObject, null]]);
  16405. var testSet = new Set([nonExtensibleObject]); // This is necessary for Rollup to not consider these unused.
  16406. // https://github.com/rollup/rollup/issues/1771
  16407. // TODO: we can remove these if Rollup fixes the bug.
  16408. testMap.set(0, 0);
  16409. testSet.add(0);
  16410. } catch (e) {
  16411. // TODO: Consider warning about bad polyfills
  16412. hasBadMapPolyfill = true;
  16413. }
  16414. }
  16415. var debugCounter = 1;
  16416. function FiberNode(tag, pendingProps, key, mode) {
  16417. // Instance
  16418. this.tag = tag;
  16419. this.key = key;
  16420. this.elementType = null;
  16421. this.type = null;
  16422. this.stateNode = null; // Fiber
  16423. this.return = null;
  16424. this.child = null;
  16425. this.sibling = null;
  16426. this.index = 0;
  16427. this.ref = null;
  16428. this.pendingProps = pendingProps;
  16429. this.memoizedProps = null;
  16430. this.updateQueue = null;
  16431. this.memoizedState = null;
  16432. this.dependencies = null;
  16433. this.mode = mode; // Effects
  16434. this.effectTag = NoEffect;
  16435. this.nextEffect = null;
  16436. this.firstEffect = null;
  16437. this.lastEffect = null;
  16438. this.expirationTime = NoWork;
  16439. this.childExpirationTime = NoWork;
  16440. this.alternate = null;
  16441. {
  16442. // Note: The following is done to avoid a v8 performance cliff.
  16443. //
  16444. // Initializing the fields below to smis and later updating them with
  16445. // double values will cause Fibers to end up having separate shapes.
  16446. // This behavior/bug has something to do with Object.preventExtension().
  16447. // Fortunately this only impacts DEV builds.
  16448. // Unfortunately it makes React unusably slow for some applications.
  16449. // To work around this, initialize the fields below with doubles.
  16450. //
  16451. // Learn more about this here:
  16452. // https://github.com/facebook/react/issues/14365
  16453. // https://bugs.chromium.org/p/v8/issues/detail?id=8538
  16454. this.actualDuration = Number.NaN;
  16455. this.actualStartTime = Number.NaN;
  16456. this.selfBaseDuration = Number.NaN;
  16457. this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization.
  16458. // This won't trigger the performance cliff mentioned above,
  16459. // and it simplifies other profiler code (including DevTools).
  16460. this.actualDuration = 0;
  16461. this.actualStartTime = -1;
  16462. this.selfBaseDuration = 0;
  16463. this.treeBaseDuration = 0;
  16464. } // This is normally DEV-only except www when it adds listeners.
  16465. // TODO: remove the User Timing integration in favor of Root Events.
  16466. {
  16467. this._debugID = debugCounter++;
  16468. this._debugIsCurrentlyTiming = false;
  16469. }
  16470. {
  16471. this._debugSource = null;
  16472. this._debugOwner = null;
  16473. this._debugNeedsRemount = false;
  16474. this._debugHookTypes = null;
  16475. if (!hasBadMapPolyfill && typeof Object.preventExtensions === "function") {
  16476. Object.preventExtensions(this);
  16477. }
  16478. }
  16479. } // This is a constructor function, rather than a POJO constructor, still
  16480. // please ensure we do the following:
  16481. // 1) Nobody should add any instance methods on this. Instance methods can be
  16482. // more difficult to predict when they get optimized and they are almost
  16483. // never inlined properly in static compilers.
  16484. // 2) Nobody should rely on `instanceof Fiber` for type testing. We should
  16485. // always know when it is a fiber.
  16486. // 3) We might want to experiment with using numeric keys since they are easier
  16487. // to optimize in a non-JIT environment.
  16488. // 4) We can easily go from a constructor to a createFiber object literal if that
  16489. // is faster.
  16490. // 5) It should be easy to port this to a C struct and keep a C implementation
  16491. // compatible.
  16492. var createFiber = function(tag, pendingProps, key, mode) {
  16493. // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
  16494. return new FiberNode(tag, pendingProps, key, mode);
  16495. };
  16496. function shouldConstruct(Component) {
  16497. var prototype = Component.prototype;
  16498. return !!(prototype && prototype.isReactComponent);
  16499. }
  16500. function isSimpleFunctionComponent(type) {
  16501. return (
  16502. typeof type === "function" &&
  16503. !shouldConstruct(type) &&
  16504. type.defaultProps === undefined
  16505. );
  16506. }
  16507. function resolveLazyComponentTag(Component) {
  16508. if (typeof Component === "function") {
  16509. return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
  16510. } else if (Component !== undefined && Component !== null) {
  16511. var $$typeof = Component.$$typeof;
  16512. if ($$typeof === REACT_FORWARD_REF_TYPE) {
  16513. return ForwardRef;
  16514. }
  16515. if ($$typeof === REACT_MEMO_TYPE) {
  16516. return MemoComponent;
  16517. }
  16518. }
  16519. return IndeterminateComponent;
  16520. } // This is used to create an alternate fiber to do work on.
  16521. function createWorkInProgress(current, pendingProps) {
  16522. var workInProgress = current.alternate;
  16523. if (workInProgress === null) {
  16524. // We use a double buffering pooling technique because we know that we'll
  16525. // only ever need at most two versions of a tree. We pool the "other" unused
  16526. // node that we're free to reuse. This is lazily created to avoid allocating
  16527. // extra objects for things that are never updated. It also allow us to
  16528. // reclaim the extra memory if needed.
  16529. workInProgress = createFiber(
  16530. current.tag,
  16531. pendingProps,
  16532. current.key,
  16533. current.mode
  16534. );
  16535. workInProgress.elementType = current.elementType;
  16536. workInProgress.type = current.type;
  16537. workInProgress.stateNode = current.stateNode;
  16538. {
  16539. // DEV-only fields
  16540. {
  16541. workInProgress._debugID = current._debugID;
  16542. }
  16543. workInProgress._debugSource = current._debugSource;
  16544. workInProgress._debugOwner = current._debugOwner;
  16545. workInProgress._debugHookTypes = current._debugHookTypes;
  16546. }
  16547. workInProgress.alternate = current;
  16548. current.alternate = workInProgress;
  16549. } else {
  16550. workInProgress.pendingProps = pendingProps; // We already have an alternate.
  16551. // Reset the effect tag.
  16552. workInProgress.effectTag = NoEffect; // The effect list is no longer valid.
  16553. workInProgress.nextEffect = null;
  16554. workInProgress.firstEffect = null;
  16555. workInProgress.lastEffect = null;
  16556. {
  16557. // We intentionally reset, rather than copy, actualDuration & actualStartTime.
  16558. // This prevents time from endlessly accumulating in new commits.
  16559. // This has the downside of resetting values for different priority renders,
  16560. // But works for yielding (the common case) and should support resuming.
  16561. workInProgress.actualDuration = 0;
  16562. workInProgress.actualStartTime = -1;
  16563. }
  16564. }
  16565. {
  16566. // Trying to debug a mysterious internal-only production failure.
  16567. // See D20130868 and t62461245.
  16568. // This is only on for RN FB builds.
  16569. if (current == null) {
  16570. throw Error("current is " + current + " but it can't be");
  16571. }
  16572. if (workInProgress == null) {
  16573. throw Error("workInProgress is " + workInProgress + " but it can't be");
  16574. }
  16575. }
  16576. workInProgress.childExpirationTime = current.childExpirationTime;
  16577. workInProgress.expirationTime = current.expirationTime;
  16578. workInProgress.child = current.child;
  16579. workInProgress.memoizedProps = current.memoizedProps;
  16580. workInProgress.memoizedState = current.memoizedState;
  16581. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  16582. // it cannot be shared with the current fiber.
  16583. var currentDependencies = current.dependencies;
  16584. workInProgress.dependencies =
  16585. currentDependencies === null
  16586. ? null
  16587. : {
  16588. expirationTime: currentDependencies.expirationTime,
  16589. firstContext: currentDependencies.firstContext,
  16590. responders: currentDependencies.responders
  16591. }; // These will be overridden during the parent's reconciliation
  16592. workInProgress.sibling = current.sibling;
  16593. workInProgress.index = current.index;
  16594. workInProgress.ref = current.ref;
  16595. {
  16596. workInProgress.selfBaseDuration = current.selfBaseDuration;
  16597. workInProgress.treeBaseDuration = current.treeBaseDuration;
  16598. }
  16599. {
  16600. workInProgress._debugNeedsRemount = current._debugNeedsRemount;
  16601. switch (workInProgress.tag) {
  16602. case IndeterminateComponent:
  16603. case FunctionComponent:
  16604. case SimpleMemoComponent:
  16605. workInProgress.type = resolveFunctionForHotReloading(current.type);
  16606. break;
  16607. case ClassComponent:
  16608. workInProgress.type = resolveClassForHotReloading(current.type);
  16609. break;
  16610. case ForwardRef:
  16611. workInProgress.type = resolveForwardRefForHotReloading(current.type);
  16612. break;
  16613. }
  16614. }
  16615. return workInProgress;
  16616. } // Used to reuse a Fiber for a second pass.
  16617. function resetWorkInProgress(workInProgress, renderExpirationTime) {
  16618. // This resets the Fiber to what createFiber or createWorkInProgress would
  16619. // have set the values to before during the first pass. Ideally this wouldn't
  16620. // be necessary but unfortunately many code paths reads from the workInProgress
  16621. // when they should be reading from current and writing to workInProgress.
  16622. // We assume pendingProps, index, key, ref, return are still untouched to
  16623. // avoid doing another reconciliation.
  16624. // Reset the effect tag but keep any Placement tags, since that's something
  16625. // that child fiber is setting, not the reconciliation.
  16626. workInProgress.effectTag &= Placement; // The effect list is no longer valid.
  16627. workInProgress.nextEffect = null;
  16628. workInProgress.firstEffect = null;
  16629. workInProgress.lastEffect = null;
  16630. var current = workInProgress.alternate;
  16631. if (current === null) {
  16632. // Reset to createFiber's initial values.
  16633. workInProgress.childExpirationTime = NoWork;
  16634. workInProgress.expirationTime = renderExpirationTime;
  16635. workInProgress.child = null;
  16636. workInProgress.memoizedProps = null;
  16637. workInProgress.memoizedState = null;
  16638. workInProgress.updateQueue = null;
  16639. workInProgress.dependencies = null;
  16640. {
  16641. // Note: We don't reset the actualTime counts. It's useful to accumulate
  16642. // actual time across multiple render passes.
  16643. workInProgress.selfBaseDuration = 0;
  16644. workInProgress.treeBaseDuration = 0;
  16645. }
  16646. } else {
  16647. // Reset to the cloned values that createWorkInProgress would've.
  16648. workInProgress.childExpirationTime = current.childExpirationTime;
  16649. workInProgress.expirationTime = current.expirationTime;
  16650. workInProgress.child = current.child;
  16651. workInProgress.memoizedProps = current.memoizedProps;
  16652. workInProgress.memoizedState = current.memoizedState;
  16653. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  16654. // it cannot be shared with the current fiber.
  16655. var currentDependencies = current.dependencies;
  16656. workInProgress.dependencies =
  16657. currentDependencies === null
  16658. ? null
  16659. : {
  16660. expirationTime: currentDependencies.expirationTime,
  16661. firstContext: currentDependencies.firstContext,
  16662. responders: currentDependencies.responders
  16663. };
  16664. {
  16665. // Note: We don't reset the actualTime counts. It's useful to accumulate
  16666. // actual time across multiple render passes.
  16667. workInProgress.selfBaseDuration = current.selfBaseDuration;
  16668. workInProgress.treeBaseDuration = current.treeBaseDuration;
  16669. }
  16670. }
  16671. return workInProgress;
  16672. }
  16673. function createHostRootFiber(tag) {
  16674. var mode;
  16675. if (tag === ConcurrentRoot) {
  16676. mode = ConcurrentMode | BlockingMode | StrictMode;
  16677. } else if (tag === BlockingRoot) {
  16678. mode = BlockingMode | StrictMode;
  16679. } else {
  16680. mode = NoMode;
  16681. }
  16682. if (isDevToolsPresent) {
  16683. // Always collect profile timings when DevTools are present.
  16684. // This enables DevTools to start capturing timing at any point–
  16685. // Without some nodes in the tree having empty base times.
  16686. mode |= ProfileMode;
  16687. }
  16688. return createFiber(HostRoot, null, null, mode);
  16689. }
  16690. function createFiberFromTypeAndProps(
  16691. type, // React$ElementType
  16692. key,
  16693. pendingProps,
  16694. owner,
  16695. mode,
  16696. expirationTime
  16697. ) {
  16698. var fiber;
  16699. var fiberTag = IndeterminateComponent; // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
  16700. var resolvedType = type;
  16701. if (typeof type === "function") {
  16702. if (shouldConstruct(type)) {
  16703. fiberTag = ClassComponent;
  16704. {
  16705. resolvedType = resolveClassForHotReloading(resolvedType);
  16706. }
  16707. } else {
  16708. {
  16709. resolvedType = resolveFunctionForHotReloading(resolvedType);
  16710. }
  16711. }
  16712. } else if (typeof type === "string") {
  16713. fiberTag = HostComponent;
  16714. } else {
  16715. getTag: switch (type) {
  16716. case REACT_FRAGMENT_TYPE:
  16717. return createFiberFromFragment(
  16718. pendingProps.children,
  16719. mode,
  16720. expirationTime,
  16721. key
  16722. );
  16723. case REACT_CONCURRENT_MODE_TYPE:
  16724. fiberTag = Mode;
  16725. mode |= ConcurrentMode | BlockingMode | StrictMode;
  16726. break;
  16727. case REACT_STRICT_MODE_TYPE:
  16728. fiberTag = Mode;
  16729. mode |= StrictMode;
  16730. break;
  16731. case REACT_PROFILER_TYPE:
  16732. return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
  16733. case REACT_SUSPENSE_TYPE:
  16734. return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
  16735. case REACT_SUSPENSE_LIST_TYPE:
  16736. return createFiberFromSuspenseList(
  16737. pendingProps,
  16738. mode,
  16739. expirationTime,
  16740. key
  16741. );
  16742. default: {
  16743. if (typeof type === "object" && type !== null) {
  16744. switch (type.$$typeof) {
  16745. case REACT_PROVIDER_TYPE:
  16746. fiberTag = ContextProvider;
  16747. break getTag;
  16748. case REACT_CONTEXT_TYPE:
  16749. // This is a consumer
  16750. fiberTag = ContextConsumer;
  16751. break getTag;
  16752. case REACT_FORWARD_REF_TYPE:
  16753. fiberTag = ForwardRef;
  16754. {
  16755. resolvedType = resolveForwardRefForHotReloading(resolvedType);
  16756. }
  16757. break getTag;
  16758. case REACT_MEMO_TYPE:
  16759. fiberTag = MemoComponent;
  16760. break getTag;
  16761. case REACT_LAZY_TYPE:
  16762. fiberTag = LazyComponent;
  16763. resolvedType = null;
  16764. break getTag;
  16765. case REACT_BLOCK_TYPE:
  16766. fiberTag = Block;
  16767. break getTag;
  16768. }
  16769. }
  16770. var info = "";
  16771. {
  16772. if (
  16773. type === undefined ||
  16774. (typeof type === "object" &&
  16775. type !== null &&
  16776. Object.keys(type).length === 0)
  16777. ) {
  16778. info +=
  16779. " You likely forgot to export your component from the file " +
  16780. "it's defined in, or you might have mixed up default and " +
  16781. "named imports.";
  16782. }
  16783. var ownerName = owner ? getComponentName(owner.type) : null;
  16784. if (ownerName) {
  16785. info += "\n\nCheck the render method of `" + ownerName + "`.";
  16786. }
  16787. }
  16788. {
  16789. throw Error(
  16790. "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: " +
  16791. (type == null ? type : typeof type) +
  16792. "." +
  16793. info
  16794. );
  16795. }
  16796. }
  16797. }
  16798. }
  16799. fiber = createFiber(fiberTag, pendingProps, key, mode);
  16800. fiber.elementType = type;
  16801. fiber.type = resolvedType;
  16802. fiber.expirationTime = expirationTime;
  16803. return fiber;
  16804. }
  16805. function createFiberFromElement(element, mode, expirationTime) {
  16806. var owner = null;
  16807. {
  16808. owner = element._owner;
  16809. }
  16810. var type = element.type;
  16811. var key = element.key;
  16812. var pendingProps = element.props;
  16813. var fiber = createFiberFromTypeAndProps(
  16814. type,
  16815. key,
  16816. pendingProps,
  16817. owner,
  16818. mode,
  16819. expirationTime
  16820. );
  16821. {
  16822. fiber._debugSource = element._source;
  16823. fiber._debugOwner = element._owner;
  16824. }
  16825. return fiber;
  16826. }
  16827. function createFiberFromFragment(elements, mode, expirationTime, key) {
  16828. var fiber = createFiber(Fragment, elements, key, mode);
  16829. fiber.expirationTime = expirationTime;
  16830. return fiber;
  16831. }
  16832. function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
  16833. {
  16834. if (typeof pendingProps.id !== "string") {
  16835. error('Profiler must specify an "id" as a prop');
  16836. }
  16837. }
  16838. var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); // TODO: The Profiler fiber shouldn't have a type. It has a tag.
  16839. fiber.elementType = REACT_PROFILER_TYPE;
  16840. fiber.type = REACT_PROFILER_TYPE;
  16841. fiber.expirationTime = expirationTime;
  16842. {
  16843. fiber.stateNode = {
  16844. effectDuration: 0,
  16845. passiveEffectDuration: 0
  16846. };
  16847. }
  16848. return fiber;
  16849. }
  16850. function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
  16851. var fiber = createFiber(SuspenseComponent, pendingProps, key, mode); // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
  16852. // This needs to be fixed in getComponentName so that it relies on the tag
  16853. // instead.
  16854. fiber.type = REACT_SUSPENSE_TYPE;
  16855. fiber.elementType = REACT_SUSPENSE_TYPE;
  16856. fiber.expirationTime = expirationTime;
  16857. return fiber;
  16858. }
  16859. function createFiberFromSuspenseList(pendingProps, mode, expirationTime, key) {
  16860. var fiber = createFiber(SuspenseListComponent, pendingProps, key, mode);
  16861. {
  16862. // TODO: The SuspenseListComponent fiber shouldn't have a type. It has a tag.
  16863. // This needs to be fixed in getComponentName so that it relies on the tag
  16864. // instead.
  16865. fiber.type = REACT_SUSPENSE_LIST_TYPE;
  16866. }
  16867. fiber.elementType = REACT_SUSPENSE_LIST_TYPE;
  16868. fiber.expirationTime = expirationTime;
  16869. return fiber;
  16870. }
  16871. function createFiberFromText(content, mode, expirationTime) {
  16872. var fiber = createFiber(HostText, content, null, mode);
  16873. fiber.expirationTime = expirationTime;
  16874. return fiber;
  16875. }
  16876. function createFiberFromPortal(portal, mode, expirationTime) {
  16877. var pendingProps = portal.children !== null ? portal.children : [];
  16878. var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
  16879. fiber.expirationTime = expirationTime;
  16880. fiber.stateNode = {
  16881. containerInfo: portal.containerInfo,
  16882. pendingChildren: null,
  16883. // Used by persistent updates
  16884. implementation: portal.implementation
  16885. };
  16886. return fiber;
  16887. } // Used for stashing WIP properties to replay failed work in DEV.
  16888. function assignFiberPropertiesInDEV(target, source) {
  16889. if (target === null) {
  16890. // This Fiber's initial properties will always be overwritten.
  16891. // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
  16892. target = createFiber(IndeterminateComponent, null, null, NoMode);
  16893. } // This is intentionally written as a list of all properties.
  16894. // We tried to use Object.assign() instead but this is called in
  16895. // the hottest path, and Object.assign() was too slow:
  16896. // https://github.com/facebook/react/issues/12502
  16897. // This code is DEV-only so size is not a concern.
  16898. target.tag = source.tag;
  16899. target.key = source.key;
  16900. target.elementType = source.elementType;
  16901. target.type = source.type;
  16902. target.stateNode = source.stateNode;
  16903. target.return = source.return;
  16904. target.child = source.child;
  16905. target.sibling = source.sibling;
  16906. target.index = source.index;
  16907. target.ref = source.ref;
  16908. target.pendingProps = source.pendingProps;
  16909. target.memoizedProps = source.memoizedProps;
  16910. target.updateQueue = source.updateQueue;
  16911. target.memoizedState = source.memoizedState;
  16912. target.dependencies = source.dependencies;
  16913. target.mode = source.mode;
  16914. target.effectTag = source.effectTag;
  16915. target.nextEffect = source.nextEffect;
  16916. target.firstEffect = source.firstEffect;
  16917. target.lastEffect = source.lastEffect;
  16918. target.expirationTime = source.expirationTime;
  16919. target.childExpirationTime = source.childExpirationTime;
  16920. target.alternate = source.alternate;
  16921. {
  16922. target.actualDuration = source.actualDuration;
  16923. target.actualStartTime = source.actualStartTime;
  16924. target.selfBaseDuration = source.selfBaseDuration;
  16925. target.treeBaseDuration = source.treeBaseDuration;
  16926. }
  16927. {
  16928. target._debugID = source._debugID;
  16929. target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming;
  16930. }
  16931. target._debugSource = source._debugSource;
  16932. target._debugOwner = source._debugOwner;
  16933. target._debugNeedsRemount = source._debugNeedsRemount;
  16934. target._debugHookTypes = source._debugHookTypes;
  16935. return target;
  16936. }
  16937. function FiberRootNode(containerInfo, tag, hydrate) {
  16938. this.tag = tag;
  16939. this.current = null;
  16940. this.containerInfo = containerInfo;
  16941. this.pendingChildren = null;
  16942. this.pingCache = null;
  16943. this.finishedExpirationTime = NoWork;
  16944. this.finishedWork = null;
  16945. this.timeoutHandle = noTimeout;
  16946. this.context = null;
  16947. this.pendingContext = null;
  16948. this.hydrate = hydrate;
  16949. this.callbackNode = null;
  16950. this.callbackPriority = NoPriority;
  16951. this.firstPendingTime = NoWork;
  16952. this.firstSuspendedTime = NoWork;
  16953. this.lastSuspendedTime = NoWork;
  16954. this.nextKnownPendingLevel = NoWork;
  16955. this.lastPingedTime = NoWork;
  16956. this.lastExpiredTime = NoWork;
  16957. {
  16958. this.interactionThreadID = tracing.unstable_getThreadID();
  16959. this.memoizedInteractions = new Set();
  16960. this.pendingInteractionMap = new Map();
  16961. }
  16962. }
  16963. function createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks) {
  16964. var root = new FiberRootNode(containerInfo, tag, hydrate);
  16965. // stateNode is any.
  16966. var uninitializedFiber = createHostRootFiber(tag);
  16967. root.current = uninitializedFiber;
  16968. uninitializedFiber.stateNode = root;
  16969. initializeUpdateQueue(uninitializedFiber);
  16970. return root;
  16971. }
  16972. function isRootSuspendedAtTime(root, expirationTime) {
  16973. var firstSuspendedTime = root.firstSuspendedTime;
  16974. var lastSuspendedTime = root.lastSuspendedTime;
  16975. return (
  16976. firstSuspendedTime !== NoWork &&
  16977. firstSuspendedTime >= expirationTime &&
  16978. lastSuspendedTime <= expirationTime
  16979. );
  16980. }
  16981. function markRootSuspendedAtTime(root, expirationTime) {
  16982. var firstSuspendedTime = root.firstSuspendedTime;
  16983. var lastSuspendedTime = root.lastSuspendedTime;
  16984. if (firstSuspendedTime < expirationTime) {
  16985. root.firstSuspendedTime = expirationTime;
  16986. }
  16987. if (lastSuspendedTime > expirationTime || firstSuspendedTime === NoWork) {
  16988. root.lastSuspendedTime = expirationTime;
  16989. }
  16990. if (expirationTime <= root.lastPingedTime) {
  16991. root.lastPingedTime = NoWork;
  16992. }
  16993. if (expirationTime <= root.lastExpiredTime) {
  16994. root.lastExpiredTime = NoWork;
  16995. }
  16996. }
  16997. function markRootUpdatedAtTime(root, expirationTime) {
  16998. // Update the range of pending times
  16999. var firstPendingTime = root.firstPendingTime;
  17000. if (expirationTime > firstPendingTime) {
  17001. root.firstPendingTime = expirationTime;
  17002. } // Update the range of suspended times. Treat everything lower priority or
  17003. // equal to this update as unsuspended.
  17004. var firstSuspendedTime = root.firstSuspendedTime;
  17005. if (firstSuspendedTime !== NoWork) {
  17006. if (expirationTime >= firstSuspendedTime) {
  17007. // The entire suspended range is now unsuspended.
  17008. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  17009. } else if (expirationTime >= root.lastSuspendedTime) {
  17010. root.lastSuspendedTime = expirationTime + 1;
  17011. } // This is a pending level. Check if it's higher priority than the next
  17012. // known pending level.
  17013. if (expirationTime > root.nextKnownPendingLevel) {
  17014. root.nextKnownPendingLevel = expirationTime;
  17015. }
  17016. }
  17017. }
  17018. function markRootFinishedAtTime(
  17019. root,
  17020. finishedExpirationTime,
  17021. remainingExpirationTime
  17022. ) {
  17023. // Update the range of pending times
  17024. root.firstPendingTime = remainingExpirationTime; // Update the range of suspended times. Treat everything higher priority or
  17025. // equal to this update as unsuspended.
  17026. if (finishedExpirationTime <= root.lastSuspendedTime) {
  17027. // The entire suspended range is now unsuspended.
  17028. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  17029. } else if (finishedExpirationTime <= root.firstSuspendedTime) {
  17030. // Part of the suspended range is now unsuspended. Narrow the range to
  17031. // include everything between the unsuspended time (non-inclusive) and the
  17032. // last suspended time.
  17033. root.firstSuspendedTime = finishedExpirationTime - 1;
  17034. }
  17035. if (finishedExpirationTime <= root.lastPingedTime) {
  17036. // Clear the pinged time
  17037. root.lastPingedTime = NoWork;
  17038. }
  17039. if (finishedExpirationTime <= root.lastExpiredTime) {
  17040. // Clear the expired time
  17041. root.lastExpiredTime = NoWork;
  17042. }
  17043. }
  17044. function markRootExpiredAtTime(root, expirationTime) {
  17045. var lastExpiredTime = root.lastExpiredTime;
  17046. if (lastExpiredTime === NoWork || lastExpiredTime > expirationTime) {
  17047. root.lastExpiredTime = expirationTime;
  17048. }
  17049. }
  17050. var didWarnAboutNestedUpdates;
  17051. var didWarnAboutFindNodeInStrictMode;
  17052. {
  17053. didWarnAboutNestedUpdates = false;
  17054. didWarnAboutFindNodeInStrictMode = {};
  17055. }
  17056. function getContextForSubtree(parentComponent) {
  17057. if (!parentComponent) {
  17058. return emptyContextObject;
  17059. }
  17060. var fiber = get(parentComponent);
  17061. var parentContext = findCurrentUnmaskedContext(fiber);
  17062. if (fiber.tag === ClassComponent) {
  17063. var Component = fiber.type;
  17064. if (isContextProvider(Component)) {
  17065. return processChildContext(fiber, Component, parentContext);
  17066. }
  17067. }
  17068. return parentContext;
  17069. }
  17070. function findHostInstanceWithWarning(component, methodName) {
  17071. {
  17072. var fiber = get(component);
  17073. if (fiber === undefined) {
  17074. if (typeof component.render === "function") {
  17075. {
  17076. throw Error("Unable to find node on an unmounted component.");
  17077. }
  17078. } else {
  17079. {
  17080. throw Error(
  17081. "Argument appears to not be a ReactComponent. Keys: " +
  17082. Object.keys(component)
  17083. );
  17084. }
  17085. }
  17086. }
  17087. var hostFiber = findCurrentHostFiber(fiber);
  17088. if (hostFiber === null) {
  17089. return null;
  17090. }
  17091. if (hostFiber.mode & StrictMode) {
  17092. var componentName = getComponentName(fiber.type) || "Component";
  17093. if (!didWarnAboutFindNodeInStrictMode[componentName]) {
  17094. didWarnAboutFindNodeInStrictMode[componentName] = true;
  17095. if (fiber.mode & StrictMode) {
  17096. error(
  17097. "%s is deprecated in StrictMode. " +
  17098. "%s was passed an instance of %s which is inside StrictMode. " +
  17099. "Instead, add a ref directly to the element you want to reference. " +
  17100. "Learn more about using refs safely here: " +
  17101. "https://fb.me/react-strict-mode-find-node%s",
  17102. methodName,
  17103. methodName,
  17104. componentName,
  17105. getStackByFiberInDevAndProd(hostFiber)
  17106. );
  17107. } else {
  17108. error(
  17109. "%s is deprecated in StrictMode. " +
  17110. "%s was passed an instance of %s which renders StrictMode children. " +
  17111. "Instead, add a ref directly to the element you want to reference. " +
  17112. "Learn more about using refs safely here: " +
  17113. "https://fb.me/react-strict-mode-find-node%s",
  17114. methodName,
  17115. methodName,
  17116. componentName,
  17117. getStackByFiberInDevAndProd(hostFiber)
  17118. );
  17119. }
  17120. }
  17121. }
  17122. return hostFiber.stateNode;
  17123. }
  17124. }
  17125. function createContainer(containerInfo, tag, hydrate, hydrationCallbacks) {
  17126. return createFiberRoot(containerInfo, tag, hydrate);
  17127. }
  17128. function updateContainer(element, container, parentComponent, callback) {
  17129. {
  17130. onScheduleRoot(container, element);
  17131. }
  17132. var current$1 = container.current;
  17133. var currentTime = requestCurrentTimeForUpdate();
  17134. {
  17135. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  17136. if ("undefined" !== typeof jest) {
  17137. warnIfUnmockedScheduler(current$1);
  17138. }
  17139. }
  17140. var suspenseConfig = requestCurrentSuspenseConfig();
  17141. var expirationTime = computeExpirationForFiber(
  17142. currentTime,
  17143. current$1,
  17144. suspenseConfig
  17145. );
  17146. var context = getContextForSubtree(parentComponent);
  17147. if (container.context === null) {
  17148. container.context = context;
  17149. } else {
  17150. container.pendingContext = context;
  17151. }
  17152. {
  17153. if (isRendering && current !== null && !didWarnAboutNestedUpdates) {
  17154. didWarnAboutNestedUpdates = true;
  17155. error(
  17156. "Render methods should be a pure function of props and state; " +
  17157. "triggering nested component updates from render is not allowed. " +
  17158. "If necessary, trigger nested updates in componentDidUpdate.\n\n" +
  17159. "Check the render method of %s.",
  17160. getComponentName(current.type) || "Unknown"
  17161. );
  17162. }
  17163. }
  17164. var update = createUpdate(expirationTime, suspenseConfig); // Caution: React DevTools currently depends on this property
  17165. // being called "element".
  17166. update.payload = {
  17167. element: element
  17168. };
  17169. callback = callback === undefined ? null : callback;
  17170. if (callback !== null) {
  17171. {
  17172. if (typeof callback !== "function") {
  17173. error(
  17174. "render(...): Expected the last optional `callback` argument to be a " +
  17175. "function. Instead received: %s.",
  17176. callback
  17177. );
  17178. }
  17179. }
  17180. update.callback = callback;
  17181. }
  17182. enqueueUpdate(current$1, update);
  17183. scheduleWork(current$1, expirationTime);
  17184. return expirationTime;
  17185. }
  17186. function getPublicRootInstance(container) {
  17187. var containerFiber = container.current;
  17188. if (!containerFiber.child) {
  17189. return null;
  17190. }
  17191. switch (containerFiber.child.tag) {
  17192. case HostComponent:
  17193. return getPublicInstance(containerFiber.child.stateNode);
  17194. default:
  17195. return containerFiber.child.stateNode;
  17196. }
  17197. }
  17198. var shouldSuspendImpl = function(fiber) {
  17199. return false;
  17200. };
  17201. function shouldSuspend(fiber) {
  17202. return shouldSuspendImpl(fiber);
  17203. }
  17204. var overrideHookState = null;
  17205. var overrideProps = null;
  17206. var scheduleUpdate = null;
  17207. var setSuspenseHandler = null;
  17208. {
  17209. var copyWithSetImpl = function(obj, path, idx, value) {
  17210. if (idx >= path.length) {
  17211. return value;
  17212. }
  17213. var key = path[idx];
  17214. var updated = Array.isArray(obj) ? obj.slice() : Object.assign({}, obj); // $FlowFixMe number or string is fine here
  17215. updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
  17216. return updated;
  17217. };
  17218. var copyWithSet = function(obj, path, value) {
  17219. return copyWithSetImpl(obj, path, 0, value);
  17220. }; // Support DevTools editable values for useState and useReducer.
  17221. overrideHookState = function(fiber, id, path, value) {
  17222. // For now, the "id" of stateful hooks is just the stateful hook index.
  17223. // This may change in the future with e.g. nested hooks.
  17224. var currentHook = fiber.memoizedState;
  17225. while (currentHook !== null && id > 0) {
  17226. currentHook = currentHook.next;
  17227. id--;
  17228. }
  17229. if (currentHook !== null) {
  17230. var newState = copyWithSet(currentHook.memoizedState, path, value);
  17231. currentHook.memoizedState = newState;
  17232. currentHook.baseState = newState; // We aren't actually adding an update to the queue,
  17233. // because there is no update we can add for useReducer hooks that won't trigger an error.
  17234. // (There's no appropriate action type for DevTools overrides.)
  17235. // As a result though, React will see the scheduled update as a noop and bailout.
  17236. // Shallow cloning props works as a workaround for now to bypass the bailout check.
  17237. fiber.memoizedProps = Object.assign({}, fiber.memoizedProps);
  17238. scheduleWork(fiber, Sync);
  17239. }
  17240. }; // Support DevTools props for function components, forwardRef, memo, host components, etc.
  17241. overrideProps = function(fiber, path, value) {
  17242. fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
  17243. if (fiber.alternate) {
  17244. fiber.alternate.pendingProps = fiber.pendingProps;
  17245. }
  17246. scheduleWork(fiber, Sync);
  17247. };
  17248. scheduleUpdate = function(fiber) {
  17249. scheduleWork(fiber, Sync);
  17250. };
  17251. setSuspenseHandler = function(newShouldSuspendImpl) {
  17252. shouldSuspendImpl = newShouldSuspendImpl;
  17253. };
  17254. }
  17255. function injectIntoDevTools(devToolsConfig) {
  17256. var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
  17257. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
  17258. return injectInternals({
  17259. bundleType: devToolsConfig.bundleType,
  17260. version: devToolsConfig.version,
  17261. rendererPackageName: devToolsConfig.rendererPackageName,
  17262. rendererConfig: devToolsConfig.rendererConfig,
  17263. overrideHookState: overrideHookState,
  17264. overrideProps: overrideProps,
  17265. setSuspenseHandler: setSuspenseHandler,
  17266. scheduleUpdate: scheduleUpdate,
  17267. currentDispatcherRef: ReactCurrentDispatcher,
  17268. findHostInstanceByFiber: function(fiber) {
  17269. var hostFiber = findCurrentHostFiber(fiber);
  17270. if (hostFiber === null) {
  17271. return null;
  17272. }
  17273. return hostFiber.stateNode;
  17274. },
  17275. findFiberByHostInstance: function(instance) {
  17276. if (!findFiberByHostInstance) {
  17277. // Might not be implemented by the renderer.
  17278. return null;
  17279. }
  17280. return findFiberByHostInstance(instance);
  17281. },
  17282. // React Refresh
  17283. findHostInstancesForRefresh: findHostInstancesForRefresh,
  17284. scheduleRefresh: scheduleRefresh,
  17285. scheduleRoot: scheduleRoot,
  17286. setRefreshHandler: setRefreshHandler,
  17287. // Enables DevTools to append owner stacks to error messages in DEV mode.
  17288. getCurrentFiber: function() {
  17289. return current;
  17290. }
  17291. });
  17292. }
  17293. var IsSomeRendererActing$1 = ReactSharedInternals.IsSomeRendererActing;
  17294. function createPortal(
  17295. children,
  17296. containerInfo, // TODO: figure out the API for cross-renderer implementation.
  17297. implementation
  17298. ) {
  17299. var key =
  17300. arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  17301. return {
  17302. // This tag allow us to uniquely identify this as a React Portal
  17303. $$typeof: REACT_PORTAL_TYPE,
  17304. key: key == null ? null : "" + key,
  17305. children: children,
  17306. containerInfo: containerInfo,
  17307. implementation: implementation
  17308. };
  17309. }
  17310. // TODO: this is special because it gets imported during build.
  17311. var ReactVersion = "16.13.0";
  17312. var instanceCache = new Map();
  17313. function getInstanceFromTag(tag) {
  17314. return instanceCache.get(tag) || null;
  17315. }
  17316. var emptyObject$1 = {};
  17317. {
  17318. Object.freeze(emptyObject$1);
  17319. }
  17320. var getInspectorDataForViewTag;
  17321. var getInspectorDataForViewAtPoint;
  17322. {
  17323. var traverseOwnerTreeUp = function(hierarchy, instance) {
  17324. if (instance) {
  17325. hierarchy.unshift(instance);
  17326. traverseOwnerTreeUp(hierarchy, instance._debugOwner);
  17327. }
  17328. };
  17329. var getOwnerHierarchy = function(instance) {
  17330. var hierarchy = [];
  17331. traverseOwnerTreeUp(hierarchy, instance);
  17332. return hierarchy;
  17333. };
  17334. var lastNonHostInstance = function(hierarchy) {
  17335. for (var i = hierarchy.length - 1; i > 1; i--) {
  17336. var instance = hierarchy[i];
  17337. if (instance.tag !== HostComponent) {
  17338. return instance;
  17339. }
  17340. }
  17341. return hierarchy[0];
  17342. };
  17343. var getHostProps = function(fiber) {
  17344. var host = findCurrentHostFiber(fiber);
  17345. if (host) {
  17346. return host.memoizedProps || emptyObject$1;
  17347. }
  17348. return emptyObject$1;
  17349. };
  17350. var getHostNode = function(fiber, findNodeHandle) {
  17351. var hostNode; // look for children first for the hostNode
  17352. // as composite fibers do not have a hostNode
  17353. while (fiber) {
  17354. if (fiber.stateNode !== null && fiber.tag === HostComponent) {
  17355. hostNode = findNodeHandle(fiber.stateNode);
  17356. }
  17357. if (hostNode) {
  17358. return hostNode;
  17359. }
  17360. fiber = fiber.child;
  17361. }
  17362. return null;
  17363. };
  17364. var createHierarchy = function(fiberHierarchy) {
  17365. return fiberHierarchy.map(function(fiber) {
  17366. return {
  17367. name: getComponentName(fiber.type),
  17368. getInspectorData: function(findNodeHandle) {
  17369. return {
  17370. props: getHostProps(fiber),
  17371. source: fiber._debugSource,
  17372. measure: function(callback) {
  17373. // If this is Fabric, we'll find a ShadowNode and use that to measure.
  17374. var hostFiber = findCurrentHostFiber(fiber);
  17375. var shadowNode =
  17376. hostFiber != null &&
  17377. hostFiber.stateNode !== null &&
  17378. hostFiber.stateNode.node;
  17379. if (shadowNode) {
  17380. nativeFabricUIManager.measure(shadowNode, callback);
  17381. } else {
  17382. return ReactNativePrivateInterface.UIManager.measure(
  17383. getHostNode(fiber, findNodeHandle),
  17384. callback
  17385. );
  17386. }
  17387. }
  17388. };
  17389. }
  17390. };
  17391. });
  17392. };
  17393. var getInspectorDataForInstance = function(closestInstance) {
  17394. // Handle case where user clicks outside of ReactNative
  17395. if (!closestInstance) {
  17396. return {
  17397. hierarchy: [],
  17398. props: emptyObject$1,
  17399. selectedIndex: null,
  17400. source: null
  17401. };
  17402. }
  17403. var fiber = findCurrentFiberUsingSlowPath(closestInstance);
  17404. var fiberHierarchy = getOwnerHierarchy(fiber);
  17405. var instance = lastNonHostInstance(fiberHierarchy);
  17406. var hierarchy = createHierarchy(fiberHierarchy);
  17407. var props = getHostProps(instance);
  17408. var source = instance._debugSource;
  17409. var selectedIndex = fiberHierarchy.indexOf(instance);
  17410. return {
  17411. hierarchy: hierarchy,
  17412. props: props,
  17413. selectedIndex: selectedIndex,
  17414. source: source
  17415. };
  17416. };
  17417. getInspectorDataForViewTag = function(viewTag) {
  17418. var closestInstance = getInstanceFromTag(viewTag); // Handle case where user clicks outside of ReactNative
  17419. if (!closestInstance) {
  17420. return {
  17421. hierarchy: [],
  17422. props: emptyObject$1,
  17423. selectedIndex: null,
  17424. source: null
  17425. };
  17426. }
  17427. var fiber = findCurrentFiberUsingSlowPath(closestInstance);
  17428. var fiberHierarchy = getOwnerHierarchy(fiber);
  17429. var instance = lastNonHostInstance(fiberHierarchy);
  17430. var hierarchy = createHierarchy(fiberHierarchy);
  17431. var props = getHostProps(instance);
  17432. var source = instance._debugSource;
  17433. var selectedIndex = fiberHierarchy.indexOf(instance);
  17434. return {
  17435. hierarchy: hierarchy,
  17436. props: props,
  17437. selectedIndex: selectedIndex,
  17438. source: source
  17439. };
  17440. };
  17441. getInspectorDataForViewAtPoint = function(
  17442. findNodeHandle,
  17443. inspectedView,
  17444. locationX,
  17445. locationY,
  17446. callback
  17447. ) {
  17448. var closestInstance = null;
  17449. if (inspectedView._internalInstanceHandle != null) {
  17450. // For Fabric we can look up the instance handle directly and measure it.
  17451. nativeFabricUIManager.findNodeAtPoint(
  17452. inspectedView._internalInstanceHandle.stateNode.node,
  17453. locationX,
  17454. locationY,
  17455. function(internalInstanceHandle) {
  17456. if (internalInstanceHandle == null) {
  17457. callback(
  17458. Object.assign(
  17459. {
  17460. pointerY: locationY,
  17461. frame: {
  17462. left: 0,
  17463. top: 0,
  17464. width: 0,
  17465. height: 0
  17466. }
  17467. },
  17468. getInspectorDataForInstance(closestInstance)
  17469. )
  17470. );
  17471. }
  17472. closestInstance =
  17473. internalInstanceHandle.stateNode.canonical._internalInstanceHandle;
  17474. nativeFabricUIManager.measure(
  17475. internalInstanceHandle.stateNode.node,
  17476. function(x, y, width, height, pageX, pageY) {
  17477. callback(
  17478. Object.assign(
  17479. {
  17480. pointerY: locationY,
  17481. frame: {
  17482. left: pageX,
  17483. top: pageY,
  17484. width: width,
  17485. height: height
  17486. }
  17487. },
  17488. getInspectorDataForInstance(closestInstance)
  17489. )
  17490. );
  17491. }
  17492. );
  17493. }
  17494. );
  17495. } else if (inspectedView._internalFiberInstanceHandleDEV != null) {
  17496. // For Paper we fall back to the old strategy using the React tag.
  17497. ReactNativePrivateInterface.UIManager.findSubviewIn(
  17498. findNodeHandle(inspectedView),
  17499. [locationX, locationY],
  17500. function(nativeViewTag, left, top, width, height) {
  17501. var inspectorData = getInspectorDataForInstance(
  17502. getInstanceFromTag(nativeViewTag)
  17503. );
  17504. callback(
  17505. Object.assign({}, inspectorData, {
  17506. pointerY: locationY,
  17507. frame: {
  17508. left: left,
  17509. top: top,
  17510. width: width,
  17511. height: height
  17512. },
  17513. touchedViewTag: nativeViewTag
  17514. })
  17515. );
  17516. }
  17517. );
  17518. } else {
  17519. error(
  17520. "getInspectorDataForViewAtPoint expects to receieve a host component"
  17521. );
  17522. return;
  17523. }
  17524. };
  17525. }
  17526. var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner;
  17527. function findHostInstance_DEPRECATED(componentOrHandle) {
  17528. {
  17529. var owner = ReactCurrentOwner$3.current;
  17530. if (owner !== null && owner.stateNode !== null) {
  17531. if (!owner.stateNode._warnedAboutRefsInRender) {
  17532. error(
  17533. "%s is accessing findNodeHandle inside its render(). " +
  17534. "render() should be a pure function of props and state. It should " +
  17535. "never access something that requires stale data from the previous " +
  17536. "render, such as refs. Move this logic to componentDidMount and " +
  17537. "componentDidUpdate instead.",
  17538. getComponentName(owner.type) || "A component"
  17539. );
  17540. }
  17541. owner.stateNode._warnedAboutRefsInRender = true;
  17542. }
  17543. }
  17544. if (componentOrHandle == null) {
  17545. return null;
  17546. }
  17547. if (componentOrHandle._nativeTag) {
  17548. return componentOrHandle;
  17549. }
  17550. if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) {
  17551. return componentOrHandle.canonical;
  17552. }
  17553. var hostInstance;
  17554. {
  17555. hostInstance = findHostInstanceWithWarning(
  17556. componentOrHandle,
  17557. "findHostInstance_DEPRECATED"
  17558. );
  17559. }
  17560. if (hostInstance == null) {
  17561. return hostInstance;
  17562. }
  17563. if (hostInstance.canonical) {
  17564. // Fabric
  17565. return hostInstance.canonical;
  17566. }
  17567. return hostInstance;
  17568. }
  17569. function findNodeHandle(componentOrHandle) {
  17570. {
  17571. var owner = ReactCurrentOwner$3.current;
  17572. if (owner !== null && owner.stateNode !== null) {
  17573. if (!owner.stateNode._warnedAboutRefsInRender) {
  17574. error(
  17575. "%s is accessing findNodeHandle inside its render(). " +
  17576. "render() should be a pure function of props and state. It should " +
  17577. "never access something that requires stale data from the previous " +
  17578. "render, such as refs. Move this logic to componentDidMount and " +
  17579. "componentDidUpdate instead.",
  17580. getComponentName(owner.type) || "A component"
  17581. );
  17582. }
  17583. owner.stateNode._warnedAboutRefsInRender = true;
  17584. }
  17585. }
  17586. if (componentOrHandle == null) {
  17587. return null;
  17588. }
  17589. if (typeof componentOrHandle === "number") {
  17590. // Already a node handle
  17591. return componentOrHandle;
  17592. }
  17593. if (componentOrHandle._nativeTag) {
  17594. return componentOrHandle._nativeTag;
  17595. }
  17596. if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) {
  17597. return componentOrHandle.canonical._nativeTag;
  17598. }
  17599. var hostInstance;
  17600. {
  17601. hostInstance = findHostInstanceWithWarning(
  17602. componentOrHandle,
  17603. "findNodeHandle"
  17604. );
  17605. }
  17606. if (hostInstance == null) {
  17607. return hostInstance;
  17608. } // TODO: the code is right but the types here are wrong.
  17609. // https://github.com/facebook/react/pull/12863
  17610. if (hostInstance.canonical) {
  17611. // Fabric
  17612. return hostInstance.canonical._nativeTag;
  17613. }
  17614. return hostInstance._nativeTag;
  17615. }
  17616. function dispatchCommand(handle, command, args) {
  17617. if (handle._nativeTag == null) {
  17618. {
  17619. error(
  17620. "dispatchCommand was called with a ref that isn't a " +
  17621. "native component. Use React.forwardRef to get access to the underlying native component"
  17622. );
  17623. }
  17624. return;
  17625. }
  17626. if (handle._internalInstanceHandle) {
  17627. nativeFabricUIManager.dispatchCommand(
  17628. handle._internalInstanceHandle.stateNode.node,
  17629. command,
  17630. args
  17631. );
  17632. } else {
  17633. ReactNativePrivateInterface.UIManager.dispatchViewManagerCommand(
  17634. handle._nativeTag,
  17635. command,
  17636. args
  17637. );
  17638. }
  17639. }
  17640. function render(element, containerTag, callback) {
  17641. var root = roots.get(containerTag);
  17642. if (!root) {
  17643. // TODO (bvaughn): If we decide to keep the wrapper component,
  17644. // We could create a wrapper for containerTag as well to reduce special casing.
  17645. root = createContainer(containerTag, LegacyRoot, false);
  17646. roots.set(containerTag, root);
  17647. }
  17648. updateContainer(element, root, null, callback);
  17649. return getPublicRootInstance(root);
  17650. }
  17651. function unmountComponentAtNode(containerTag) {
  17652. this.stopSurface(containerTag);
  17653. }
  17654. function stopSurface(containerTag) {
  17655. var root = roots.get(containerTag);
  17656. if (root) {
  17657. // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred?
  17658. updateContainer(null, root, null, function() {
  17659. roots.delete(containerTag);
  17660. });
  17661. }
  17662. }
  17663. function createPortal$1(children, containerTag) {
  17664. var key =
  17665. arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  17666. return createPortal(children, containerTag, null, key);
  17667. }
  17668. setBatchingImplementation(batchedUpdates$1);
  17669. var roots = new Map();
  17670. injectIntoDevTools({
  17671. findFiberByHostInstance: getInstanceFromInstance,
  17672. bundleType: 1,
  17673. version: ReactVersion,
  17674. rendererPackageName: "react-native-renderer",
  17675. rendererConfig: {
  17676. getInspectorDataForViewTag: getInspectorDataForViewTag,
  17677. getInspectorDataForViewAtPoint: getInspectorDataForViewAtPoint.bind(
  17678. null,
  17679. findNodeHandle
  17680. )
  17681. }
  17682. });
  17683. exports.createPortal = createPortal$1;
  17684. exports.dispatchCommand = dispatchCommand;
  17685. exports.findHostInstance_DEPRECATED = findHostInstance_DEPRECATED;
  17686. exports.findNodeHandle = findNodeHandle;
  17687. exports.render = render;
  17688. exports.stopSurface = stopSurface;
  17689. exports.unmountComponentAtNode = unmountComponentAtNode;
  17690. })();
  17691. }