ReactFabric-dev.js 621 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @noflow
  8. * @nolint
  9. * @providesModule ReactFabric-dev
  10. * @preventMunge
  11. * @generated
  12. */
  13. 'use strict';
  14. if (__DEV__) {
  15. (function() {
  16. "use strict";
  17. var React = require("react");
  18. require("react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore");
  19. var ReactNativePrivateInterface = require("react-native/Libraries/ReactPrivate/ReactNativePrivateInterface");
  20. var Scheduler = require("scheduler");
  21. var tracing = require("scheduler/tracing");
  22. var ReactSharedInternals =
  23. React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; // Prevent newer renderers from RTE when used with older react package versions.
  24. // Current owner and dispatcher used to share the same ref,
  25. // but PR #14548 split them out to better support the react-debug-tools package.
  26. if (!ReactSharedInternals.hasOwnProperty("ReactCurrentDispatcher")) {
  27. ReactSharedInternals.ReactCurrentDispatcher = {
  28. current: null
  29. };
  30. }
  31. if (!ReactSharedInternals.hasOwnProperty("ReactCurrentBatchConfig")) {
  32. ReactSharedInternals.ReactCurrentBatchConfig = {
  33. suspense: null
  34. };
  35. }
  36. // by calls to these methods by a Babel plugin.
  37. //
  38. // In PROD (or in packages without access to React internals),
  39. // they are left as they are instead.
  40. function warn(format) {
  41. {
  42. for (
  43. var _len = arguments.length,
  44. args = new Array(_len > 1 ? _len - 1 : 0),
  45. _key = 1;
  46. _key < _len;
  47. _key++
  48. ) {
  49. args[_key - 1] = arguments[_key];
  50. }
  51. printWarning("warn", format, args);
  52. }
  53. }
  54. function error(format) {
  55. {
  56. for (
  57. var _len2 = arguments.length,
  58. args = new Array(_len2 > 1 ? _len2 - 1 : 0),
  59. _key2 = 1;
  60. _key2 < _len2;
  61. _key2++
  62. ) {
  63. args[_key2 - 1] = arguments[_key2];
  64. }
  65. printWarning("error", format, args);
  66. }
  67. }
  68. function printWarning(level, format, args) {
  69. // When changing this logic, you might want to also
  70. // update consoleWithStackDev.www.js as well.
  71. {
  72. var hasExistingStack =
  73. args.length > 0 &&
  74. typeof args[args.length - 1] === "string" &&
  75. args[args.length - 1].indexOf("\n in") === 0;
  76. if (!hasExistingStack) {
  77. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  78. var stack = ReactDebugCurrentFrame.getStackAddendum();
  79. if (stack !== "") {
  80. format += "%s";
  81. args = args.concat([stack]);
  82. }
  83. }
  84. var argsWithFormat = args.map(function(item) {
  85. return "" + item;
  86. }); // Careful: RN currently depends on this prefix
  87. argsWithFormat.unshift("Warning: " + format); // We intentionally don't use spread (or .apply) directly because it
  88. // breaks IE9: https://github.com/facebook/react/issues/13610
  89. // eslint-disable-next-line react-internal/no-production-logging
  90. Function.prototype.apply.call(console[level], console, argsWithFormat);
  91. try {
  92. // --- Welcome to debugging React ---
  93. // This error was thrown as a convenience so that you can use this stack
  94. // to find the callsite that caused this warning to fire.
  95. var argIndex = 0;
  96. var message =
  97. "Warning: " +
  98. format.replace(/%s/g, function() {
  99. return args[argIndex++];
  100. });
  101. throw new Error(message);
  102. } catch (x) {}
  103. }
  104. }
  105. var FunctionComponent = 0;
  106. var ClassComponent = 1;
  107. var IndeterminateComponent = 2; // Before we know whether it is function or class
  108. var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
  109. var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
  110. var HostComponent = 5;
  111. var HostText = 6;
  112. var Fragment = 7;
  113. var Mode = 8;
  114. var ContextConsumer = 9;
  115. var ContextProvider = 10;
  116. var ForwardRef = 11;
  117. var Profiler = 12;
  118. var SuspenseComponent = 13;
  119. var MemoComponent = 14;
  120. var SimpleMemoComponent = 15;
  121. var LazyComponent = 16;
  122. var IncompleteClassComponent = 17;
  123. var DehydratedFragment = 18;
  124. var SuspenseListComponent = 19;
  125. var FundamentalComponent = 20;
  126. var ScopeComponent = 21;
  127. var Block = 22;
  128. function getParent(inst) {
  129. do {
  130. inst = inst.return; // TODO: If this is a HostRoot we might want to bail out.
  131. // That is depending on if we want nested subtrees (layers) to bubble
  132. // events to their parent. We could also go through parentNode on the
  133. // host node but that wouldn't work for React Native and doesn't let us
  134. // do the portal feature.
  135. } while (inst && inst.tag !== HostComponent);
  136. if (inst) {
  137. return inst;
  138. }
  139. return null;
  140. }
  141. /**
  142. * Return the lowest common ancestor of A and B, or null if they are in
  143. * different trees.
  144. */
  145. function getLowestCommonAncestor(instA, instB) {
  146. var depthA = 0;
  147. for (var tempA = instA; tempA; tempA = getParent(tempA)) {
  148. depthA++;
  149. }
  150. var depthB = 0;
  151. for (var tempB = instB; tempB; tempB = getParent(tempB)) {
  152. depthB++;
  153. } // If A is deeper, crawl up.
  154. while (depthA - depthB > 0) {
  155. instA = getParent(instA);
  156. depthA--;
  157. } // If B is deeper, crawl up.
  158. while (depthB - depthA > 0) {
  159. instB = getParent(instB);
  160. depthB--;
  161. } // Walk in lockstep until we find a match.
  162. var depth = depthA;
  163. while (depth--) {
  164. if (instA === instB || instA === instB.alternate) {
  165. return instA;
  166. }
  167. instA = getParent(instA);
  168. instB = getParent(instB);
  169. }
  170. return null;
  171. }
  172. /**
  173. * Return if A is an ancestor of B.
  174. */
  175. function isAncestor(instA, instB) {
  176. while (instB) {
  177. if (instA === instB || instA === instB.alternate) {
  178. return true;
  179. }
  180. instB = getParent(instB);
  181. }
  182. return false;
  183. }
  184. /**
  185. * Return the parent instance of the passed-in instance.
  186. */
  187. function getParentInstance(inst) {
  188. return getParent(inst);
  189. }
  190. /**
  191. * Simulates the traversal of a two-phase, capture/bubble event dispatch.
  192. */
  193. function traverseTwoPhase(inst, fn, arg) {
  194. var path = [];
  195. while (inst) {
  196. path.push(inst);
  197. inst = getParent(inst);
  198. }
  199. var i;
  200. for (i = path.length; i-- > 0; ) {
  201. fn(path[i], "captured", arg);
  202. }
  203. for (i = 0; i < path.length; i++) {
  204. fn(path[i], "bubbled", arg);
  205. }
  206. }
  207. var invokeGuardedCallbackImpl = function(
  208. name,
  209. func,
  210. context,
  211. a,
  212. b,
  213. c,
  214. d,
  215. e,
  216. f
  217. ) {
  218. var funcArgs = Array.prototype.slice.call(arguments, 3);
  219. try {
  220. func.apply(context, funcArgs);
  221. } catch (error) {
  222. this.onError(error);
  223. }
  224. };
  225. {
  226. // In DEV mode, we swap out invokeGuardedCallback for a special version
  227. // that plays more nicely with the browser's DevTools. The idea is to preserve
  228. // "Pause on exceptions" behavior. Because React wraps all user-provided
  229. // functions in invokeGuardedCallback, and the production version of
  230. // invokeGuardedCallback uses a try-catch, all user exceptions are treated
  231. // like caught exceptions, and the DevTools won't pause unless the developer
  232. // takes the extra step of enabling pause on caught exceptions. This is
  233. // unintuitive, though, because even though React has caught the error, from
  234. // the developer's perspective, the error is uncaught.
  235. //
  236. // To preserve the expected "Pause on exceptions" behavior, we don't use a
  237. // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
  238. // DOM node, and call the user-provided callback from inside an event handler
  239. // for that fake event. If the callback throws, the error is "captured" using
  240. // a global event handler. But because the error happens in a different
  241. // event loop context, it does not interrupt the normal program flow.
  242. // Effectively, this gives us try-catch behavior without actually using
  243. // try-catch. Neat!
  244. // Check that the browser supports the APIs we need to implement our special
  245. // DEV version of invokeGuardedCallback
  246. if (
  247. typeof window !== "undefined" &&
  248. typeof window.dispatchEvent === "function" &&
  249. typeof document !== "undefined" &&
  250. typeof document.createEvent === "function"
  251. ) {
  252. var fakeNode = document.createElement("react");
  253. var invokeGuardedCallbackDev = function(
  254. name,
  255. func,
  256. context,
  257. a,
  258. b,
  259. c,
  260. d,
  261. e,
  262. f
  263. ) {
  264. // If document doesn't exist we know for sure we will crash in this method
  265. // when we call document.createEvent(). However this can cause confusing
  266. // errors: https://github.com/facebookincubator/create-react-app/issues/3482
  267. // So we preemptively throw with a better message instead.
  268. if (!(typeof document !== "undefined")) {
  269. throw Error(
  270. "The `document` global was defined when React was initialized, but is not defined anymore. This can happen in a test environment if a component schedules an update from an asynchronous callback, but the test has already finished running. To solve this, you can either unmount the component at the end of your test (and ensure that any asynchronous operations get canceled in `componentWillUnmount`), or you can change the test itself to be asynchronous."
  271. );
  272. }
  273. var evt = document.createEvent("Event"); // Keeps track of whether the user-provided callback threw an error. We
  274. // set this to true at the beginning, then set it to false right after
  275. // calling the function. If the function errors, `didError` will never be
  276. // set to false. This strategy works even if the browser is flaky and
  277. // fails to call our global error handler, because it doesn't rely on
  278. // the error event at all.
  279. var didError = true; // Keeps track of the value of window.event so that we can reset it
  280. // during the callback to let user code access window.event in the
  281. // browsers that support it.
  282. var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
  283. // dispatching: https://github.com/facebook/react/issues/13688
  284. var windowEventDescriptor = Object.getOwnPropertyDescriptor(
  285. window,
  286. "event"
  287. ); // Create an event handler for our fake event. We will synchronously
  288. // dispatch our fake event using `dispatchEvent`. Inside the handler, we
  289. // call the user-provided callback.
  290. var funcArgs = Array.prototype.slice.call(arguments, 3);
  291. function callCallback() {
  292. // We immediately remove the callback from event listeners so that
  293. // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
  294. // nested call would trigger the fake event handlers of any call higher
  295. // in the stack.
  296. fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
  297. // window.event assignment in both IE <= 10 as they throw an error
  298. // "Member not found" in strict mode, and in Firefox which does not
  299. // support window.event.
  300. if (
  301. typeof window.event !== "undefined" &&
  302. window.hasOwnProperty("event")
  303. ) {
  304. window.event = windowEvent;
  305. }
  306. func.apply(context, funcArgs);
  307. didError = false;
  308. } // Create a global error event handler. We use this to capture the value
  309. // that was thrown. It's possible that this error handler will fire more
  310. // than once; for example, if non-React code also calls `dispatchEvent`
  311. // and a handler for that event throws. We should be resilient to most of
  312. // those cases. Even if our error event handler fires more than once, the
  313. // last error event is always used. If the callback actually does error,
  314. // we know that the last error event is the correct one, because it's not
  315. // possible for anything else to have happened in between our callback
  316. // erroring and the code that follows the `dispatchEvent` call below. If
  317. // the callback doesn't error, but the error event was fired, we know to
  318. // ignore it because `didError` will be false, as described above.
  319. var error; // Use this to track whether the error event is ever called.
  320. var didSetError = false;
  321. var isCrossOriginError = false;
  322. function handleWindowError(event) {
  323. error = event.error;
  324. didSetError = true;
  325. if (error === null && event.colno === 0 && event.lineno === 0) {
  326. isCrossOriginError = true;
  327. }
  328. if (event.defaultPrevented) {
  329. // Some other error handler has prevented default.
  330. // Browsers silence the error report if this happens.
  331. // We'll remember this to later decide whether to log it or not.
  332. if (error != null && typeof error === "object") {
  333. try {
  334. error._suppressLogging = true;
  335. } catch (inner) {
  336. // Ignore.
  337. }
  338. }
  339. }
  340. } // Create a fake event type.
  341. var evtType = "react-" + (name ? name : "invokeguardedcallback"); // Attach our event handlers
  342. window.addEventListener("error", handleWindowError);
  343. fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
  344. // errors, it will trigger our global error handler.
  345. evt.initEvent(evtType, false, false);
  346. fakeNode.dispatchEvent(evt);
  347. if (windowEventDescriptor) {
  348. Object.defineProperty(window, "event", windowEventDescriptor);
  349. }
  350. if (didError) {
  351. if (!didSetError) {
  352. // The callback errored, but the error event never fired.
  353. error = new Error(
  354. "An error was thrown inside one of your components, but React " +
  355. "doesn't know what it was. This is likely due to browser " +
  356. 'flakiness. React does its best to preserve the "Pause on ' +
  357. 'exceptions" behavior of the DevTools, which requires some ' +
  358. "DEV-mode only tricks. It's possible that these don't work in " +
  359. "your browser. Try triggering the error in production mode, " +
  360. "or switching to a modern browser. If you suspect that this is " +
  361. "actually an issue with React, please file an issue."
  362. );
  363. } else if (isCrossOriginError) {
  364. error = new Error(
  365. "A cross-origin error was thrown. React doesn't have access to " +
  366. "the actual error object in development. " +
  367. "See https://fb.me/react-crossorigin-error for more information."
  368. );
  369. }
  370. this.onError(error);
  371. } // Remove our event listeners
  372. window.removeEventListener("error", handleWindowError);
  373. };
  374. invokeGuardedCallbackImpl = invokeGuardedCallbackDev;
  375. }
  376. }
  377. var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
  378. var hasError = false;
  379. var caughtError = null; // Used by event system to capture/rethrow the first error.
  380. var hasRethrowError = false;
  381. var rethrowError = null;
  382. var reporter = {
  383. onError: function(error) {
  384. hasError = true;
  385. caughtError = error;
  386. }
  387. };
  388. /**
  389. * Call a function while guarding against errors that happens within it.
  390. * Returns an error if it throws, otherwise null.
  391. *
  392. * In production, this is implemented using a try-catch. The reason we don't
  393. * use a try-catch directly is so that we can swap out a different
  394. * implementation in DEV mode.
  395. *
  396. * @param {String} name of the guard to use for logging or debugging
  397. * @param {Function} func The function to invoke
  398. * @param {*} context The context to use when calling the function
  399. * @param {...*} args Arguments for function
  400. */
  401. function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
  402. hasError = false;
  403. caughtError = null;
  404. invokeGuardedCallbackImpl$1.apply(reporter, arguments);
  405. }
  406. /**
  407. * Same as invokeGuardedCallback, but instead of returning an error, it stores
  408. * it in a global so it can be rethrown by `rethrowCaughtError` later.
  409. * TODO: See if caughtError and rethrowError can be unified.
  410. *
  411. * @param {String} name of the guard to use for logging or debugging
  412. * @param {Function} func The function to invoke
  413. * @param {*} context The context to use when calling the function
  414. * @param {...*} args Arguments for function
  415. */
  416. function invokeGuardedCallbackAndCatchFirstError(
  417. name,
  418. func,
  419. context,
  420. a,
  421. b,
  422. c,
  423. d,
  424. e,
  425. f
  426. ) {
  427. invokeGuardedCallback.apply(this, arguments);
  428. if (hasError) {
  429. var error = clearCaughtError();
  430. if (!hasRethrowError) {
  431. hasRethrowError = true;
  432. rethrowError = error;
  433. }
  434. }
  435. }
  436. /**
  437. * During execution of guarded functions we will capture the first error which
  438. * we will rethrow to be handled by the top level error handler.
  439. */
  440. function rethrowCaughtError() {
  441. if (hasRethrowError) {
  442. var error = rethrowError;
  443. hasRethrowError = false;
  444. rethrowError = null;
  445. throw error;
  446. }
  447. }
  448. function hasCaughtError() {
  449. return hasError;
  450. }
  451. function clearCaughtError() {
  452. if (hasError) {
  453. var error = caughtError;
  454. hasError = false;
  455. caughtError = null;
  456. return error;
  457. } else {
  458. {
  459. throw Error(
  460. "clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue."
  461. );
  462. }
  463. }
  464. }
  465. var getFiberCurrentPropsFromNode = null;
  466. var getInstanceFromNode = null;
  467. var getNodeFromInstance = null;
  468. function setComponentTree(
  469. getFiberCurrentPropsFromNodeImpl,
  470. getInstanceFromNodeImpl,
  471. getNodeFromInstanceImpl
  472. ) {
  473. getFiberCurrentPropsFromNode = getFiberCurrentPropsFromNodeImpl;
  474. getInstanceFromNode = getInstanceFromNodeImpl;
  475. getNodeFromInstance = getNodeFromInstanceImpl;
  476. {
  477. if (!getNodeFromInstance || !getInstanceFromNode) {
  478. error(
  479. "EventPluginUtils.setComponentTree(...): Injected " +
  480. "module is missing getNodeFromInstance or getInstanceFromNode."
  481. );
  482. }
  483. }
  484. }
  485. var validateEventDispatches;
  486. {
  487. validateEventDispatches = function(event) {
  488. var dispatchListeners = event._dispatchListeners;
  489. var dispatchInstances = event._dispatchInstances;
  490. var listenersIsArr = Array.isArray(dispatchListeners);
  491. var listenersLen = listenersIsArr
  492. ? dispatchListeners.length
  493. : dispatchListeners
  494. ? 1
  495. : 0;
  496. var instancesIsArr = Array.isArray(dispatchInstances);
  497. var instancesLen = instancesIsArr
  498. ? dispatchInstances.length
  499. : dispatchInstances
  500. ? 1
  501. : 0;
  502. if (instancesIsArr !== listenersIsArr || instancesLen !== listenersLen) {
  503. error("EventPluginUtils: Invalid `event`.");
  504. }
  505. };
  506. }
  507. /**
  508. * Dispatch the event to the listener.
  509. * @param {SyntheticEvent} event SyntheticEvent to handle
  510. * @param {function} listener Application-level callback
  511. * @param {*} inst Internal component instance
  512. */
  513. function executeDispatch(event, listener, inst) {
  514. var type = event.type || "unknown-event";
  515. event.currentTarget = getNodeFromInstance(inst);
  516. invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event);
  517. event.currentTarget = null;
  518. }
  519. /**
  520. * Standard/simple iteration through an event's collected dispatches.
  521. */
  522. function executeDispatchesInOrder(event) {
  523. var dispatchListeners = event._dispatchListeners;
  524. var dispatchInstances = event._dispatchInstances;
  525. {
  526. validateEventDispatches(event);
  527. }
  528. if (Array.isArray(dispatchListeners)) {
  529. for (var i = 0; i < dispatchListeners.length; i++) {
  530. if (event.isPropagationStopped()) {
  531. break;
  532. } // Listeners and Instances are two parallel arrays that are always in sync.
  533. executeDispatch(event, dispatchListeners[i], dispatchInstances[i]);
  534. }
  535. } else if (dispatchListeners) {
  536. executeDispatch(event, dispatchListeners, dispatchInstances);
  537. }
  538. event._dispatchListeners = null;
  539. event._dispatchInstances = null;
  540. }
  541. /**
  542. * Standard/simple iteration through an event's collected dispatches, but stops
  543. * at the first dispatch execution returning true, and returns that id.
  544. *
  545. * @return {?string} id of the first dispatch execution who's listener returns
  546. * true, or null if no listener returned true.
  547. */
  548. function executeDispatchesInOrderStopAtTrueImpl(event) {
  549. var dispatchListeners = event._dispatchListeners;
  550. var dispatchInstances = event._dispatchInstances;
  551. {
  552. validateEventDispatches(event);
  553. }
  554. if (Array.isArray(dispatchListeners)) {
  555. for (var i = 0; i < dispatchListeners.length; i++) {
  556. if (event.isPropagationStopped()) {
  557. break;
  558. } // Listeners and Instances are two parallel arrays that are always in sync.
  559. if (dispatchListeners[i](event, dispatchInstances[i])) {
  560. return dispatchInstances[i];
  561. }
  562. }
  563. } else if (dispatchListeners) {
  564. if (dispatchListeners(event, dispatchInstances)) {
  565. return dispatchInstances;
  566. }
  567. }
  568. return null;
  569. }
  570. /**
  571. * @see executeDispatchesInOrderStopAtTrueImpl
  572. */
  573. function executeDispatchesInOrderStopAtTrue(event) {
  574. var ret = executeDispatchesInOrderStopAtTrueImpl(event);
  575. event._dispatchInstances = null;
  576. event._dispatchListeners = null;
  577. return ret;
  578. }
  579. /**
  580. * Execution of a "direct" dispatch - there must be at most one dispatch
  581. * accumulated on the event or it is considered an error. It doesn't really make
  582. * sense for an event with multiple dispatches (bubbled) to keep track of the
  583. * return values at each dispatch execution, but it does tend to make sense when
  584. * dealing with "direct" dispatches.
  585. *
  586. * @return {*} The return value of executing the single dispatch.
  587. */
  588. function executeDirectDispatch(event) {
  589. {
  590. validateEventDispatches(event);
  591. }
  592. var dispatchListener = event._dispatchListeners;
  593. var dispatchInstance = event._dispatchInstances;
  594. if (!!Array.isArray(dispatchListener)) {
  595. throw Error("executeDirectDispatch(...): Invalid `event`.");
  596. }
  597. event.currentTarget = dispatchListener
  598. ? getNodeFromInstance(dispatchInstance)
  599. : null;
  600. var res = dispatchListener ? dispatchListener(event) : null;
  601. event.currentTarget = null;
  602. event._dispatchListeners = null;
  603. event._dispatchInstances = null;
  604. return res;
  605. }
  606. /**
  607. * @param {SyntheticEvent} event
  608. * @return {boolean} True iff number of dispatches accumulated is greater than 0.
  609. */
  610. function hasDispatches(event) {
  611. return !!event._dispatchListeners;
  612. }
  613. function isInteractive(tag) {
  614. return (
  615. tag === "button" ||
  616. tag === "input" ||
  617. tag === "select" ||
  618. tag === "textarea"
  619. );
  620. }
  621. function shouldPreventMouseEvent(name, type, props) {
  622. switch (name) {
  623. case "onClick":
  624. case "onClickCapture":
  625. case "onDoubleClick":
  626. case "onDoubleClickCapture":
  627. case "onMouseDown":
  628. case "onMouseDownCapture":
  629. case "onMouseMove":
  630. case "onMouseMoveCapture":
  631. case "onMouseUp":
  632. case "onMouseUpCapture":
  633. case "onMouseEnter":
  634. return !!(props.disabled && isInteractive(type));
  635. default:
  636. return false;
  637. }
  638. }
  639. /**
  640. * @param {object} inst The instance, which is the source of events.
  641. * @param {string} registrationName Name of listener (e.g. `onClick`).
  642. * @return {?function} The stored callback.
  643. */
  644. function getListener(inst, registrationName) {
  645. var listener; // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
  646. // live here; needs to be moved to a better place soon
  647. var stateNode = inst.stateNode;
  648. if (!stateNode) {
  649. // Work in progress (ex: onload events in incremental mode).
  650. return null;
  651. }
  652. var props = getFiberCurrentPropsFromNode(stateNode);
  653. if (!props) {
  654. // Work in progress.
  655. return null;
  656. }
  657. listener = props[registrationName];
  658. if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
  659. return null;
  660. }
  661. if (!(!listener || typeof listener === "function")) {
  662. throw Error(
  663. "Expected `" +
  664. registrationName +
  665. "` listener to be a function, instead got a value of `" +
  666. typeof listener +
  667. "` type."
  668. );
  669. }
  670. return listener;
  671. }
  672. /**
  673. * Accumulates items that must not be null or undefined into the first one. This
  674. * is used to conserve memory by avoiding array allocations, and thus sacrifices
  675. * API cleanness. Since `current` can be null before being passed in and not
  676. * null after this function, make sure to assign it back to `current`:
  677. *
  678. * `a = accumulateInto(a, b);`
  679. *
  680. * This API should be sparingly used. Try `accumulate` for something cleaner.
  681. *
  682. * @return {*|array<*>} An accumulation of items.
  683. */
  684. function accumulateInto(current, next) {
  685. if (!(next != null)) {
  686. throw Error(
  687. "accumulateInto(...): Accumulated items must not be null or undefined."
  688. );
  689. }
  690. if (current == null) {
  691. return next;
  692. } // Both are not empty. Warning: Never call x.concat(y) when you are not
  693. // certain that x is an Array (x could be a string with concat method).
  694. if (Array.isArray(current)) {
  695. if (Array.isArray(next)) {
  696. current.push.apply(current, next);
  697. return current;
  698. }
  699. current.push(next);
  700. return current;
  701. }
  702. if (Array.isArray(next)) {
  703. // A bit too dangerous to mutate `next`.
  704. return [current].concat(next);
  705. }
  706. return [current, next];
  707. }
  708. /**
  709. * @param {array} arr an "accumulation" of items which is either an Array or
  710. * a single item. Useful when paired with the `accumulate` module. This is a
  711. * simple utility that allows us to reason about a collection of items, but
  712. * handling the case when there is exactly one item (and we do not need to
  713. * allocate an array).
  714. * @param {function} cb Callback invoked with each element or a collection.
  715. * @param {?} [scope] Scope used as `this` in a callback.
  716. */
  717. function forEachAccumulated(arr, cb, scope) {
  718. if (Array.isArray(arr)) {
  719. arr.forEach(cb, scope);
  720. } else if (arr) {
  721. cb.call(scope, arr);
  722. }
  723. }
  724. /**
  725. * Some event types have a notion of different registration names for different
  726. * "phases" of propagation. This finds listeners by a given phase.
  727. */
  728. function listenerAtPhase(inst, event, propagationPhase) {
  729. var registrationName =
  730. event.dispatchConfig.phasedRegistrationNames[propagationPhase];
  731. return getListener(inst, registrationName);
  732. }
  733. /**
  734. * A small set of propagation patterns, each of which will accept a small amount
  735. * of information, and generate a set of "dispatch ready event objects" - which
  736. * are sets of events that have already been annotated with a set of dispatched
  737. * listener functions/ids. The API is designed this way to discourage these
  738. * propagation strategies from actually executing the dispatches, since we
  739. * always want to collect the entire set of dispatches before executing even a
  740. * single one.
  741. */
  742. /**
  743. * Tags a `SyntheticEvent` with dispatched listeners. Creating this function
  744. * here, allows us to not have to bind or create functions for each event.
  745. * Mutating the event's members allows us to not have to create a wrapping
  746. * "dispatch" object that pairs the event with the listener.
  747. */
  748. function accumulateDirectionalDispatches(inst, phase, event) {
  749. {
  750. if (!inst) {
  751. error("Dispatching inst must not be null");
  752. }
  753. }
  754. var listener = listenerAtPhase(inst, event, phase);
  755. if (listener) {
  756. event._dispatchListeners = accumulateInto(
  757. event._dispatchListeners,
  758. listener
  759. );
  760. event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
  761. }
  762. }
  763. /**
  764. * Collect dispatches (must be entirely collected before dispatching - see unit
  765. * tests). Lazily allocate the array to conserve memory. We must loop through
  766. * each event and perform the traversal for each one. We cannot perform a
  767. * single traversal for the entire collection of events because each event may
  768. * have a different target.
  769. */
  770. function accumulateTwoPhaseDispatchesSingle(event) {
  771. if (event && event.dispatchConfig.phasedRegistrationNames) {
  772. traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
  773. }
  774. }
  775. /**
  776. * Same as `accumulateTwoPhaseDispatchesSingle`, but skips over the targetID.
  777. */
  778. function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
  779. if (event && event.dispatchConfig.phasedRegistrationNames) {
  780. var targetInst = event._targetInst;
  781. var parentInst = targetInst ? getParentInstance(targetInst) : null;
  782. traverseTwoPhase(parentInst, accumulateDirectionalDispatches, event);
  783. }
  784. }
  785. /**
  786. * Accumulates without regard to direction, does not look for phased
  787. * registration names. Same as `accumulateDirectDispatchesSingle` but without
  788. * requiring that the `dispatchMarker` be the same as the dispatched ID.
  789. */
  790. function accumulateDispatches(inst, ignoredDirection, event) {
  791. if (inst && event && event.dispatchConfig.registrationName) {
  792. var registrationName = event.dispatchConfig.registrationName;
  793. var listener = getListener(inst, registrationName);
  794. if (listener) {
  795. event._dispatchListeners = accumulateInto(
  796. event._dispatchListeners,
  797. listener
  798. );
  799. event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
  800. }
  801. }
  802. }
  803. /**
  804. * Accumulates dispatches on an `SyntheticEvent`, but only for the
  805. * `dispatchMarker`.
  806. * @param {SyntheticEvent} event
  807. */
  808. function accumulateDirectDispatchesSingle(event) {
  809. if (event && event.dispatchConfig.registrationName) {
  810. accumulateDispatches(event._targetInst, null, event);
  811. }
  812. }
  813. function accumulateTwoPhaseDispatches(events) {
  814. forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle);
  815. }
  816. function accumulateTwoPhaseDispatchesSkipTarget(events) {
  817. forEachAccumulated(events, accumulateTwoPhaseDispatchesSingleSkipTarget);
  818. }
  819. function accumulateDirectDispatches(events) {
  820. forEachAccumulated(events, accumulateDirectDispatchesSingle);
  821. }
  822. var EVENT_POOL_SIZE = 10;
  823. /**
  824. * @interface Event
  825. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  826. */
  827. var EventInterface = {
  828. type: null,
  829. target: null,
  830. // currentTarget is set when dispatching; no use in copying it here
  831. currentTarget: function() {
  832. return null;
  833. },
  834. eventPhase: null,
  835. bubbles: null,
  836. cancelable: null,
  837. timeStamp: function(event) {
  838. return event.timeStamp || Date.now();
  839. },
  840. defaultPrevented: null,
  841. isTrusted: null
  842. };
  843. function functionThatReturnsTrue() {
  844. return true;
  845. }
  846. function functionThatReturnsFalse() {
  847. return false;
  848. }
  849. /**
  850. * Synthetic events are dispatched by event plugins, typically in response to a
  851. * top-level event delegation handler.
  852. *
  853. * These systems should generally use pooling to reduce the frequency of garbage
  854. * collection. The system should check `isPersistent` to determine whether the
  855. * event should be released into the pool after being dispatched. Users that
  856. * need a persisted event should invoke `persist`.
  857. *
  858. * Synthetic events (and subclasses) implement the DOM Level 3 Events API by
  859. * normalizing browser quirks. Subclasses do not necessarily have to implement a
  860. * DOM interface; custom application-specific events can also subclass this.
  861. *
  862. * @param {object} dispatchConfig Configuration used to dispatch this event.
  863. * @param {*} targetInst Marker identifying the event target.
  864. * @param {object} nativeEvent Native browser event.
  865. * @param {DOMEventTarget} nativeEventTarget Target node.
  866. */
  867. function SyntheticEvent(
  868. dispatchConfig,
  869. targetInst,
  870. nativeEvent,
  871. nativeEventTarget
  872. ) {
  873. {
  874. // these have a getter/setter for warnings
  875. delete this.nativeEvent;
  876. delete this.preventDefault;
  877. delete this.stopPropagation;
  878. delete this.isDefaultPrevented;
  879. delete this.isPropagationStopped;
  880. }
  881. this.dispatchConfig = dispatchConfig;
  882. this._targetInst = targetInst;
  883. this.nativeEvent = nativeEvent;
  884. var Interface = this.constructor.Interface;
  885. for (var propName in Interface) {
  886. if (!Interface.hasOwnProperty(propName)) {
  887. continue;
  888. }
  889. {
  890. delete this[propName]; // this has a getter/setter for warnings
  891. }
  892. var normalize = Interface[propName];
  893. if (normalize) {
  894. this[propName] = normalize(nativeEvent);
  895. } else {
  896. if (propName === "target") {
  897. this.target = nativeEventTarget;
  898. } else {
  899. this[propName] = nativeEvent[propName];
  900. }
  901. }
  902. }
  903. var defaultPrevented =
  904. nativeEvent.defaultPrevented != null
  905. ? nativeEvent.defaultPrevented
  906. : nativeEvent.returnValue === false;
  907. if (defaultPrevented) {
  908. this.isDefaultPrevented = functionThatReturnsTrue;
  909. } else {
  910. this.isDefaultPrevented = functionThatReturnsFalse;
  911. }
  912. this.isPropagationStopped = functionThatReturnsFalse;
  913. return this;
  914. }
  915. Object.assign(SyntheticEvent.prototype, {
  916. preventDefault: function() {
  917. this.defaultPrevented = true;
  918. var event = this.nativeEvent;
  919. if (!event) {
  920. return;
  921. }
  922. if (event.preventDefault) {
  923. event.preventDefault();
  924. } else if (typeof event.returnValue !== "unknown") {
  925. event.returnValue = false;
  926. }
  927. this.isDefaultPrevented = functionThatReturnsTrue;
  928. },
  929. stopPropagation: function() {
  930. var event = this.nativeEvent;
  931. if (!event) {
  932. return;
  933. }
  934. if (event.stopPropagation) {
  935. event.stopPropagation();
  936. } else if (typeof event.cancelBubble !== "unknown") {
  937. // The ChangeEventPlugin registers a "propertychange" event for
  938. // IE. This event does not support bubbling or cancelling, and
  939. // any references to cancelBubble throw "Member not found". A
  940. // typeof check of "unknown" circumvents this issue (and is also
  941. // IE specific).
  942. event.cancelBubble = true;
  943. }
  944. this.isPropagationStopped = functionThatReturnsTrue;
  945. },
  946. /**
  947. * We release all dispatched `SyntheticEvent`s after each event loop, adding
  948. * them back into the pool. This allows a way to hold onto a reference that
  949. * won't be added back into the pool.
  950. */
  951. persist: function() {
  952. this.isPersistent = functionThatReturnsTrue;
  953. },
  954. /**
  955. * Checks if this event should be released back into the pool.
  956. *
  957. * @return {boolean} True if this should not be released, false otherwise.
  958. */
  959. isPersistent: functionThatReturnsFalse,
  960. /**
  961. * `PooledClass` looks for `destructor` on each instance it releases.
  962. */
  963. destructor: function() {
  964. var Interface = this.constructor.Interface;
  965. for (var propName in Interface) {
  966. {
  967. Object.defineProperty(
  968. this,
  969. propName,
  970. getPooledWarningPropertyDefinition(propName, Interface[propName])
  971. );
  972. }
  973. }
  974. this.dispatchConfig = null;
  975. this._targetInst = null;
  976. this.nativeEvent = null;
  977. this.isDefaultPrevented = functionThatReturnsFalse;
  978. this.isPropagationStopped = functionThatReturnsFalse;
  979. this._dispatchListeners = null;
  980. this._dispatchInstances = null;
  981. {
  982. Object.defineProperty(
  983. this,
  984. "nativeEvent",
  985. getPooledWarningPropertyDefinition("nativeEvent", null)
  986. );
  987. Object.defineProperty(
  988. this,
  989. "isDefaultPrevented",
  990. getPooledWarningPropertyDefinition(
  991. "isDefaultPrevented",
  992. functionThatReturnsFalse
  993. )
  994. );
  995. Object.defineProperty(
  996. this,
  997. "isPropagationStopped",
  998. getPooledWarningPropertyDefinition(
  999. "isPropagationStopped",
  1000. functionThatReturnsFalse
  1001. )
  1002. );
  1003. Object.defineProperty(
  1004. this,
  1005. "preventDefault",
  1006. getPooledWarningPropertyDefinition("preventDefault", function() {})
  1007. );
  1008. Object.defineProperty(
  1009. this,
  1010. "stopPropagation",
  1011. getPooledWarningPropertyDefinition("stopPropagation", function() {})
  1012. );
  1013. }
  1014. }
  1015. });
  1016. SyntheticEvent.Interface = EventInterface;
  1017. /**
  1018. * Helper to reduce boilerplate when creating subclasses.
  1019. */
  1020. SyntheticEvent.extend = function(Interface) {
  1021. var Super = this;
  1022. var E = function() {};
  1023. E.prototype = Super.prototype;
  1024. var prototype = new E();
  1025. function Class() {
  1026. return Super.apply(this, arguments);
  1027. }
  1028. Object.assign(prototype, Class.prototype);
  1029. Class.prototype = prototype;
  1030. Class.prototype.constructor = Class;
  1031. Class.Interface = Object.assign({}, Super.Interface, Interface);
  1032. Class.extend = Super.extend;
  1033. addEventPoolingTo(Class);
  1034. return Class;
  1035. };
  1036. addEventPoolingTo(SyntheticEvent);
  1037. /**
  1038. * Helper to nullify syntheticEvent instance properties when destructing
  1039. *
  1040. * @param {String} propName
  1041. * @param {?object} getVal
  1042. * @return {object} defineProperty object
  1043. */
  1044. function getPooledWarningPropertyDefinition(propName, getVal) {
  1045. var isFunction = typeof getVal === "function";
  1046. return {
  1047. configurable: true,
  1048. set: set,
  1049. get: get
  1050. };
  1051. function set(val) {
  1052. var action = isFunction ? "setting the method" : "setting the property";
  1053. warn(action, "This is effectively a no-op");
  1054. return val;
  1055. }
  1056. function get() {
  1057. var action = isFunction ? "accessing the method" : "accessing the property";
  1058. var result = isFunction
  1059. ? "This is a no-op function"
  1060. : "This is set to null";
  1061. warn(action, result);
  1062. return getVal;
  1063. }
  1064. function warn(action, result) {
  1065. {
  1066. error(
  1067. "This synthetic event is reused for performance reasons. If you're seeing this, " +
  1068. "you're %s `%s` on a released/nullified synthetic event. %s. " +
  1069. "If you must keep the original synthetic event around, use event.persist(). " +
  1070. "See https://fb.me/react-event-pooling for more information.",
  1071. action,
  1072. propName,
  1073. result
  1074. );
  1075. }
  1076. }
  1077. }
  1078. function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) {
  1079. var EventConstructor = this;
  1080. if (EventConstructor.eventPool.length) {
  1081. var instance = EventConstructor.eventPool.pop();
  1082. EventConstructor.call(
  1083. instance,
  1084. dispatchConfig,
  1085. targetInst,
  1086. nativeEvent,
  1087. nativeInst
  1088. );
  1089. return instance;
  1090. }
  1091. return new EventConstructor(
  1092. dispatchConfig,
  1093. targetInst,
  1094. nativeEvent,
  1095. nativeInst
  1096. );
  1097. }
  1098. function releasePooledEvent(event) {
  1099. var EventConstructor = this;
  1100. if (!(event instanceof EventConstructor)) {
  1101. throw Error(
  1102. "Trying to release an event instance into a pool of a different type."
  1103. );
  1104. }
  1105. event.destructor();
  1106. if (EventConstructor.eventPool.length < EVENT_POOL_SIZE) {
  1107. EventConstructor.eventPool.push(event);
  1108. }
  1109. }
  1110. function addEventPoolingTo(EventConstructor) {
  1111. EventConstructor.eventPool = [];
  1112. EventConstructor.getPooled = getPooledEvent;
  1113. EventConstructor.release = releasePooledEvent;
  1114. }
  1115. /**
  1116. * `touchHistory` isn't actually on the native event, but putting it in the
  1117. * interface will ensure that it is cleaned up when pooled/destroyed. The
  1118. * `ResponderEventPlugin` will populate it appropriately.
  1119. */
  1120. var ResponderSyntheticEvent = SyntheticEvent.extend({
  1121. touchHistory: function(nativeEvent) {
  1122. return null; // Actually doesn't even look at the native event.
  1123. }
  1124. });
  1125. var TOP_TOUCH_START = "topTouchStart";
  1126. var TOP_TOUCH_MOVE = "topTouchMove";
  1127. var TOP_TOUCH_END = "topTouchEnd";
  1128. var TOP_TOUCH_CANCEL = "topTouchCancel";
  1129. var TOP_SCROLL = "topScroll";
  1130. var TOP_SELECTION_CHANGE = "topSelectionChange";
  1131. function isStartish(topLevelType) {
  1132. return topLevelType === TOP_TOUCH_START;
  1133. }
  1134. function isMoveish(topLevelType) {
  1135. return topLevelType === TOP_TOUCH_MOVE;
  1136. }
  1137. function isEndish(topLevelType) {
  1138. return topLevelType === TOP_TOUCH_END || topLevelType === TOP_TOUCH_CANCEL;
  1139. }
  1140. var startDependencies = [TOP_TOUCH_START];
  1141. var moveDependencies = [TOP_TOUCH_MOVE];
  1142. var endDependencies = [TOP_TOUCH_CANCEL, TOP_TOUCH_END];
  1143. /**
  1144. * Tracks the position and time of each active touch by `touch.identifier`. We
  1145. * should typically only see IDs in the range of 1-20 because IDs get recycled
  1146. * when touches end and start again.
  1147. */
  1148. var MAX_TOUCH_BANK = 20;
  1149. var touchBank = [];
  1150. var touchHistory = {
  1151. touchBank: touchBank,
  1152. numberActiveTouches: 0,
  1153. // If there is only one active touch, we remember its location. This prevents
  1154. // us having to loop through all of the touches all the time in the most
  1155. // common case.
  1156. indexOfSingleActiveTouch: -1,
  1157. mostRecentTimeStamp: 0
  1158. };
  1159. function timestampForTouch(touch) {
  1160. // The legacy internal implementation provides "timeStamp", which has been
  1161. // renamed to "timestamp". Let both work for now while we iron it out
  1162. // TODO (evv): rename timeStamp to timestamp in internal code
  1163. return touch.timeStamp || touch.timestamp;
  1164. }
  1165. /**
  1166. * TODO: Instead of making gestures recompute filtered velocity, we could
  1167. * include a built in velocity computation that can be reused globally.
  1168. */
  1169. function createTouchRecord(touch) {
  1170. return {
  1171. touchActive: true,
  1172. startPageX: touch.pageX,
  1173. startPageY: touch.pageY,
  1174. startTimeStamp: timestampForTouch(touch),
  1175. currentPageX: touch.pageX,
  1176. currentPageY: touch.pageY,
  1177. currentTimeStamp: timestampForTouch(touch),
  1178. previousPageX: touch.pageX,
  1179. previousPageY: touch.pageY,
  1180. previousTimeStamp: timestampForTouch(touch)
  1181. };
  1182. }
  1183. function resetTouchRecord(touchRecord, touch) {
  1184. touchRecord.touchActive = true;
  1185. touchRecord.startPageX = touch.pageX;
  1186. touchRecord.startPageY = touch.pageY;
  1187. touchRecord.startTimeStamp = timestampForTouch(touch);
  1188. touchRecord.currentPageX = touch.pageX;
  1189. touchRecord.currentPageY = touch.pageY;
  1190. touchRecord.currentTimeStamp = timestampForTouch(touch);
  1191. touchRecord.previousPageX = touch.pageX;
  1192. touchRecord.previousPageY = touch.pageY;
  1193. touchRecord.previousTimeStamp = timestampForTouch(touch);
  1194. }
  1195. function getTouchIdentifier(_ref) {
  1196. var identifier = _ref.identifier;
  1197. if (!(identifier != null)) {
  1198. throw Error("Touch object is missing identifier.");
  1199. }
  1200. {
  1201. if (identifier > MAX_TOUCH_BANK) {
  1202. error(
  1203. "Touch identifier %s is greater than maximum supported %s which causes " +
  1204. "performance issues backfilling array locations for all of the indices.",
  1205. identifier,
  1206. MAX_TOUCH_BANK
  1207. );
  1208. }
  1209. }
  1210. return identifier;
  1211. }
  1212. function recordTouchStart(touch) {
  1213. var identifier = getTouchIdentifier(touch);
  1214. var touchRecord = touchBank[identifier];
  1215. if (touchRecord) {
  1216. resetTouchRecord(touchRecord, touch);
  1217. } else {
  1218. touchBank[identifier] = createTouchRecord(touch);
  1219. }
  1220. touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
  1221. }
  1222. function recordTouchMove(touch) {
  1223. var touchRecord = touchBank[getTouchIdentifier(touch)];
  1224. if (touchRecord) {
  1225. touchRecord.touchActive = true;
  1226. touchRecord.previousPageX = touchRecord.currentPageX;
  1227. touchRecord.previousPageY = touchRecord.currentPageY;
  1228. touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
  1229. touchRecord.currentPageX = touch.pageX;
  1230. touchRecord.currentPageY = touch.pageY;
  1231. touchRecord.currentTimeStamp = timestampForTouch(touch);
  1232. touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
  1233. } else {
  1234. {
  1235. warn(
  1236. "Cannot record touch move without a touch start.\n" +
  1237. "Touch Move: %s\n" +
  1238. "Touch Bank: %s",
  1239. printTouch(touch),
  1240. printTouchBank()
  1241. );
  1242. }
  1243. }
  1244. }
  1245. function recordTouchEnd(touch) {
  1246. var touchRecord = touchBank[getTouchIdentifier(touch)];
  1247. if (touchRecord) {
  1248. touchRecord.touchActive = false;
  1249. touchRecord.previousPageX = touchRecord.currentPageX;
  1250. touchRecord.previousPageY = touchRecord.currentPageY;
  1251. touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
  1252. touchRecord.currentPageX = touch.pageX;
  1253. touchRecord.currentPageY = touch.pageY;
  1254. touchRecord.currentTimeStamp = timestampForTouch(touch);
  1255. touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
  1256. } else {
  1257. {
  1258. warn(
  1259. "Cannot record touch end without a touch start.\n" +
  1260. "Touch End: %s\n" +
  1261. "Touch Bank: %s",
  1262. printTouch(touch),
  1263. printTouchBank()
  1264. );
  1265. }
  1266. }
  1267. }
  1268. function printTouch(touch) {
  1269. return JSON.stringify({
  1270. identifier: touch.identifier,
  1271. pageX: touch.pageX,
  1272. pageY: touch.pageY,
  1273. timestamp: timestampForTouch(touch)
  1274. });
  1275. }
  1276. function printTouchBank() {
  1277. var printed = JSON.stringify(touchBank.slice(0, MAX_TOUCH_BANK));
  1278. if (touchBank.length > MAX_TOUCH_BANK) {
  1279. printed += " (original size: " + touchBank.length + ")";
  1280. }
  1281. return printed;
  1282. }
  1283. var ResponderTouchHistoryStore = {
  1284. recordTouchTrack: function(topLevelType, nativeEvent) {
  1285. if (isMoveish(topLevelType)) {
  1286. nativeEvent.changedTouches.forEach(recordTouchMove);
  1287. } else if (isStartish(topLevelType)) {
  1288. nativeEvent.changedTouches.forEach(recordTouchStart);
  1289. touchHistory.numberActiveTouches = nativeEvent.touches.length;
  1290. if (touchHistory.numberActiveTouches === 1) {
  1291. touchHistory.indexOfSingleActiveTouch =
  1292. nativeEvent.touches[0].identifier;
  1293. }
  1294. } else if (isEndish(topLevelType)) {
  1295. nativeEvent.changedTouches.forEach(recordTouchEnd);
  1296. touchHistory.numberActiveTouches = nativeEvent.touches.length;
  1297. if (touchHistory.numberActiveTouches === 1) {
  1298. for (var i = 0; i < touchBank.length; i++) {
  1299. var touchTrackToCheck = touchBank[i];
  1300. if (touchTrackToCheck != null && touchTrackToCheck.touchActive) {
  1301. touchHistory.indexOfSingleActiveTouch = i;
  1302. break;
  1303. }
  1304. }
  1305. {
  1306. var activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch];
  1307. if (activeRecord == null || !activeRecord.touchActive) {
  1308. error("Cannot find single active touch.");
  1309. }
  1310. }
  1311. }
  1312. }
  1313. },
  1314. touchHistory: touchHistory
  1315. };
  1316. /**
  1317. * Accumulates items that must not be null or undefined.
  1318. *
  1319. * This is used to conserve memory by avoiding array allocations.
  1320. *
  1321. * @return {*|array<*>} An accumulation of items.
  1322. */
  1323. function accumulate(current, next) {
  1324. if (!(next != null)) {
  1325. throw Error(
  1326. "accumulate(...): Accumulated items must not be null or undefined."
  1327. );
  1328. }
  1329. if (current == null) {
  1330. return next;
  1331. } // Both are not empty. Warning: Never call x.concat(y) when you are not
  1332. // certain that x is an Array (x could be a string with concat method).
  1333. if (Array.isArray(current)) {
  1334. return current.concat(next);
  1335. }
  1336. if (Array.isArray(next)) {
  1337. return [current].concat(next);
  1338. }
  1339. return [current, next];
  1340. }
  1341. /**
  1342. * Instance of element that should respond to touch/move types of interactions,
  1343. * as indicated explicitly by relevant callbacks.
  1344. */
  1345. var responderInst = null;
  1346. /**
  1347. * Count of current touches. A textInput should become responder iff the
  1348. * selection changes while there is a touch on the screen.
  1349. */
  1350. var trackedTouchCount = 0;
  1351. var changeResponder = function(nextResponderInst, blockHostResponder) {
  1352. var oldResponderInst = responderInst;
  1353. responderInst = nextResponderInst;
  1354. if (ResponderEventPlugin.GlobalResponderHandler !== null) {
  1355. ResponderEventPlugin.GlobalResponderHandler.onChange(
  1356. oldResponderInst,
  1357. nextResponderInst,
  1358. blockHostResponder
  1359. );
  1360. }
  1361. };
  1362. var eventTypes = {
  1363. /**
  1364. * On a `touchStart`/`mouseDown`, is it desired that this element become the
  1365. * responder?
  1366. */
  1367. startShouldSetResponder: {
  1368. phasedRegistrationNames: {
  1369. bubbled: "onStartShouldSetResponder",
  1370. captured: "onStartShouldSetResponderCapture"
  1371. },
  1372. dependencies: startDependencies
  1373. },
  1374. /**
  1375. * On a `scroll`, is it desired that this element become the responder? This
  1376. * is usually not needed, but should be used to retroactively infer that a
  1377. * `touchStart` had occurred during momentum scroll. During a momentum scroll,
  1378. * a touch start will be immediately followed by a scroll event if the view is
  1379. * currently scrolling.
  1380. *
  1381. * TODO: This shouldn't bubble.
  1382. */
  1383. scrollShouldSetResponder: {
  1384. phasedRegistrationNames: {
  1385. bubbled: "onScrollShouldSetResponder",
  1386. captured: "onScrollShouldSetResponderCapture"
  1387. },
  1388. dependencies: [TOP_SCROLL]
  1389. },
  1390. /**
  1391. * On text selection change, should this element become the responder? This
  1392. * is needed for text inputs or other views with native selection, so the
  1393. * JS view can claim the responder.
  1394. *
  1395. * TODO: This shouldn't bubble.
  1396. */
  1397. selectionChangeShouldSetResponder: {
  1398. phasedRegistrationNames: {
  1399. bubbled: "onSelectionChangeShouldSetResponder",
  1400. captured: "onSelectionChangeShouldSetResponderCapture"
  1401. },
  1402. dependencies: [TOP_SELECTION_CHANGE]
  1403. },
  1404. /**
  1405. * On a `touchMove`/`mouseMove`, is it desired that this element become the
  1406. * responder?
  1407. */
  1408. moveShouldSetResponder: {
  1409. phasedRegistrationNames: {
  1410. bubbled: "onMoveShouldSetResponder",
  1411. captured: "onMoveShouldSetResponderCapture"
  1412. },
  1413. dependencies: moveDependencies
  1414. },
  1415. /**
  1416. * Direct responder events dispatched directly to responder. Do not bubble.
  1417. */
  1418. responderStart: {
  1419. registrationName: "onResponderStart",
  1420. dependencies: startDependencies
  1421. },
  1422. responderMove: {
  1423. registrationName: "onResponderMove",
  1424. dependencies: moveDependencies
  1425. },
  1426. responderEnd: {
  1427. registrationName: "onResponderEnd",
  1428. dependencies: endDependencies
  1429. },
  1430. responderRelease: {
  1431. registrationName: "onResponderRelease",
  1432. dependencies: endDependencies
  1433. },
  1434. responderTerminationRequest: {
  1435. registrationName: "onResponderTerminationRequest",
  1436. dependencies: []
  1437. },
  1438. responderGrant: {
  1439. registrationName: "onResponderGrant",
  1440. dependencies: []
  1441. },
  1442. responderReject: {
  1443. registrationName: "onResponderReject",
  1444. dependencies: []
  1445. },
  1446. responderTerminate: {
  1447. registrationName: "onResponderTerminate",
  1448. dependencies: []
  1449. }
  1450. };
  1451. /**
  1452. *
  1453. * Responder System:
  1454. * ----------------
  1455. *
  1456. * - A global, solitary "interaction lock" on a view.
  1457. * - If a node becomes the responder, it should convey visual feedback
  1458. * immediately to indicate so, either by highlighting or moving accordingly.
  1459. * - To be the responder means, that touches are exclusively important to that
  1460. * responder view, and no other view.
  1461. * - While touches are still occurring, the responder lock can be transferred to
  1462. * a new view, but only to increasingly "higher" views (meaning ancestors of
  1463. * the current responder).
  1464. *
  1465. * Responder being granted:
  1466. * ------------------------
  1467. *
  1468. * - Touch starts, moves, and scrolls can cause an ID to become the responder.
  1469. * - We capture/bubble `startShouldSetResponder`/`moveShouldSetResponder` to
  1470. * the "appropriate place".
  1471. * - If nothing is currently the responder, the "appropriate place" is the
  1472. * initiating event's `targetID`.
  1473. * - If something *is* already the responder, the "appropriate place" is the
  1474. * first common ancestor of the event target and the current `responderInst`.
  1475. * - Some negotiation happens: See the timing diagram below.
  1476. * - Scrolled views automatically become responder. The reasoning is that a
  1477. * platform scroll view that isn't built on top of the responder system has
  1478. * began scrolling, and the active responder must now be notified that the
  1479. * interaction is no longer locked to it - the system has taken over.
  1480. *
  1481. * - Responder being released:
  1482. * As soon as no more touches that *started* inside of descendants of the
  1483. * *current* responderInst, an `onResponderRelease` event is dispatched to the
  1484. * current responder, and the responder lock is released.
  1485. *
  1486. * TODO:
  1487. * - on "end", a callback hook for `onResponderEndShouldRemainResponder` that
  1488. * determines if the responder lock should remain.
  1489. * - If a view shouldn't "remain" the responder, any active touches should by
  1490. * default be considered "dead" and do not influence future negotiations or
  1491. * bubble paths. It should be as if those touches do not exist.
  1492. * -- For multitouch: Usually a translate-z will choose to "remain" responder
  1493. * after one out of many touches ended. For translate-y, usually the view
  1494. * doesn't wish to "remain" responder after one of many touches end.
  1495. * - Consider building this on top of a `stopPropagation` model similar to
  1496. * `W3C` events.
  1497. * - Ensure that `onResponderTerminate` is called on touch cancels, whether or
  1498. * not `onResponderTerminationRequest` returns `true` or `false`.
  1499. *
  1500. */
  1501. /* Negotiation Performed
  1502. +-----------------------+
  1503. / \
  1504. Process low level events to + Current Responder + wantsResponderID
  1505. determine who to perform negot-| (if any exists at all) |
  1506. iation/transition | Otherwise just pass through|
  1507. -------------------------------+----------------------------+------------------+
  1508. Bubble to find first ID | |
  1509. to return true:wantsResponderID| |
  1510. | |
  1511. +-------------+ | |
  1512. | onTouchStart| | |
  1513. +------+------+ none | |
  1514. | return| |
  1515. +-----------v-------------+true| +------------------------+ |
  1516. |onStartShouldSetResponder|----->|onResponderStart (cur) |<-----------+
  1517. +-----------+-------------+ | +------------------------+ | |
  1518. | | | +--------+-------+
  1519. | returned true for| false:REJECT +-------->|onResponderReject
  1520. | wantsResponderID | | | +----------------+
  1521. | (now attempt | +------------------+-----+ |
  1522. | handoff) | | onResponder | |
  1523. +------------------->| TerminationRequest| |
  1524. | +------------------+-----+ |
  1525. | | | +----------------+
  1526. | true:GRANT +-------->|onResponderGrant|
  1527. | | +--------+-------+
  1528. | +------------------------+ | |
  1529. | | onResponderTerminate |<-----------+
  1530. | +------------------+-----+ |
  1531. | | | +----------------+
  1532. | +-------->|onResponderStart|
  1533. | | +----------------+
  1534. Bubble to find first ID | |
  1535. to return true:wantsResponderID| |
  1536. | |
  1537. +-------------+ | |
  1538. | onTouchMove | | |
  1539. +------+------+ none | |
  1540. | return| |
  1541. +-----------v-------------+true| +------------------------+ |
  1542. |onMoveShouldSetResponder |----->|onResponderMove (cur) |<-----------+
  1543. +-----------+-------------+ | +------------------------+ | |
  1544. | | | +--------+-------+
  1545. | returned true for| false:REJECT +-------->|onResponderRejec|
  1546. | wantsResponderID | | | +----------------+
  1547. | (now attempt | +------------------+-----+ |
  1548. | handoff) | | onResponder | |
  1549. +------------------->| TerminationRequest| |
  1550. | +------------------+-----+ |
  1551. | | | +----------------+
  1552. | true:GRANT +-------->|onResponderGrant|
  1553. | | +--------+-------+
  1554. | +------------------------+ | |
  1555. | | onResponderTerminate |<-----------+
  1556. | +------------------+-----+ |
  1557. | | | +----------------+
  1558. | +-------->|onResponderMove |
  1559. | | +----------------+
  1560. | |
  1561. | |
  1562. Some active touch started| |
  1563. inside current responder | +------------------------+ |
  1564. +------------------------->| onResponderEnd | |
  1565. | | +------------------------+ |
  1566. +---+---------+ | |
  1567. | onTouchEnd | | |
  1568. +---+---------+ | |
  1569. | | +------------------------+ |
  1570. +------------------------->| onResponderEnd | |
  1571. No active touches started| +-----------+------------+ |
  1572. inside current responder | | |
  1573. | v |
  1574. | +------------------------+ |
  1575. | | onResponderRelease | |
  1576. | +------------------------+ |
  1577. | |
  1578. + + */
  1579. /**
  1580. * A note about event ordering in the `EventPluginRegistry`.
  1581. *
  1582. * Suppose plugins are injected in the following order:
  1583. *
  1584. * `[R, S, C]`
  1585. *
  1586. * To help illustrate the example, assume `S` is `SimpleEventPlugin` (for
  1587. * `onClick` etc) and `R` is `ResponderEventPlugin`.
  1588. *
  1589. * "Deferred-Dispatched Events":
  1590. *
  1591. * - The current event plugin system will traverse the list of injected plugins,
  1592. * in order, and extract events by collecting the plugin's return value of
  1593. * `extractEvents()`.
  1594. * - These events that are returned from `extractEvents` are "deferred
  1595. * dispatched events".
  1596. * - When returned from `extractEvents`, deferred-dispatched events contain an
  1597. * "accumulation" of deferred dispatches.
  1598. * - These deferred dispatches are accumulated/collected before they are
  1599. * returned, but processed at a later time by the `EventPluginRegistry` (hence the
  1600. * name deferred).
  1601. *
  1602. * In the process of returning their deferred-dispatched events, event plugins
  1603. * themselves can dispatch events on-demand without returning them from
  1604. * `extractEvents`. Plugins might want to do this, so that they can use event
  1605. * dispatching as a tool that helps them decide which events should be extracted
  1606. * in the first place.
  1607. *
  1608. * "On-Demand-Dispatched Events":
  1609. *
  1610. * - On-demand-dispatched events are not returned from `extractEvents`.
  1611. * - On-demand-dispatched events are dispatched during the process of returning
  1612. * the deferred-dispatched events.
  1613. * - They should not have side effects.
  1614. * - They should be avoided, and/or eventually be replaced with another
  1615. * abstraction that allows event plugins to perform multiple "rounds" of event
  1616. * extraction.
  1617. *
  1618. * Therefore, the sequence of event dispatches becomes:
  1619. *
  1620. * - `R`s on-demand events (if any) (dispatched by `R` on-demand)
  1621. * - `S`s on-demand events (if any) (dispatched by `S` on-demand)
  1622. * - `C`s on-demand events (if any) (dispatched by `C` on-demand)
  1623. * - `R`s extracted events (if any) (dispatched by `EventPluginRegistry`)
  1624. * - `S`s extracted events (if any) (dispatched by `EventPluginRegistry`)
  1625. * - `C`s extracted events (if any) (dispatched by `EventPluginRegistry`)
  1626. *
  1627. * In the case of `ResponderEventPlugin`: If the `startShouldSetResponder`
  1628. * on-demand dispatch returns `true` (and some other details are satisfied) the
  1629. * `onResponderGrant` deferred dispatched event is returned from
  1630. * `extractEvents`. The sequence of dispatch executions in this case
  1631. * will appear as follows:
  1632. *
  1633. * - `startShouldSetResponder` (`ResponderEventPlugin` dispatches on-demand)
  1634. * - `touchStartCapture` (`EventPluginRegistry` dispatches as usual)
  1635. * - `touchStart` (`EventPluginRegistry` dispatches as usual)
  1636. * - `responderGrant/Reject` (`EventPluginRegistry` dispatches as usual)
  1637. */
  1638. function setResponderAndExtractTransfer(
  1639. topLevelType,
  1640. targetInst,
  1641. nativeEvent,
  1642. nativeEventTarget
  1643. ) {
  1644. var shouldSetEventType = isStartish(topLevelType)
  1645. ? eventTypes.startShouldSetResponder
  1646. : isMoveish(topLevelType)
  1647. ? eventTypes.moveShouldSetResponder
  1648. : topLevelType === TOP_SELECTION_CHANGE
  1649. ? eventTypes.selectionChangeShouldSetResponder
  1650. : eventTypes.scrollShouldSetResponder; // TODO: stop one short of the current responder.
  1651. var bubbleShouldSetFrom = !responderInst
  1652. ? targetInst
  1653. : getLowestCommonAncestor(responderInst, targetInst); // When capturing/bubbling the "shouldSet" event, we want to skip the target
  1654. // (deepest ID) if it happens to be the current responder. The reasoning:
  1655. // It's strange to get an `onMoveShouldSetResponder` when you're *already*
  1656. // the responder.
  1657. var skipOverBubbleShouldSetFrom = bubbleShouldSetFrom === responderInst;
  1658. var shouldSetEvent = ResponderSyntheticEvent.getPooled(
  1659. shouldSetEventType,
  1660. bubbleShouldSetFrom,
  1661. nativeEvent,
  1662. nativeEventTarget
  1663. );
  1664. shouldSetEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1665. if (skipOverBubbleShouldSetFrom) {
  1666. accumulateTwoPhaseDispatchesSkipTarget(shouldSetEvent);
  1667. } else {
  1668. accumulateTwoPhaseDispatches(shouldSetEvent);
  1669. }
  1670. var wantsResponderInst = executeDispatchesInOrderStopAtTrue(shouldSetEvent);
  1671. if (!shouldSetEvent.isPersistent()) {
  1672. shouldSetEvent.constructor.release(shouldSetEvent);
  1673. }
  1674. if (!wantsResponderInst || wantsResponderInst === responderInst) {
  1675. return null;
  1676. }
  1677. var extracted;
  1678. var grantEvent = ResponderSyntheticEvent.getPooled(
  1679. eventTypes.responderGrant,
  1680. wantsResponderInst,
  1681. nativeEvent,
  1682. nativeEventTarget
  1683. );
  1684. grantEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1685. accumulateDirectDispatches(grantEvent);
  1686. var blockHostResponder = executeDirectDispatch(grantEvent) === true;
  1687. if (responderInst) {
  1688. var terminationRequestEvent = ResponderSyntheticEvent.getPooled(
  1689. eventTypes.responderTerminationRequest,
  1690. responderInst,
  1691. nativeEvent,
  1692. nativeEventTarget
  1693. );
  1694. terminationRequestEvent.touchHistory =
  1695. ResponderTouchHistoryStore.touchHistory;
  1696. accumulateDirectDispatches(terminationRequestEvent);
  1697. var shouldSwitch =
  1698. !hasDispatches(terminationRequestEvent) ||
  1699. executeDirectDispatch(terminationRequestEvent);
  1700. if (!terminationRequestEvent.isPersistent()) {
  1701. terminationRequestEvent.constructor.release(terminationRequestEvent);
  1702. }
  1703. if (shouldSwitch) {
  1704. var terminateEvent = ResponderSyntheticEvent.getPooled(
  1705. eventTypes.responderTerminate,
  1706. responderInst,
  1707. nativeEvent,
  1708. nativeEventTarget
  1709. );
  1710. terminateEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1711. accumulateDirectDispatches(terminateEvent);
  1712. extracted = accumulate(extracted, [grantEvent, terminateEvent]);
  1713. changeResponder(wantsResponderInst, blockHostResponder);
  1714. } else {
  1715. var rejectEvent = ResponderSyntheticEvent.getPooled(
  1716. eventTypes.responderReject,
  1717. wantsResponderInst,
  1718. nativeEvent,
  1719. nativeEventTarget
  1720. );
  1721. rejectEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1722. accumulateDirectDispatches(rejectEvent);
  1723. extracted = accumulate(extracted, rejectEvent);
  1724. }
  1725. } else {
  1726. extracted = accumulate(extracted, grantEvent);
  1727. changeResponder(wantsResponderInst, blockHostResponder);
  1728. }
  1729. return extracted;
  1730. }
  1731. /**
  1732. * A transfer is a negotiation between a currently set responder and the next
  1733. * element to claim responder status. Any start event could trigger a transfer
  1734. * of responderInst. Any move event could trigger a transfer.
  1735. *
  1736. * @param {string} topLevelType Record from `BrowserEventConstants`.
  1737. * @return {boolean} True if a transfer of responder could possibly occur.
  1738. */
  1739. function canTriggerTransfer(topLevelType, topLevelInst, nativeEvent) {
  1740. return (
  1741. topLevelInst && // responderIgnoreScroll: We are trying to migrate away from specifically
  1742. // tracking native scroll events here and responderIgnoreScroll indicates we
  1743. // will send topTouchCancel to handle canceling touch events instead
  1744. ((topLevelType === TOP_SCROLL && !nativeEvent.responderIgnoreScroll) ||
  1745. (trackedTouchCount > 0 && topLevelType === TOP_SELECTION_CHANGE) ||
  1746. isStartish(topLevelType) ||
  1747. isMoveish(topLevelType))
  1748. );
  1749. }
  1750. /**
  1751. * Returns whether or not this touch end event makes it such that there are no
  1752. * longer any touches that started inside of the current `responderInst`.
  1753. *
  1754. * @param {NativeEvent} nativeEvent Native touch end event.
  1755. * @return {boolean} Whether or not this touch end event ends the responder.
  1756. */
  1757. function noResponderTouches(nativeEvent) {
  1758. var touches = nativeEvent.touches;
  1759. if (!touches || touches.length === 0) {
  1760. return true;
  1761. }
  1762. for (var i = 0; i < touches.length; i++) {
  1763. var activeTouch = touches[i];
  1764. var target = activeTouch.target;
  1765. if (target !== null && target !== undefined && target !== 0) {
  1766. // Is the original touch location inside of the current responder?
  1767. var targetInst = getInstanceFromNode(target);
  1768. if (isAncestor(responderInst, targetInst)) {
  1769. return false;
  1770. }
  1771. }
  1772. }
  1773. return true;
  1774. }
  1775. var ResponderEventPlugin = {
  1776. /* For unit testing only */
  1777. _getResponder: function() {
  1778. return responderInst;
  1779. },
  1780. eventTypes: eventTypes,
  1781. /**
  1782. * We must be resilient to `targetInst` being `null` on `touchMove` or
  1783. * `touchEnd`. On certain platforms, this means that a native scroll has
  1784. * assumed control and the original touch targets are destroyed.
  1785. */
  1786. extractEvents: function(
  1787. topLevelType,
  1788. targetInst,
  1789. nativeEvent,
  1790. nativeEventTarget,
  1791. eventSystemFlags
  1792. ) {
  1793. if (isStartish(topLevelType)) {
  1794. trackedTouchCount += 1;
  1795. } else if (isEndish(topLevelType)) {
  1796. if (trackedTouchCount >= 0) {
  1797. trackedTouchCount -= 1;
  1798. } else {
  1799. {
  1800. warn(
  1801. "Ended a touch event which was not counted in `trackedTouchCount`."
  1802. );
  1803. }
  1804. return null;
  1805. }
  1806. }
  1807. ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent);
  1808. var extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent)
  1809. ? setResponderAndExtractTransfer(
  1810. topLevelType,
  1811. targetInst,
  1812. nativeEvent,
  1813. nativeEventTarget
  1814. )
  1815. : null; // Responder may or may not have transferred on a new touch start/move.
  1816. // Regardless, whoever is the responder after any potential transfer, we
  1817. // direct all touch start/move/ends to them in the form of
  1818. // `onResponderMove/Start/End`. These will be called for *every* additional
  1819. // finger that move/start/end, dispatched directly to whoever is the
  1820. // current responder at that moment, until the responder is "released".
  1821. //
  1822. // These multiple individual change touch events are are always bookended
  1823. // by `onResponderGrant`, and one of
  1824. // (`onResponderRelease/onResponderTerminate`).
  1825. var isResponderTouchStart = responderInst && isStartish(topLevelType);
  1826. var isResponderTouchMove = responderInst && isMoveish(topLevelType);
  1827. var isResponderTouchEnd = responderInst && isEndish(topLevelType);
  1828. var incrementalTouch = isResponderTouchStart
  1829. ? eventTypes.responderStart
  1830. : isResponderTouchMove
  1831. ? eventTypes.responderMove
  1832. : isResponderTouchEnd
  1833. ? eventTypes.responderEnd
  1834. : null;
  1835. if (incrementalTouch) {
  1836. var gesture = ResponderSyntheticEvent.getPooled(
  1837. incrementalTouch,
  1838. responderInst,
  1839. nativeEvent,
  1840. nativeEventTarget
  1841. );
  1842. gesture.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1843. accumulateDirectDispatches(gesture);
  1844. extracted = accumulate(extracted, gesture);
  1845. }
  1846. var isResponderTerminate =
  1847. responderInst && topLevelType === TOP_TOUCH_CANCEL;
  1848. var isResponderRelease =
  1849. responderInst &&
  1850. !isResponderTerminate &&
  1851. isEndish(topLevelType) &&
  1852. noResponderTouches(nativeEvent);
  1853. var finalTouch = isResponderTerminate
  1854. ? eventTypes.responderTerminate
  1855. : isResponderRelease
  1856. ? eventTypes.responderRelease
  1857. : null;
  1858. if (finalTouch) {
  1859. var finalEvent = ResponderSyntheticEvent.getPooled(
  1860. finalTouch,
  1861. responderInst,
  1862. nativeEvent,
  1863. nativeEventTarget
  1864. );
  1865. finalEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
  1866. accumulateDirectDispatches(finalEvent);
  1867. extracted = accumulate(extracted, finalEvent);
  1868. changeResponder(null);
  1869. }
  1870. return extracted;
  1871. },
  1872. GlobalResponderHandler: null,
  1873. injection: {
  1874. /**
  1875. * @param {{onChange: (ReactID, ReactID) => void} GlobalResponderHandler
  1876. * Object that handles any change in responder. Use this to inject
  1877. * integration with an existing touch handling system etc.
  1878. */
  1879. injectGlobalResponderHandler: function(GlobalResponderHandler) {
  1880. ResponderEventPlugin.GlobalResponderHandler = GlobalResponderHandler;
  1881. }
  1882. }
  1883. };
  1884. /**
  1885. * Injectable ordering of event plugins.
  1886. */
  1887. var eventPluginOrder = null;
  1888. /**
  1889. * Injectable mapping from names to event plugin modules.
  1890. */
  1891. var namesToPlugins = {};
  1892. /**
  1893. * Recomputes the plugin list using the injected plugins and plugin ordering.
  1894. *
  1895. * @private
  1896. */
  1897. function recomputePluginOrdering() {
  1898. if (!eventPluginOrder) {
  1899. // Wait until an `eventPluginOrder` is injected.
  1900. return;
  1901. }
  1902. for (var pluginName in namesToPlugins) {
  1903. var pluginModule = namesToPlugins[pluginName];
  1904. var pluginIndex = eventPluginOrder.indexOf(pluginName);
  1905. if (!(pluginIndex > -1)) {
  1906. throw Error(
  1907. "EventPluginRegistry: Cannot inject event plugins that do not exist in the plugin ordering, `" +
  1908. pluginName +
  1909. "`."
  1910. );
  1911. }
  1912. if (plugins[pluginIndex]) {
  1913. continue;
  1914. }
  1915. if (!pluginModule.extractEvents) {
  1916. throw Error(
  1917. "EventPluginRegistry: Event plugins must implement an `extractEvents` method, but `" +
  1918. pluginName +
  1919. "` does not."
  1920. );
  1921. }
  1922. plugins[pluginIndex] = pluginModule;
  1923. var publishedEvents = pluginModule.eventTypes;
  1924. for (var eventName in publishedEvents) {
  1925. if (
  1926. !publishEventForPlugin(
  1927. publishedEvents[eventName],
  1928. pluginModule,
  1929. eventName
  1930. )
  1931. ) {
  1932. throw Error(
  1933. "EventPluginRegistry: Failed to publish event `" +
  1934. eventName +
  1935. "` for plugin `" +
  1936. pluginName +
  1937. "`."
  1938. );
  1939. }
  1940. }
  1941. }
  1942. }
  1943. /**
  1944. * Publishes an event so that it can be dispatched by the supplied plugin.
  1945. *
  1946. * @param {object} dispatchConfig Dispatch configuration for the event.
  1947. * @param {object} PluginModule Plugin publishing the event.
  1948. * @return {boolean} True if the event was successfully published.
  1949. * @private
  1950. */
  1951. function publishEventForPlugin(dispatchConfig, pluginModule, eventName) {
  1952. if (!!eventNameDispatchConfigs.hasOwnProperty(eventName)) {
  1953. throw Error(
  1954. "EventPluginRegistry: More than one plugin attempted to publish the same event name, `" +
  1955. eventName +
  1956. "`."
  1957. );
  1958. }
  1959. eventNameDispatchConfigs[eventName] = dispatchConfig;
  1960. var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
  1961. if (phasedRegistrationNames) {
  1962. for (var phaseName in phasedRegistrationNames) {
  1963. if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
  1964. var phasedRegistrationName = phasedRegistrationNames[phaseName];
  1965. publishRegistrationName(
  1966. phasedRegistrationName,
  1967. pluginModule,
  1968. eventName
  1969. );
  1970. }
  1971. }
  1972. return true;
  1973. } else if (dispatchConfig.registrationName) {
  1974. publishRegistrationName(
  1975. dispatchConfig.registrationName,
  1976. pluginModule,
  1977. eventName
  1978. );
  1979. return true;
  1980. }
  1981. return false;
  1982. }
  1983. /**
  1984. * Publishes a registration name that is used to identify dispatched events.
  1985. *
  1986. * @param {string} registrationName Registration name to add.
  1987. * @param {object} PluginModule Plugin publishing the event.
  1988. * @private
  1989. */
  1990. function publishRegistrationName(registrationName, pluginModule, eventName) {
  1991. if (!!registrationNameModules[registrationName]) {
  1992. throw Error(
  1993. "EventPluginRegistry: More than one plugin attempted to publish the same registration name, `" +
  1994. registrationName +
  1995. "`."
  1996. );
  1997. }
  1998. registrationNameModules[registrationName] = pluginModule;
  1999. registrationNameDependencies[registrationName] =
  2000. pluginModule.eventTypes[eventName].dependencies;
  2001. {
  2002. var lowerCasedName = registrationName.toLowerCase();
  2003. }
  2004. }
  2005. /**
  2006. * Registers plugins so that they can extract and dispatch events.
  2007. */
  2008. /**
  2009. * Ordered list of injected plugins.
  2010. */
  2011. var plugins = [];
  2012. /**
  2013. * Mapping from event name to dispatch config
  2014. */
  2015. var eventNameDispatchConfigs = {};
  2016. /**
  2017. * Mapping from registration name to plugin module
  2018. */
  2019. var registrationNameModules = {};
  2020. /**
  2021. * Mapping from registration name to event name
  2022. */
  2023. var registrationNameDependencies = {};
  2024. /**
  2025. * Injects an ordering of plugins (by plugin name). This allows the ordering
  2026. * to be decoupled from injection of the actual plugins so that ordering is
  2027. * always deterministic regardless of packaging, on-the-fly injection, etc.
  2028. *
  2029. * @param {array} InjectedEventPluginOrder
  2030. * @internal
  2031. */
  2032. function injectEventPluginOrder(injectedEventPluginOrder) {
  2033. if (!!eventPluginOrder) {
  2034. throw Error(
  2035. "EventPluginRegistry: Cannot inject event plugin ordering more than once. You are likely trying to load more than one copy of React."
  2036. );
  2037. } // Clone the ordering so it cannot be dynamically mutated.
  2038. eventPluginOrder = Array.prototype.slice.call(injectedEventPluginOrder);
  2039. recomputePluginOrdering();
  2040. }
  2041. /**
  2042. * Injects plugins to be used by plugin event system. The plugin names must be
  2043. * in the ordering injected by `injectEventPluginOrder`.
  2044. *
  2045. * Plugins can be injected as part of page initialization or on-the-fly.
  2046. *
  2047. * @param {object} injectedNamesToPlugins Map from names to plugin modules.
  2048. * @internal
  2049. */
  2050. function injectEventPluginsByName(injectedNamesToPlugins) {
  2051. var isOrderingDirty = false;
  2052. for (var pluginName in injectedNamesToPlugins) {
  2053. if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
  2054. continue;
  2055. }
  2056. var pluginModule = injectedNamesToPlugins[pluginName];
  2057. if (
  2058. !namesToPlugins.hasOwnProperty(pluginName) ||
  2059. namesToPlugins[pluginName] !== pluginModule
  2060. ) {
  2061. if (!!namesToPlugins[pluginName]) {
  2062. throw Error(
  2063. "EventPluginRegistry: Cannot inject two different event plugins using the same name, `" +
  2064. pluginName +
  2065. "`."
  2066. );
  2067. }
  2068. namesToPlugins[pluginName] = pluginModule;
  2069. isOrderingDirty = true;
  2070. }
  2071. }
  2072. if (isOrderingDirty) {
  2073. recomputePluginOrdering();
  2074. }
  2075. }
  2076. var customBubblingEventTypes =
  2077. ReactNativePrivateInterface.ReactNativeViewConfigRegistry
  2078. .customBubblingEventTypes,
  2079. customDirectEventTypes =
  2080. ReactNativePrivateInterface.ReactNativeViewConfigRegistry
  2081. .customDirectEventTypes;
  2082. var ReactNativeBridgeEventPlugin = {
  2083. eventTypes: {},
  2084. extractEvents: function(
  2085. topLevelType,
  2086. targetInst,
  2087. nativeEvent,
  2088. nativeEventTarget,
  2089. eventSystemFlags
  2090. ) {
  2091. if (targetInst == null) {
  2092. // Probably a node belonging to another renderer's tree.
  2093. return null;
  2094. }
  2095. var bubbleDispatchConfig = customBubblingEventTypes[topLevelType];
  2096. var directDispatchConfig = customDirectEventTypes[topLevelType];
  2097. if (!(bubbleDispatchConfig || directDispatchConfig)) {
  2098. throw Error(
  2099. 'Unsupported top level event type "' + topLevelType + '" dispatched'
  2100. );
  2101. }
  2102. var event = SyntheticEvent.getPooled(
  2103. bubbleDispatchConfig || directDispatchConfig,
  2104. targetInst,
  2105. nativeEvent,
  2106. nativeEventTarget
  2107. );
  2108. if (bubbleDispatchConfig) {
  2109. accumulateTwoPhaseDispatches(event);
  2110. } else if (directDispatchConfig) {
  2111. accumulateDirectDispatches(event);
  2112. } else {
  2113. return null;
  2114. }
  2115. return event;
  2116. }
  2117. };
  2118. var ReactNativeEventPluginOrder = [
  2119. "ResponderEventPlugin",
  2120. "ReactNativeBridgeEventPlugin"
  2121. ];
  2122. /**
  2123. * Make sure essential globals are available and are patched correctly. Please don't remove this
  2124. * line. Bundles created by react-packager `require` it before executing any application code. This
  2125. * ensures it exists in the dependency graph and can be `require`d.
  2126. * TODO: require this in packager, not in React #10932517
  2127. */
  2128. /**
  2129. * Inject module for resolving DOM hierarchy and plugin ordering.
  2130. */
  2131. injectEventPluginOrder(ReactNativeEventPluginOrder);
  2132. /**
  2133. * Some important event plugins included by default (without having to require
  2134. * them).
  2135. */
  2136. injectEventPluginsByName({
  2137. ResponderEventPlugin: ResponderEventPlugin,
  2138. ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin
  2139. });
  2140. function getInstanceFromInstance(instanceHandle) {
  2141. return instanceHandle;
  2142. }
  2143. function getTagFromInstance(inst) {
  2144. var nativeInstance = inst.stateNode.canonical;
  2145. if (!nativeInstance._nativeTag) {
  2146. throw Error("All native instances should have a tag.");
  2147. }
  2148. return nativeInstance;
  2149. }
  2150. function getFiberCurrentPropsFromNode$1(inst) {
  2151. return inst.canonical.currentProps;
  2152. }
  2153. // Module provided by RN:
  2154. var ReactFabricGlobalResponderHandler = {
  2155. onChange: function(from, to, blockNativeResponder) {
  2156. if (to !== null) {
  2157. var tag = to.stateNode.canonical._nativeTag;
  2158. ReactNativePrivateInterface.UIManager.setJSResponder(
  2159. tag,
  2160. blockNativeResponder
  2161. );
  2162. } else {
  2163. ReactNativePrivateInterface.UIManager.clearJSResponder();
  2164. }
  2165. }
  2166. };
  2167. setComponentTree(
  2168. getFiberCurrentPropsFromNode$1,
  2169. getInstanceFromInstance,
  2170. getTagFromInstance
  2171. );
  2172. ResponderEventPlugin.injection.injectGlobalResponderHandler(
  2173. ReactFabricGlobalResponderHandler
  2174. );
  2175. /**
  2176. * `ReactInstanceMap` maintains a mapping from a public facing stateful
  2177. * instance (key) and the internal representation (value). This allows public
  2178. * methods to accept the user facing instance as an argument and map them back
  2179. * to internal methods.
  2180. *
  2181. * Note that this module is currently shared and assumed to be stateless.
  2182. * If this becomes an actual Map, that will break.
  2183. */
  2184. function get(key) {
  2185. return key._reactInternalFiber;
  2186. }
  2187. function set(key, value) {
  2188. key._reactInternalFiber = value;
  2189. }
  2190. // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
  2191. // nor polyfill, then a plain number is used for performance.
  2192. var hasSymbol = typeof Symbol === "function" && Symbol.for;
  2193. var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for("react.element") : 0xeac7;
  2194. var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for("react.portal") : 0xeaca;
  2195. var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for("react.fragment") : 0xeacb;
  2196. var REACT_STRICT_MODE_TYPE = hasSymbol
  2197. ? Symbol.for("react.strict_mode")
  2198. : 0xeacc;
  2199. var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for("react.profiler") : 0xead2;
  2200. var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for("react.provider") : 0xeacd;
  2201. var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for("react.context") : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
  2202. var REACT_CONCURRENT_MODE_TYPE = hasSymbol
  2203. ? Symbol.for("react.concurrent_mode")
  2204. : 0xeacf;
  2205. var REACT_FORWARD_REF_TYPE = hasSymbol
  2206. ? Symbol.for("react.forward_ref")
  2207. : 0xead0;
  2208. var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for("react.suspense") : 0xead1;
  2209. var REACT_SUSPENSE_LIST_TYPE = hasSymbol
  2210. ? Symbol.for("react.suspense_list")
  2211. : 0xead8;
  2212. var REACT_MEMO_TYPE = hasSymbol ? Symbol.for("react.memo") : 0xead3;
  2213. var REACT_LAZY_TYPE = hasSymbol ? Symbol.for("react.lazy") : 0xead4;
  2214. var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for("react.block") : 0xead9;
  2215. var MAYBE_ITERATOR_SYMBOL = typeof Symbol === "function" && Symbol.iterator;
  2216. var FAUX_ITERATOR_SYMBOL = "@@iterator";
  2217. function getIteratorFn(maybeIterable) {
  2218. if (maybeIterable === null || typeof maybeIterable !== "object") {
  2219. return null;
  2220. }
  2221. var maybeIterator =
  2222. (MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL]) ||
  2223. maybeIterable[FAUX_ITERATOR_SYMBOL];
  2224. if (typeof maybeIterator === "function") {
  2225. return maybeIterator;
  2226. }
  2227. return null;
  2228. }
  2229. // TODO: Move this to "react" once we can import from externals.
  2230. var Uninitialized = -1;
  2231. var Pending = 0;
  2232. var Resolved = 1;
  2233. var Rejected = 2;
  2234. function refineResolvedLazyComponent(lazyComponent) {
  2235. return lazyComponent._status === Resolved ? lazyComponent._result : null;
  2236. }
  2237. function initializeLazyComponentType(lazyComponent) {
  2238. if (lazyComponent._status === Uninitialized) {
  2239. var ctor = lazyComponent._result;
  2240. if (!ctor) {
  2241. // TODO: Remove this later. THis only exists in case you use an older "react" package.
  2242. ctor = lazyComponent._ctor;
  2243. }
  2244. var thenable = ctor(); // Transition to the next state.
  2245. var pending = lazyComponent;
  2246. pending._status = Pending;
  2247. pending._result = thenable;
  2248. thenable.then(
  2249. function(moduleObject) {
  2250. if (lazyComponent._status === Pending) {
  2251. var defaultExport = moduleObject.default;
  2252. {
  2253. if (defaultExport === undefined) {
  2254. error(
  2255. "lazy: Expected the result of a dynamic import() call. " +
  2256. "Instead received: %s\n\nYour code should look like: \n " + // Break up imports to avoid accidentally parsing them as dependencies.
  2257. "const MyComponent = lazy(() => imp" +
  2258. "ort('./MyComponent'))",
  2259. moduleObject
  2260. );
  2261. }
  2262. } // Transition to the next state.
  2263. var resolved = lazyComponent;
  2264. resolved._status = Resolved;
  2265. resolved._result = defaultExport;
  2266. }
  2267. },
  2268. function(error) {
  2269. if (lazyComponent._status === Pending) {
  2270. // Transition to the next state.
  2271. var rejected = lazyComponent;
  2272. rejected._status = Rejected;
  2273. rejected._result = error;
  2274. }
  2275. }
  2276. );
  2277. }
  2278. }
  2279. function getWrappedName(outerType, innerType, wrapperName) {
  2280. var functionName = innerType.displayName || innerType.name || "";
  2281. return (
  2282. outerType.displayName ||
  2283. (functionName !== "" ? wrapperName + "(" + functionName + ")" : wrapperName)
  2284. );
  2285. }
  2286. function getContextName(type) {
  2287. return type.displayName || "Context";
  2288. }
  2289. function getComponentName(type) {
  2290. if (type == null) {
  2291. // Host root, text node or just invalid type.
  2292. return null;
  2293. }
  2294. {
  2295. if (typeof type.tag === "number") {
  2296. error(
  2297. "Received an unexpected object in getComponentName(). " +
  2298. "This is likely a bug in React. Please file an issue."
  2299. );
  2300. }
  2301. }
  2302. if (typeof type === "function") {
  2303. return type.displayName || type.name || null;
  2304. }
  2305. if (typeof type === "string") {
  2306. return type;
  2307. }
  2308. switch (type) {
  2309. case REACT_FRAGMENT_TYPE:
  2310. return "Fragment";
  2311. case REACT_PORTAL_TYPE:
  2312. return "Portal";
  2313. case REACT_PROFILER_TYPE:
  2314. return "Profiler";
  2315. case REACT_STRICT_MODE_TYPE:
  2316. return "StrictMode";
  2317. case REACT_SUSPENSE_TYPE:
  2318. return "Suspense";
  2319. case REACT_SUSPENSE_LIST_TYPE:
  2320. return "SuspenseList";
  2321. }
  2322. if (typeof type === "object") {
  2323. switch (type.$$typeof) {
  2324. case REACT_CONTEXT_TYPE:
  2325. var context = type;
  2326. return getContextName(context) + ".Consumer";
  2327. case REACT_PROVIDER_TYPE:
  2328. var provider = type;
  2329. return getContextName(provider._context) + ".Provider";
  2330. case REACT_FORWARD_REF_TYPE:
  2331. return getWrappedName(type, type.render, "ForwardRef");
  2332. case REACT_MEMO_TYPE:
  2333. return getComponentName(type.type);
  2334. case REACT_BLOCK_TYPE:
  2335. return getComponentName(type.render);
  2336. case REACT_LAZY_TYPE: {
  2337. var thenable = type;
  2338. var resolvedThenable = refineResolvedLazyComponent(thenable);
  2339. if (resolvedThenable) {
  2340. return getComponentName(resolvedThenable);
  2341. }
  2342. break;
  2343. }
  2344. }
  2345. }
  2346. return null;
  2347. }
  2348. // Don't change these two values. They're used by React Dev Tools.
  2349. var NoEffect =
  2350. /* */
  2351. 0;
  2352. var PerformedWork =
  2353. /* */
  2354. 1; // You can change the rest (and add more).
  2355. var Placement =
  2356. /* */
  2357. 2;
  2358. var Update =
  2359. /* */
  2360. 4;
  2361. var PlacementAndUpdate =
  2362. /* */
  2363. 6;
  2364. var Deletion =
  2365. /* */
  2366. 8;
  2367. var ContentReset =
  2368. /* */
  2369. 16;
  2370. var Callback =
  2371. /* */
  2372. 32;
  2373. var DidCapture =
  2374. /* */
  2375. 64;
  2376. var Ref =
  2377. /* */
  2378. 128;
  2379. var Snapshot =
  2380. /* */
  2381. 256;
  2382. var Passive =
  2383. /* */
  2384. 512;
  2385. var Hydrating =
  2386. /* */
  2387. 1024;
  2388. var HydratingAndUpdate =
  2389. /* */
  2390. 1028; // Passive & Update & Callback & Ref & Snapshot
  2391. var LifecycleEffectMask =
  2392. /* */
  2393. 932; // Union of all host effects
  2394. var HostEffectMask =
  2395. /* */
  2396. 2047;
  2397. var Incomplete =
  2398. /* */
  2399. 2048;
  2400. var ShouldCapture =
  2401. /* */
  2402. 4096;
  2403. var enableProfilerTimer = true;
  2404. var warnAboutStringRefs = false;
  2405. var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
  2406. function getNearestMountedFiber(fiber) {
  2407. var node = fiber;
  2408. var nearestMounted = fiber;
  2409. if (!fiber.alternate) {
  2410. // If there is no alternate, this might be a new tree that isn't inserted
  2411. // yet. If it is, then it will have a pending insertion effect on it.
  2412. var nextNode = node;
  2413. do {
  2414. node = nextNode;
  2415. if ((node.effectTag & (Placement | Hydrating)) !== NoEffect) {
  2416. // This is an insertion or in-progress hydration. The nearest possible
  2417. // mounted fiber is the parent but we need to continue to figure out
  2418. // if that one is still mounted.
  2419. nearestMounted = node.return;
  2420. }
  2421. nextNode = node.return;
  2422. } while (nextNode);
  2423. } else {
  2424. while (node.return) {
  2425. node = node.return;
  2426. }
  2427. }
  2428. if (node.tag === HostRoot) {
  2429. // TODO: Check if this was a nested HostRoot when used with
  2430. // renderContainerIntoSubtree.
  2431. return nearestMounted;
  2432. } // If we didn't hit the root, that means that we're in an disconnected tree
  2433. // that has been unmounted.
  2434. return null;
  2435. }
  2436. function isFiberMounted(fiber) {
  2437. return getNearestMountedFiber(fiber) === fiber;
  2438. }
  2439. function isMounted(component) {
  2440. {
  2441. var owner = ReactCurrentOwner.current;
  2442. if (owner !== null && owner.tag === ClassComponent) {
  2443. var ownerFiber = owner;
  2444. var instance = ownerFiber.stateNode;
  2445. if (!instance._warnedAboutRefsInRender) {
  2446. error(
  2447. "%s is accessing isMounted inside its render() function. " +
  2448. "render() should be a pure function of props and state. It should " +
  2449. "never access something that requires stale data from the previous " +
  2450. "render, such as refs. Move this logic to componentDidMount and " +
  2451. "componentDidUpdate instead.",
  2452. getComponentName(ownerFiber.type) || "A component"
  2453. );
  2454. }
  2455. instance._warnedAboutRefsInRender = true;
  2456. }
  2457. }
  2458. var fiber = get(component);
  2459. if (!fiber) {
  2460. return false;
  2461. }
  2462. return getNearestMountedFiber(fiber) === fiber;
  2463. }
  2464. function assertIsMounted(fiber) {
  2465. if (!(getNearestMountedFiber(fiber) === fiber)) {
  2466. throw Error("Unable to find node on an unmounted component.");
  2467. }
  2468. }
  2469. function findCurrentFiberUsingSlowPath(fiber) {
  2470. var alternate = fiber.alternate;
  2471. if (!alternate) {
  2472. // If there is no alternate, then we only need to check if it is mounted.
  2473. var nearestMounted = getNearestMountedFiber(fiber);
  2474. if (!(nearestMounted !== null)) {
  2475. throw Error("Unable to find node on an unmounted component.");
  2476. }
  2477. if (nearestMounted !== fiber) {
  2478. return null;
  2479. }
  2480. return fiber;
  2481. } // If we have two possible branches, we'll walk backwards up to the root
  2482. // to see what path the root points to. On the way we may hit one of the
  2483. // special cases and we'll deal with them.
  2484. var a = fiber;
  2485. var b = alternate;
  2486. while (true) {
  2487. var parentA = a.return;
  2488. if (parentA === null) {
  2489. // We're at the root.
  2490. break;
  2491. }
  2492. var parentB = parentA.alternate;
  2493. if (parentB === null) {
  2494. // There is no alternate. This is an unusual case. Currently, it only
  2495. // happens when a Suspense component is hidden. An extra fragment fiber
  2496. // is inserted in between the Suspense fiber and its children. Skip
  2497. // over this extra fragment fiber and proceed to the next parent.
  2498. var nextParent = parentA.return;
  2499. if (nextParent !== null) {
  2500. a = b = nextParent;
  2501. continue;
  2502. } // If there's no parent, we're at the root.
  2503. break;
  2504. } // If both copies of the parent fiber point to the same child, we can
  2505. // assume that the child is current. This happens when we bailout on low
  2506. // priority: the bailed out fiber's child reuses the current child.
  2507. if (parentA.child === parentB.child) {
  2508. var child = parentA.child;
  2509. while (child) {
  2510. if (child === a) {
  2511. // We've determined that A is the current branch.
  2512. assertIsMounted(parentA);
  2513. return fiber;
  2514. }
  2515. if (child === b) {
  2516. // We've determined that B is the current branch.
  2517. assertIsMounted(parentA);
  2518. return alternate;
  2519. }
  2520. child = child.sibling;
  2521. } // We should never have an alternate for any mounting node. So the only
  2522. // way this could possibly happen is if this was unmounted, if at all.
  2523. {
  2524. throw Error("Unable to find node on an unmounted component.");
  2525. }
  2526. }
  2527. if (a.return !== b.return) {
  2528. // The return pointer of A and the return pointer of B point to different
  2529. // fibers. We assume that return pointers never criss-cross, so A must
  2530. // belong to the child set of A.return, and B must belong to the child
  2531. // set of B.return.
  2532. a = parentA;
  2533. b = parentB;
  2534. } else {
  2535. // The return pointers point to the same fiber. We'll have to use the
  2536. // default, slow path: scan the child sets of each parent alternate to see
  2537. // which child belongs to which set.
  2538. //
  2539. // Search parent A's child set
  2540. var didFindChild = false;
  2541. var _child = parentA.child;
  2542. while (_child) {
  2543. if (_child === a) {
  2544. didFindChild = true;
  2545. a = parentA;
  2546. b = parentB;
  2547. break;
  2548. }
  2549. if (_child === b) {
  2550. didFindChild = true;
  2551. b = parentA;
  2552. a = parentB;
  2553. break;
  2554. }
  2555. _child = _child.sibling;
  2556. }
  2557. if (!didFindChild) {
  2558. // Search parent B's child set
  2559. _child = parentB.child;
  2560. while (_child) {
  2561. if (_child === a) {
  2562. didFindChild = true;
  2563. a = parentB;
  2564. b = parentA;
  2565. break;
  2566. }
  2567. if (_child === b) {
  2568. didFindChild = true;
  2569. b = parentB;
  2570. a = parentA;
  2571. break;
  2572. }
  2573. _child = _child.sibling;
  2574. }
  2575. if (!didFindChild) {
  2576. throw Error(
  2577. "Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue."
  2578. );
  2579. }
  2580. }
  2581. }
  2582. if (!(a.alternate === b)) {
  2583. throw Error(
  2584. "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue."
  2585. );
  2586. }
  2587. } // If the root is not a host container, we're in a disconnected tree. I.e.
  2588. // unmounted.
  2589. if (!(a.tag === HostRoot)) {
  2590. throw Error("Unable to find node on an unmounted component.");
  2591. }
  2592. if (a.stateNode.current === a) {
  2593. // We've determined that A is the current branch.
  2594. return fiber;
  2595. } // Otherwise B has to be current branch.
  2596. return alternate;
  2597. }
  2598. function findCurrentHostFiber(parent) {
  2599. var currentParent = findCurrentFiberUsingSlowPath(parent);
  2600. if (!currentParent) {
  2601. return null;
  2602. } // Next we'll drill down this component to find the first HostComponent/Text.
  2603. var node = currentParent;
  2604. while (true) {
  2605. if (node.tag === HostComponent || node.tag === HostText) {
  2606. return node;
  2607. } else if (node.child) {
  2608. node.child.return = node;
  2609. node = node.child;
  2610. continue;
  2611. }
  2612. if (node === currentParent) {
  2613. return null;
  2614. }
  2615. while (!node.sibling) {
  2616. if (!node.return || node.return === currentParent) {
  2617. return null;
  2618. }
  2619. node = node.return;
  2620. }
  2621. node.sibling.return = node.return;
  2622. node = node.sibling;
  2623. } // Flow needs the return null here, but ESLint complains about it.
  2624. // eslint-disable-next-line no-unreachable
  2625. return null;
  2626. }
  2627. /**
  2628. * In the future, we should cleanup callbacks by cancelling them instead of
  2629. * using this.
  2630. */
  2631. function mountSafeCallback_NOT_REALLY_SAFE(context, callback) {
  2632. return function() {
  2633. if (!callback) {
  2634. return undefined;
  2635. } // This protects against createClass() components.
  2636. // We don't know if there is code depending on it.
  2637. // We intentionally don't use isMounted() because even accessing
  2638. // isMounted property on a React ES6 class will trigger a warning.
  2639. if (typeof context.__isMounted === "boolean") {
  2640. if (!context.__isMounted) {
  2641. return undefined;
  2642. }
  2643. } // FIXME: there used to be other branches that protected
  2644. // against unmounted host components. But RN host components don't
  2645. // define isMounted() anymore, so those checks didn't do anything.
  2646. // They caused false positive warning noise so we removed them:
  2647. // https://github.com/facebook/react-native/issues/18868#issuecomment-413579095
  2648. // However, this means that the callback is NOT guaranteed to be safe
  2649. // for host components. The solution we should implement is to make
  2650. // UIManager.measure() and similar calls truly cancelable. Then we
  2651. // can change our own code calling them to cancel when something unmounts.
  2652. return callback.apply(context, arguments);
  2653. };
  2654. }
  2655. // Modules provided by RN:
  2656. var emptyObject = {};
  2657. /**
  2658. * Create a payload that contains all the updates between two sets of props.
  2659. *
  2660. * These helpers are all encapsulated into a single module, because they use
  2661. * mutation as a performance optimization which leads to subtle shared
  2662. * dependencies between the code paths. To avoid this mutable state leaking
  2663. * across modules, I've kept them isolated to this module.
  2664. */
  2665. // Tracks removed keys
  2666. var removedKeys = null;
  2667. var removedKeyCount = 0;
  2668. var deepDifferOptions = {
  2669. unsafelyIgnoreFunctions: true
  2670. };
  2671. function defaultDiffer(prevProp, nextProp) {
  2672. if (typeof nextProp !== "object" || nextProp === null) {
  2673. // Scalars have already been checked for equality
  2674. return true;
  2675. } else {
  2676. // For objects and arrays, the default diffing algorithm is a deep compare
  2677. return ReactNativePrivateInterface.deepDiffer(
  2678. prevProp,
  2679. nextProp,
  2680. deepDifferOptions
  2681. );
  2682. }
  2683. }
  2684. function restoreDeletedValuesInNestedArray(
  2685. updatePayload,
  2686. node,
  2687. validAttributes
  2688. ) {
  2689. if (Array.isArray(node)) {
  2690. var i = node.length;
  2691. while (i-- && removedKeyCount > 0) {
  2692. restoreDeletedValuesInNestedArray(
  2693. updatePayload,
  2694. node[i],
  2695. validAttributes
  2696. );
  2697. }
  2698. } else if (node && removedKeyCount > 0) {
  2699. var obj = node;
  2700. for (var propKey in removedKeys) {
  2701. if (!removedKeys[propKey]) {
  2702. continue;
  2703. }
  2704. var nextProp = obj[propKey];
  2705. if (nextProp === undefined) {
  2706. continue;
  2707. }
  2708. var attributeConfig = validAttributes[propKey];
  2709. if (!attributeConfig) {
  2710. continue; // not a valid native prop
  2711. }
  2712. if (typeof nextProp === "function") {
  2713. nextProp = true;
  2714. }
  2715. if (typeof nextProp === "undefined") {
  2716. nextProp = null;
  2717. }
  2718. if (typeof attributeConfig !== "object") {
  2719. // case: !Object is the default case
  2720. updatePayload[propKey] = nextProp;
  2721. } else if (
  2722. typeof attributeConfig.diff === "function" ||
  2723. typeof attributeConfig.process === "function"
  2724. ) {
  2725. // case: CustomAttributeConfiguration
  2726. var nextValue =
  2727. typeof attributeConfig.process === "function"
  2728. ? attributeConfig.process(nextProp)
  2729. : nextProp;
  2730. updatePayload[propKey] = nextValue;
  2731. }
  2732. removedKeys[propKey] = false;
  2733. removedKeyCount--;
  2734. }
  2735. }
  2736. }
  2737. function diffNestedArrayProperty(
  2738. updatePayload,
  2739. prevArray,
  2740. nextArray,
  2741. validAttributes
  2742. ) {
  2743. var minLength =
  2744. prevArray.length < nextArray.length ? prevArray.length : nextArray.length;
  2745. var i;
  2746. for (i = 0; i < minLength; i++) {
  2747. // Diff any items in the array in the forward direction. Repeated keys
  2748. // will be overwritten by later values.
  2749. updatePayload = diffNestedProperty(
  2750. updatePayload,
  2751. prevArray[i],
  2752. nextArray[i],
  2753. validAttributes
  2754. );
  2755. }
  2756. for (; i < prevArray.length; i++) {
  2757. // Clear out all remaining properties.
  2758. updatePayload = clearNestedProperty(
  2759. updatePayload,
  2760. prevArray[i],
  2761. validAttributes
  2762. );
  2763. }
  2764. for (; i < nextArray.length; i++) {
  2765. // Add all remaining properties.
  2766. updatePayload = addNestedProperty(
  2767. updatePayload,
  2768. nextArray[i],
  2769. validAttributes
  2770. );
  2771. }
  2772. return updatePayload;
  2773. }
  2774. function diffNestedProperty(
  2775. updatePayload,
  2776. prevProp,
  2777. nextProp,
  2778. validAttributes
  2779. ) {
  2780. if (!updatePayload && prevProp === nextProp) {
  2781. // If no properties have been added, then we can bail out quickly on object
  2782. // equality.
  2783. return updatePayload;
  2784. }
  2785. if (!prevProp || !nextProp) {
  2786. if (nextProp) {
  2787. return addNestedProperty(updatePayload, nextProp, validAttributes);
  2788. }
  2789. if (prevProp) {
  2790. return clearNestedProperty(updatePayload, prevProp, validAttributes);
  2791. }
  2792. return updatePayload;
  2793. }
  2794. if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) {
  2795. // Both are leaves, we can diff the leaves.
  2796. return diffProperties(updatePayload, prevProp, nextProp, validAttributes);
  2797. }
  2798. if (Array.isArray(prevProp) && Array.isArray(nextProp)) {
  2799. // Both are arrays, we can diff the arrays.
  2800. return diffNestedArrayProperty(
  2801. updatePayload,
  2802. prevProp,
  2803. nextProp,
  2804. validAttributes
  2805. );
  2806. }
  2807. if (Array.isArray(prevProp)) {
  2808. return diffProperties(
  2809. updatePayload, // $FlowFixMe - We know that this is always an object when the input is.
  2810. ReactNativePrivateInterface.flattenStyle(prevProp), // $FlowFixMe - We know that this isn't an array because of above flow.
  2811. nextProp,
  2812. validAttributes
  2813. );
  2814. }
  2815. return diffProperties(
  2816. updatePayload,
  2817. prevProp, // $FlowFixMe - We know that this is always an object when the input is.
  2818. ReactNativePrivateInterface.flattenStyle(nextProp),
  2819. validAttributes
  2820. );
  2821. }
  2822. /**
  2823. * addNestedProperty takes a single set of props and valid attribute
  2824. * attribute configurations. It processes each prop and adds it to the
  2825. * updatePayload.
  2826. */
  2827. function addNestedProperty(updatePayload, nextProp, validAttributes) {
  2828. if (!nextProp) {
  2829. return updatePayload;
  2830. }
  2831. if (!Array.isArray(nextProp)) {
  2832. // Add each property of the leaf.
  2833. return addProperties(updatePayload, nextProp, validAttributes);
  2834. }
  2835. for (var i = 0; i < nextProp.length; i++) {
  2836. // Add all the properties of the array.
  2837. updatePayload = addNestedProperty(
  2838. updatePayload,
  2839. nextProp[i],
  2840. validAttributes
  2841. );
  2842. }
  2843. return updatePayload;
  2844. }
  2845. /**
  2846. * clearNestedProperty takes a single set of props and valid attributes. It
  2847. * adds a null sentinel to the updatePayload, for each prop key.
  2848. */
  2849. function clearNestedProperty(updatePayload, prevProp, validAttributes) {
  2850. if (!prevProp) {
  2851. return updatePayload;
  2852. }
  2853. if (!Array.isArray(prevProp)) {
  2854. // Add each property of the leaf.
  2855. return clearProperties(updatePayload, prevProp, validAttributes);
  2856. }
  2857. for (var i = 0; i < prevProp.length; i++) {
  2858. // Add all the properties of the array.
  2859. updatePayload = clearNestedProperty(
  2860. updatePayload,
  2861. prevProp[i],
  2862. validAttributes
  2863. );
  2864. }
  2865. return updatePayload;
  2866. }
  2867. /**
  2868. * diffProperties takes two sets of props and a set of valid attributes
  2869. * and write to updatePayload the values that changed or were deleted.
  2870. * If no updatePayload is provided, a new one is created and returned if
  2871. * anything changed.
  2872. */
  2873. function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
  2874. var attributeConfig;
  2875. var nextProp;
  2876. var prevProp;
  2877. for (var propKey in nextProps) {
  2878. attributeConfig = validAttributes[propKey];
  2879. if (!attributeConfig) {
  2880. continue; // not a valid native prop
  2881. }
  2882. prevProp = prevProps[propKey];
  2883. nextProp = nextProps[propKey]; // functions are converted to booleans as markers that the associated
  2884. // events should be sent from native.
  2885. if (typeof nextProp === "function") {
  2886. nextProp = true; // If nextProp is not a function, then don't bother changing prevProp
  2887. // since nextProp will win and go into the updatePayload regardless.
  2888. if (typeof prevProp === "function") {
  2889. prevProp = true;
  2890. }
  2891. } // An explicit value of undefined is treated as a null because it overrides
  2892. // any other preceding value.
  2893. if (typeof nextProp === "undefined") {
  2894. nextProp = null;
  2895. if (typeof prevProp === "undefined") {
  2896. prevProp = null;
  2897. }
  2898. }
  2899. if (removedKeys) {
  2900. removedKeys[propKey] = false;
  2901. }
  2902. if (updatePayload && updatePayload[propKey] !== undefined) {
  2903. // Something else already triggered an update to this key because another
  2904. // value diffed. Since we're now later in the nested arrays our value is
  2905. // more important so we need to calculate it and override the existing
  2906. // value. It doesn't matter if nothing changed, we'll set it anyway.
  2907. // Pattern match on: attributeConfig
  2908. if (typeof attributeConfig !== "object") {
  2909. // case: !Object is the default case
  2910. updatePayload[propKey] = nextProp;
  2911. } else if (
  2912. typeof attributeConfig.diff === "function" ||
  2913. typeof attributeConfig.process === "function"
  2914. ) {
  2915. // case: CustomAttributeConfiguration
  2916. var nextValue =
  2917. typeof attributeConfig.process === "function"
  2918. ? attributeConfig.process(nextProp)
  2919. : nextProp;
  2920. updatePayload[propKey] = nextValue;
  2921. }
  2922. continue;
  2923. }
  2924. if (prevProp === nextProp) {
  2925. continue; // nothing changed
  2926. } // Pattern match on: attributeConfig
  2927. if (typeof attributeConfig !== "object") {
  2928. // case: !Object is the default case
  2929. if (defaultDiffer(prevProp, nextProp)) {
  2930. // a normal leaf has changed
  2931. (updatePayload || (updatePayload = {}))[propKey] = nextProp;
  2932. }
  2933. } else if (
  2934. typeof attributeConfig.diff === "function" ||
  2935. typeof attributeConfig.process === "function"
  2936. ) {
  2937. // case: CustomAttributeConfiguration
  2938. var shouldUpdate =
  2939. prevProp === undefined ||
  2940. (typeof attributeConfig.diff === "function"
  2941. ? attributeConfig.diff(prevProp, nextProp)
  2942. : defaultDiffer(prevProp, nextProp));
  2943. if (shouldUpdate) {
  2944. var _nextValue =
  2945. typeof attributeConfig.process === "function"
  2946. ? attributeConfig.process(nextProp)
  2947. : nextProp;
  2948. (updatePayload || (updatePayload = {}))[propKey] = _nextValue;
  2949. }
  2950. } else {
  2951. // default: fallthrough case when nested properties are defined
  2952. removedKeys = null;
  2953. removedKeyCount = 0; // We think that attributeConfig is not CustomAttributeConfiguration at
  2954. // this point so we assume it must be AttributeConfiguration.
  2955. updatePayload = diffNestedProperty(
  2956. updatePayload,
  2957. prevProp,
  2958. nextProp,
  2959. attributeConfig
  2960. );
  2961. if (removedKeyCount > 0 && updatePayload) {
  2962. restoreDeletedValuesInNestedArray(
  2963. updatePayload,
  2964. nextProp,
  2965. attributeConfig
  2966. );
  2967. removedKeys = null;
  2968. }
  2969. }
  2970. } // Also iterate through all the previous props to catch any that have been
  2971. // removed and make sure native gets the signal so it can reset them to the
  2972. // default.
  2973. for (var _propKey in prevProps) {
  2974. if (nextProps[_propKey] !== undefined) {
  2975. continue; // we've already covered this key in the previous pass
  2976. }
  2977. attributeConfig = validAttributes[_propKey];
  2978. if (!attributeConfig) {
  2979. continue; // not a valid native prop
  2980. }
  2981. if (updatePayload && updatePayload[_propKey] !== undefined) {
  2982. // This was already updated to a diff result earlier.
  2983. continue;
  2984. }
  2985. prevProp = prevProps[_propKey];
  2986. if (prevProp === undefined) {
  2987. continue; // was already empty anyway
  2988. } // Pattern match on: attributeConfig
  2989. if (
  2990. typeof attributeConfig !== "object" ||
  2991. typeof attributeConfig.diff === "function" ||
  2992. typeof attributeConfig.process === "function"
  2993. ) {
  2994. // case: CustomAttributeConfiguration | !Object
  2995. // Flag the leaf property for removal by sending a sentinel.
  2996. (updatePayload || (updatePayload = {}))[_propKey] = null;
  2997. if (!removedKeys) {
  2998. removedKeys = {};
  2999. }
  3000. if (!removedKeys[_propKey]) {
  3001. removedKeys[_propKey] = true;
  3002. removedKeyCount++;
  3003. }
  3004. } else {
  3005. // default:
  3006. // This is a nested attribute configuration where all the properties
  3007. // were removed so we need to go through and clear out all of them.
  3008. updatePayload = clearNestedProperty(
  3009. updatePayload,
  3010. prevProp,
  3011. attributeConfig
  3012. );
  3013. }
  3014. }
  3015. return updatePayload;
  3016. }
  3017. /**
  3018. * addProperties adds all the valid props to the payload after being processed.
  3019. */
  3020. function addProperties(updatePayload, props, validAttributes) {
  3021. // TODO: Fast path
  3022. return diffProperties(updatePayload, emptyObject, props, validAttributes);
  3023. }
  3024. /**
  3025. * clearProperties clears all the previous props by adding a null sentinel
  3026. * to the payload for each valid key.
  3027. */
  3028. function clearProperties(updatePayload, prevProps, validAttributes) {
  3029. // TODO: Fast path
  3030. return diffProperties(updatePayload, prevProps, emptyObject, validAttributes);
  3031. }
  3032. function create(props, validAttributes) {
  3033. return addProperties(
  3034. null, // updatePayload
  3035. props,
  3036. validAttributes
  3037. );
  3038. }
  3039. function diff(prevProps, nextProps, validAttributes) {
  3040. return diffProperties(
  3041. null, // updatePayload
  3042. prevProps,
  3043. nextProps,
  3044. validAttributes
  3045. );
  3046. }
  3047. var PLUGIN_EVENT_SYSTEM = 1;
  3048. // the renderer. Such as when we're dispatching events or if third party
  3049. // libraries need to call batchedUpdates. Eventually, this API will go away when
  3050. // everything is batched by default. We'll then have a similar API to opt-out of
  3051. // scheduled work and instead do synchronous work.
  3052. // Defaults
  3053. var batchedUpdatesImpl = function(fn, bookkeeping) {
  3054. return fn(bookkeeping);
  3055. };
  3056. var isInsideEventHandler = false;
  3057. function batchedUpdates(fn, bookkeeping) {
  3058. if (isInsideEventHandler) {
  3059. // If we are currently inside another batch, we need to wait until it
  3060. // fully completes before restoring state.
  3061. return fn(bookkeeping);
  3062. }
  3063. isInsideEventHandler = true;
  3064. try {
  3065. return batchedUpdatesImpl(fn, bookkeeping);
  3066. } finally {
  3067. isInsideEventHandler = false;
  3068. }
  3069. }
  3070. function setBatchingImplementation(
  3071. _batchedUpdatesImpl,
  3072. _discreteUpdatesImpl,
  3073. _flushDiscreteUpdatesImpl,
  3074. _batchedEventUpdatesImpl
  3075. ) {
  3076. batchedUpdatesImpl = _batchedUpdatesImpl;
  3077. }
  3078. /**
  3079. * Internal queue of events that have accumulated their dispatches and are
  3080. * waiting to have their dispatches executed.
  3081. */
  3082. var eventQueue = null;
  3083. /**
  3084. * Dispatches an event and releases it back into the pool, unless persistent.
  3085. *
  3086. * @param {?object} event Synthetic event to be dispatched.
  3087. * @private
  3088. */
  3089. var executeDispatchesAndRelease = function(event) {
  3090. if (event) {
  3091. executeDispatchesInOrder(event);
  3092. if (!event.isPersistent()) {
  3093. event.constructor.release(event);
  3094. }
  3095. }
  3096. };
  3097. var executeDispatchesAndReleaseTopLevel = function(e) {
  3098. return executeDispatchesAndRelease(e);
  3099. };
  3100. function runEventsInBatch(events) {
  3101. if (events !== null) {
  3102. eventQueue = accumulateInto(eventQueue, events);
  3103. } // Set `eventQueue` to null before processing it so that we can tell if more
  3104. // events get enqueued while processing.
  3105. var processingEventQueue = eventQueue;
  3106. eventQueue = null;
  3107. if (!processingEventQueue) {
  3108. return;
  3109. }
  3110. forEachAccumulated(processingEventQueue, executeDispatchesAndReleaseTopLevel);
  3111. if (!!eventQueue) {
  3112. throw Error(
  3113. "processEventQueue(): Additional events were enqueued while processing an event queue. Support for this has not yet been implemented."
  3114. );
  3115. } // This would be a good time to rethrow if any of the event handlers threw.
  3116. rethrowCaughtError();
  3117. }
  3118. /**
  3119. * Allows registered plugins an opportunity to extract events from top-level
  3120. * native browser events.
  3121. *
  3122. * @return {*} An accumulation of synthetic events.
  3123. * @internal
  3124. */
  3125. function extractPluginEvents(
  3126. topLevelType,
  3127. targetInst,
  3128. nativeEvent,
  3129. nativeEventTarget,
  3130. eventSystemFlags
  3131. ) {
  3132. var events = null;
  3133. for (var i = 0; i < plugins.length; i++) {
  3134. // Not every plugin in the ordering may be loaded at runtime.
  3135. var possiblePlugin = plugins[i];
  3136. if (possiblePlugin) {
  3137. var extractedEvents = possiblePlugin.extractEvents(
  3138. topLevelType,
  3139. targetInst,
  3140. nativeEvent,
  3141. nativeEventTarget,
  3142. eventSystemFlags
  3143. );
  3144. if (extractedEvents) {
  3145. events = accumulateInto(events, extractedEvents);
  3146. }
  3147. }
  3148. }
  3149. return events;
  3150. }
  3151. function runExtractedPluginEventsInBatch(
  3152. topLevelType,
  3153. targetInst,
  3154. nativeEvent,
  3155. nativeEventTarget,
  3156. eventSystemFlags
  3157. ) {
  3158. var events = extractPluginEvents(
  3159. topLevelType,
  3160. targetInst,
  3161. nativeEvent,
  3162. nativeEventTarget,
  3163. eventSystemFlags
  3164. );
  3165. runEventsInBatch(events);
  3166. }
  3167. function dispatchEvent(target, topLevelType, nativeEvent) {
  3168. var targetFiber = target;
  3169. var eventTarget = null;
  3170. if (targetFiber != null) {
  3171. var stateNode = targetFiber.stateNode; // Guard against Fiber being unmounted
  3172. if (stateNode != null) {
  3173. eventTarget = stateNode.canonical;
  3174. }
  3175. }
  3176. batchedUpdates(function() {
  3177. // Heritage plugin event system
  3178. runExtractedPluginEventsInBatch(
  3179. topLevelType,
  3180. targetFiber,
  3181. nativeEvent,
  3182. eventTarget,
  3183. PLUGIN_EVENT_SYSTEM
  3184. );
  3185. }); // React Native doesn't use ReactControlledComponent but if it did, here's
  3186. // where it would do it.
  3187. }
  3188. // can re-export everything from this module.
  3189. function shim() {
  3190. {
  3191. throw Error(
  3192. "The current renderer does not support mutation. This error is likely caused by a bug in React. Please file an issue."
  3193. );
  3194. }
  3195. } // Mutation (when unsupported)
  3196. var supportsMutation = false;
  3197. var commitMount = shim;
  3198. // can re-export everything from this module.
  3199. function shim$1() {
  3200. {
  3201. throw Error(
  3202. "The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue."
  3203. );
  3204. }
  3205. } // Hydration (when unsupported)
  3206. var isSuspenseInstancePending = shim$1;
  3207. var isSuspenseInstanceFallback = shim$1;
  3208. var hydrateTextInstance = shim$1;
  3209. var _nativeFabricUIManage = nativeFabricUIManager,
  3210. createNode = _nativeFabricUIManage.createNode,
  3211. cloneNode = _nativeFabricUIManage.cloneNode,
  3212. cloneNodeWithNewChildren = _nativeFabricUIManage.cloneNodeWithNewChildren,
  3213. cloneNodeWithNewChildrenAndProps =
  3214. _nativeFabricUIManage.cloneNodeWithNewChildrenAndProps,
  3215. cloneNodeWithNewProps = _nativeFabricUIManage.cloneNodeWithNewProps,
  3216. createChildNodeSet = _nativeFabricUIManage.createChildSet,
  3217. appendChildNode = _nativeFabricUIManage.appendChild,
  3218. appendChildNodeToSet = _nativeFabricUIManage.appendChildToSet,
  3219. completeRoot = _nativeFabricUIManage.completeRoot,
  3220. registerEventHandler = _nativeFabricUIManage.registerEventHandler,
  3221. fabricMeasure = _nativeFabricUIManage.measure,
  3222. fabricMeasureInWindow = _nativeFabricUIManage.measureInWindow,
  3223. fabricMeasureLayout = _nativeFabricUIManage.measureLayout;
  3224. var getViewConfigForType =
  3225. ReactNativePrivateInterface.ReactNativeViewConfigRegistry.get; // Counter for uniquely identifying views.
  3226. // % 10 === 1 means it is a rootTag.
  3227. // % 2 === 0 means it is a Fabric tag.
  3228. // This means that they never overlap.
  3229. var nextReactTag = 2;
  3230. // TODO: Remove this conditional once all changes have propagated.
  3231. if (registerEventHandler) {
  3232. /**
  3233. * Register the event emitter with the native bridge
  3234. */
  3235. registerEventHandler(dispatchEvent);
  3236. }
  3237. /**
  3238. * This is used for refs on host components.
  3239. */
  3240. var ReactFabricHostComponent =
  3241. /*#__PURE__*/
  3242. (function() {
  3243. function ReactFabricHostComponent(
  3244. tag,
  3245. viewConfig,
  3246. props,
  3247. internalInstanceHandle
  3248. ) {
  3249. this._nativeTag = tag;
  3250. this.viewConfig = viewConfig;
  3251. this.currentProps = props;
  3252. this._internalInstanceHandle = internalInstanceHandle;
  3253. }
  3254. var _proto = ReactFabricHostComponent.prototype;
  3255. _proto.blur = function blur() {
  3256. ReactNativePrivateInterface.TextInputState.blurTextInput(this);
  3257. };
  3258. _proto.focus = function focus() {
  3259. ReactNativePrivateInterface.TextInputState.focusTextInput(this);
  3260. };
  3261. _proto.measure = function measure(callback) {
  3262. fabricMeasure(
  3263. this._internalInstanceHandle.stateNode.node,
  3264. mountSafeCallback_NOT_REALLY_SAFE(this, callback)
  3265. );
  3266. };
  3267. _proto.measureInWindow = function measureInWindow(callback) {
  3268. fabricMeasureInWindow(
  3269. this._internalInstanceHandle.stateNode.node,
  3270. mountSafeCallback_NOT_REALLY_SAFE(this, callback)
  3271. );
  3272. };
  3273. _proto.measureLayout = function measureLayout(
  3274. relativeToNativeNode,
  3275. onSuccess,
  3276. onFail
  3277. ) /* currently unused */
  3278. {
  3279. if (
  3280. typeof relativeToNativeNode === "number" ||
  3281. !(relativeToNativeNode instanceof ReactFabricHostComponent)
  3282. ) {
  3283. {
  3284. error(
  3285. "Warning: ref.measureLayout must be called with a ref to a native component."
  3286. );
  3287. }
  3288. return;
  3289. }
  3290. fabricMeasureLayout(
  3291. this._internalInstanceHandle.stateNode.node,
  3292. relativeToNativeNode._internalInstanceHandle.stateNode.node,
  3293. mountSafeCallback_NOT_REALLY_SAFE(this, onFail),
  3294. mountSafeCallback_NOT_REALLY_SAFE(this, onSuccess)
  3295. );
  3296. };
  3297. _proto.setNativeProps = function setNativeProps(nativeProps) {
  3298. {
  3299. error("Warning: setNativeProps is not currently supported in Fabric");
  3300. }
  3301. return;
  3302. };
  3303. return ReactFabricHostComponent;
  3304. })(); // eslint-disable-next-line no-unused-expressions
  3305. function appendInitialChild(parentInstance, child) {
  3306. appendChildNode(parentInstance.node, child.node);
  3307. }
  3308. function createInstance(
  3309. type,
  3310. props,
  3311. rootContainerInstance,
  3312. hostContext,
  3313. internalInstanceHandle
  3314. ) {
  3315. var tag = nextReactTag;
  3316. nextReactTag += 2;
  3317. var viewConfig = getViewConfigForType(type);
  3318. {
  3319. for (var key in viewConfig.validAttributes) {
  3320. if (props.hasOwnProperty(key)) {
  3321. ReactNativePrivateInterface.deepFreezeAndThrowOnMutationInDev(
  3322. props[key]
  3323. );
  3324. }
  3325. }
  3326. }
  3327. var updatePayload = create(props, viewConfig.validAttributes);
  3328. var node = createNode(
  3329. tag, // reactTag
  3330. viewConfig.uiViewClassName, // viewName
  3331. rootContainerInstance, // rootTag
  3332. updatePayload, // props
  3333. internalInstanceHandle // internalInstanceHandle
  3334. );
  3335. var component = new ReactFabricHostComponent(
  3336. tag,
  3337. viewConfig,
  3338. props,
  3339. internalInstanceHandle
  3340. );
  3341. return {
  3342. node: node,
  3343. canonical: component
  3344. };
  3345. }
  3346. function createTextInstance(
  3347. text,
  3348. rootContainerInstance,
  3349. hostContext,
  3350. internalInstanceHandle
  3351. ) {
  3352. if (!hostContext.isInAParentText) {
  3353. throw Error("Text strings must be rendered within a <Text> component.");
  3354. }
  3355. var tag = nextReactTag;
  3356. nextReactTag += 2;
  3357. var node = createNode(
  3358. tag, // reactTag
  3359. "RCTRawText", // viewName
  3360. rootContainerInstance, // rootTag
  3361. {
  3362. text: text
  3363. }, // props
  3364. internalInstanceHandle // instance handle
  3365. );
  3366. return {
  3367. node: node
  3368. };
  3369. }
  3370. function getRootHostContext(rootContainerInstance) {
  3371. return {
  3372. isInAParentText: false
  3373. };
  3374. }
  3375. function getChildHostContext(parentHostContext, type, rootContainerInstance) {
  3376. var prevIsInAParentText = parentHostContext.isInAParentText;
  3377. var isInAParentText =
  3378. type === "AndroidTextInput" || // Android
  3379. type === "RCTMultilineTextInputView" || // iOS
  3380. type === "RCTSinglelineTextInputView" || // iOS
  3381. type === "RCTText" ||
  3382. type === "RCTVirtualText";
  3383. if (prevIsInAParentText !== isInAParentText) {
  3384. return {
  3385. isInAParentText: isInAParentText
  3386. };
  3387. } else {
  3388. return parentHostContext;
  3389. }
  3390. }
  3391. function getPublicInstance(instance) {
  3392. return instance.canonical;
  3393. }
  3394. function prepareForCommit(containerInfo) {
  3395. // Noop
  3396. }
  3397. function prepareUpdate(
  3398. instance,
  3399. type,
  3400. oldProps,
  3401. newProps,
  3402. rootContainerInstance,
  3403. hostContext
  3404. ) {
  3405. var viewConfig = instance.canonical.viewConfig;
  3406. var updatePayload = diff(oldProps, newProps, viewConfig.validAttributes); // TODO: If the event handlers have changed, we need to update the current props
  3407. // in the commit phase but there is no host config hook to do it yet.
  3408. // So instead we hack it by updating it in the render phase.
  3409. instance.canonical.currentProps = newProps;
  3410. return updatePayload;
  3411. }
  3412. function resetAfterCommit(containerInfo) {
  3413. // Noop
  3414. }
  3415. function shouldDeprioritizeSubtree(type, props) {
  3416. return false;
  3417. }
  3418. function shouldSetTextContent(type, props) {
  3419. // TODO (bvaughn) Revisit this decision.
  3420. // Always returning false simplifies the createInstance() implementation,
  3421. // But creates an additional child Fiber for raw text children.
  3422. // No additional native views are created though.
  3423. // It's not clear to me which is better so I'm deferring for now.
  3424. // More context @ github.com/facebook/react/pull/8560#discussion_r92111303
  3425. return false;
  3426. } // The Fabric renderer is secondary to the existing React Native renderer.
  3427. var scheduleTimeout = setTimeout;
  3428. var cancelTimeout = clearTimeout;
  3429. var noTimeout = -1; // -------------------
  3430. function cloneInstance(
  3431. instance,
  3432. updatePayload,
  3433. type,
  3434. oldProps,
  3435. newProps,
  3436. internalInstanceHandle,
  3437. keepChildren,
  3438. recyclableInstance
  3439. ) {
  3440. var node = instance.node;
  3441. var clone;
  3442. if (keepChildren) {
  3443. if (updatePayload !== null) {
  3444. clone = cloneNodeWithNewProps(node, updatePayload);
  3445. } else {
  3446. clone = cloneNode(node);
  3447. }
  3448. } else {
  3449. if (updatePayload !== null) {
  3450. clone = cloneNodeWithNewChildrenAndProps(node, updatePayload);
  3451. } else {
  3452. clone = cloneNodeWithNewChildren(node);
  3453. }
  3454. }
  3455. return {
  3456. node: clone,
  3457. canonical: instance.canonical
  3458. };
  3459. }
  3460. function cloneHiddenInstance(instance, type, props, internalInstanceHandle) {
  3461. var viewConfig = instance.canonical.viewConfig;
  3462. var node = instance.node;
  3463. var updatePayload = create(
  3464. {
  3465. style: {
  3466. display: "none"
  3467. }
  3468. },
  3469. viewConfig.validAttributes
  3470. );
  3471. return {
  3472. node: cloneNodeWithNewProps(node, updatePayload),
  3473. canonical: instance.canonical
  3474. };
  3475. }
  3476. function cloneHiddenTextInstance(instance, text, internalInstanceHandle) {
  3477. throw new Error("Not yet implemented.");
  3478. }
  3479. function createContainerChildSet(container) {
  3480. return createChildNodeSet(container);
  3481. }
  3482. function appendChildToContainerChildSet(childSet, child) {
  3483. appendChildNodeToSet(childSet, child.node);
  3484. }
  3485. function finalizeContainerChildren(container, newChildren) {
  3486. completeRoot(container, newChildren);
  3487. }
  3488. var loggedTypeFailures = {};
  3489. function checkPropTypes(typeSpecs, values, location, componentName) {
  3490. {
  3491. // $FlowFixMe This is okay but Flow doesn't know it.
  3492. var has = Function.call.bind(Object.prototype.hasOwnProperty);
  3493. for (var typeSpecName in typeSpecs) {
  3494. if (has(typeSpecs, typeSpecName)) {
  3495. var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
  3496. // fail the render phase where it didn't fail before. So we log it.
  3497. // After these have been cleaned up, we'll let them throw.
  3498. try {
  3499. // This is intentionally an invariant that gets caught. It's the same
  3500. // behavior as without this statement except with a better message.
  3501. if (typeof typeSpecs[typeSpecName] !== "function") {
  3502. var err = Error(
  3503. (componentName || "React class") +
  3504. ": " +
  3505. location +
  3506. " type `" +
  3507. typeSpecName +
  3508. "` is invalid; " +
  3509. "it must be a function, usually from the `prop-types` package, but received `" +
  3510. typeof typeSpecs[typeSpecName] +
  3511. "`." +
  3512. "This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."
  3513. );
  3514. err.name = "Invariant Violation";
  3515. throw err;
  3516. }
  3517. error$1 = typeSpecs[typeSpecName](
  3518. values,
  3519. typeSpecName,
  3520. componentName,
  3521. location,
  3522. null,
  3523. "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"
  3524. );
  3525. } catch (ex) {
  3526. error$1 = ex;
  3527. }
  3528. if (error$1 && !(error$1 instanceof Error)) {
  3529. error(
  3530. "%s: type specification of %s" +
  3531. " `%s` is invalid; the type checker " +
  3532. "function must return `null` or an `Error` but returned a %s. " +
  3533. "You may have forgotten to pass an argument to the type checker " +
  3534. "creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and " +
  3535. "shape all require an argument).",
  3536. componentName || "React class",
  3537. location,
  3538. typeSpecName,
  3539. typeof error$1
  3540. );
  3541. }
  3542. if (
  3543. error$1 instanceof Error &&
  3544. !(error$1.message in loggedTypeFailures)
  3545. ) {
  3546. // Only monitor this failure once because there tends to be a lot of the
  3547. // same error.
  3548. loggedTypeFailures[error$1.message] = true;
  3549. error("Failed %s type: %s", location, error$1.message);
  3550. }
  3551. }
  3552. }
  3553. }
  3554. }
  3555. // Prefix measurements so that it's possible to filter them.
  3556. // Longer prefixes are hard to read in DevTools.
  3557. var reactEmoji = "\u269B";
  3558. var warningEmoji = "\u26D4";
  3559. var supportsUserTiming =
  3560. typeof performance !== "undefined" &&
  3561. typeof performance.mark === "function" &&
  3562. typeof performance.clearMarks === "function" &&
  3563. typeof performance.measure === "function" &&
  3564. typeof performance.clearMeasures === "function"; // Keep track of current fiber so that we know the path to unwind on pause.
  3565. // TODO: this looks the same as nextUnitOfWork in scheduler. Can we unify them?
  3566. var currentFiber = null; // If we're in the middle of user code, which fiber and method is it?
  3567. // Reusing `currentFiber` would be confusing for this because user code fiber
  3568. // can change during commit phase too, but we don't need to unwind it (since
  3569. // lifecycles in the commit phase don't resemble a tree).
  3570. var currentPhase = null;
  3571. var currentPhaseFiber = null; // Did lifecycle hook schedule an update? This is often a performance problem,
  3572. // so we will keep track of it, and include it in the report.
  3573. // Track commits caused by cascading updates.
  3574. var isCommitting = false;
  3575. var hasScheduledUpdateInCurrentCommit = false;
  3576. var hasScheduledUpdateInCurrentPhase = false;
  3577. var commitCountInCurrentWorkLoop = 0;
  3578. var effectCountInCurrentCommit = 0;
  3579. // to avoid stretch the commit phase with measurement overhead.
  3580. var labelsInCurrentCommit = new Set();
  3581. var formatMarkName = function(markName) {
  3582. return reactEmoji + " " + markName;
  3583. };
  3584. var formatLabel = function(label, warning) {
  3585. var prefix = warning ? warningEmoji + " " : reactEmoji + " ";
  3586. var suffix = warning ? " Warning: " + warning : "";
  3587. return "" + prefix + label + suffix;
  3588. };
  3589. var beginMark = function(markName) {
  3590. performance.mark(formatMarkName(markName));
  3591. };
  3592. var clearMark = function(markName) {
  3593. performance.clearMarks(formatMarkName(markName));
  3594. };
  3595. var endMark = function(label, markName, warning) {
  3596. var formattedMarkName = formatMarkName(markName);
  3597. var formattedLabel = formatLabel(label, warning);
  3598. try {
  3599. performance.measure(formattedLabel, formattedMarkName);
  3600. } catch (err) {} // If previous mark was missing for some reason, this will throw.
  3601. // This could only happen if React crashed in an unexpected place earlier.
  3602. // Don't pile on with more errors.
  3603. // Clear marks immediately to avoid growing buffer.
  3604. performance.clearMarks(formattedMarkName);
  3605. performance.clearMeasures(formattedLabel);
  3606. };
  3607. var getFiberMarkName = function(label, debugID) {
  3608. return label + " (#" + debugID + ")";
  3609. };
  3610. var getFiberLabel = function(componentName, isMounted, phase) {
  3611. if (phase === null) {
  3612. // These are composite component total time measurements.
  3613. return componentName + " [" + (isMounted ? "update" : "mount") + "]";
  3614. } else {
  3615. // Composite component methods.
  3616. return componentName + "." + phase;
  3617. }
  3618. };
  3619. var beginFiberMark = function(fiber, phase) {
  3620. var componentName = getComponentName(fiber.type) || "Unknown";
  3621. var debugID = fiber._debugID;
  3622. var isMounted = fiber.alternate !== null;
  3623. var label = getFiberLabel(componentName, isMounted, phase);
  3624. if (isCommitting && labelsInCurrentCommit.has(label)) {
  3625. // During the commit phase, we don't show duplicate labels because
  3626. // there is a fixed overhead for every measurement, and we don't
  3627. // want to stretch the commit phase beyond necessary.
  3628. return false;
  3629. }
  3630. labelsInCurrentCommit.add(label);
  3631. var markName = getFiberMarkName(label, debugID);
  3632. beginMark(markName);
  3633. return true;
  3634. };
  3635. var clearFiberMark = function(fiber, phase) {
  3636. var componentName = getComponentName(fiber.type) || "Unknown";
  3637. var debugID = fiber._debugID;
  3638. var isMounted = fiber.alternate !== null;
  3639. var label = getFiberLabel(componentName, isMounted, phase);
  3640. var markName = getFiberMarkName(label, debugID);
  3641. clearMark(markName);
  3642. };
  3643. var endFiberMark = function(fiber, phase, warning) {
  3644. var componentName = getComponentName(fiber.type) || "Unknown";
  3645. var debugID = fiber._debugID;
  3646. var isMounted = fiber.alternate !== null;
  3647. var label = getFiberLabel(componentName, isMounted, phase);
  3648. var markName = getFiberMarkName(label, debugID);
  3649. endMark(label, markName, warning);
  3650. };
  3651. var shouldIgnoreFiber = function(fiber) {
  3652. // Host components should be skipped in the timeline.
  3653. // We could check typeof fiber.type, but does this work with RN?
  3654. switch (fiber.tag) {
  3655. case HostRoot:
  3656. case HostComponent:
  3657. case HostText:
  3658. case HostPortal:
  3659. case Fragment:
  3660. case ContextProvider:
  3661. case ContextConsumer:
  3662. case Mode:
  3663. return true;
  3664. default:
  3665. return false;
  3666. }
  3667. };
  3668. var clearPendingPhaseMeasurement = function() {
  3669. if (currentPhase !== null && currentPhaseFiber !== null) {
  3670. clearFiberMark(currentPhaseFiber, currentPhase);
  3671. }
  3672. currentPhaseFiber = null;
  3673. currentPhase = null;
  3674. hasScheduledUpdateInCurrentPhase = false;
  3675. };
  3676. var pauseTimers = function() {
  3677. // Stops all currently active measurements so that they can be resumed
  3678. // if we continue in a later deferred loop from the same unit of work.
  3679. var fiber = currentFiber;
  3680. while (fiber) {
  3681. if (fiber._debugIsCurrentlyTiming) {
  3682. endFiberMark(fiber, null, null);
  3683. }
  3684. fiber = fiber.return;
  3685. }
  3686. };
  3687. var resumeTimersRecursively = function(fiber) {
  3688. if (fiber.return !== null) {
  3689. resumeTimersRecursively(fiber.return);
  3690. }
  3691. if (fiber._debugIsCurrentlyTiming) {
  3692. beginFiberMark(fiber, null);
  3693. }
  3694. };
  3695. var resumeTimers = function() {
  3696. // Resumes all measurements that were active during the last deferred loop.
  3697. if (currentFiber !== null) {
  3698. resumeTimersRecursively(currentFiber);
  3699. }
  3700. };
  3701. function recordEffect() {
  3702. {
  3703. effectCountInCurrentCommit++;
  3704. }
  3705. }
  3706. function recordScheduleUpdate() {
  3707. {
  3708. if (isCommitting) {
  3709. hasScheduledUpdateInCurrentCommit = true;
  3710. }
  3711. if (
  3712. currentPhase !== null &&
  3713. currentPhase !== "componentWillMount" &&
  3714. currentPhase !== "componentWillReceiveProps"
  3715. ) {
  3716. hasScheduledUpdateInCurrentPhase = true;
  3717. }
  3718. }
  3719. }
  3720. function startWorkTimer(fiber) {
  3721. {
  3722. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  3723. return;
  3724. } // If we pause, this is the fiber to unwind from.
  3725. currentFiber = fiber;
  3726. if (!beginFiberMark(fiber, null)) {
  3727. return;
  3728. }
  3729. fiber._debugIsCurrentlyTiming = true;
  3730. }
  3731. }
  3732. function cancelWorkTimer(fiber) {
  3733. {
  3734. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  3735. return;
  3736. } // Remember we shouldn't complete measurement for this fiber.
  3737. // Otherwise flamechart will be deep even for small updates.
  3738. fiber._debugIsCurrentlyTiming = false;
  3739. clearFiberMark(fiber, null);
  3740. }
  3741. }
  3742. function stopWorkTimer(fiber) {
  3743. {
  3744. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  3745. return;
  3746. } // If we pause, its parent is the fiber to unwind from.
  3747. currentFiber = fiber.return;
  3748. if (!fiber._debugIsCurrentlyTiming) {
  3749. return;
  3750. }
  3751. fiber._debugIsCurrentlyTiming = false;
  3752. endFiberMark(fiber, null, null);
  3753. }
  3754. }
  3755. function stopFailedWorkTimer(fiber) {
  3756. {
  3757. if (!supportsUserTiming || shouldIgnoreFiber(fiber)) {
  3758. return;
  3759. } // If we pause, its parent is the fiber to unwind from.
  3760. currentFiber = fiber.return;
  3761. if (!fiber._debugIsCurrentlyTiming) {
  3762. return;
  3763. }
  3764. fiber._debugIsCurrentlyTiming = false;
  3765. var warning =
  3766. fiber.tag === SuspenseComponent
  3767. ? "Rendering was suspended"
  3768. : "An error was thrown inside this error boundary";
  3769. endFiberMark(fiber, null, warning);
  3770. }
  3771. }
  3772. function startPhaseTimer(fiber, phase) {
  3773. {
  3774. if (!supportsUserTiming) {
  3775. return;
  3776. }
  3777. clearPendingPhaseMeasurement();
  3778. if (!beginFiberMark(fiber, phase)) {
  3779. return;
  3780. }
  3781. currentPhaseFiber = fiber;
  3782. currentPhase = phase;
  3783. }
  3784. }
  3785. function stopPhaseTimer() {
  3786. {
  3787. if (!supportsUserTiming) {
  3788. return;
  3789. }
  3790. if (currentPhase !== null && currentPhaseFiber !== null) {
  3791. var warning = hasScheduledUpdateInCurrentPhase
  3792. ? "Scheduled a cascading update"
  3793. : null;
  3794. endFiberMark(currentPhaseFiber, currentPhase, warning);
  3795. }
  3796. currentPhase = null;
  3797. currentPhaseFiber = null;
  3798. }
  3799. }
  3800. function startWorkLoopTimer(nextUnitOfWork) {
  3801. {
  3802. currentFiber = nextUnitOfWork;
  3803. if (!supportsUserTiming) {
  3804. return;
  3805. }
  3806. commitCountInCurrentWorkLoop = 0; // This is top level call.
  3807. // Any other measurements are performed within.
  3808. beginMark("(React Tree Reconciliation)"); // Resume any measurements that were in progress during the last loop.
  3809. resumeTimers();
  3810. }
  3811. }
  3812. function stopWorkLoopTimer(interruptedBy, didCompleteRoot) {
  3813. {
  3814. if (!supportsUserTiming) {
  3815. return;
  3816. }
  3817. var warning = null;
  3818. if (interruptedBy !== null) {
  3819. if (interruptedBy.tag === HostRoot) {
  3820. warning = "A top-level update interrupted the previous render";
  3821. } else {
  3822. var componentName = getComponentName(interruptedBy.type) || "Unknown";
  3823. warning =
  3824. "An update to " + componentName + " interrupted the previous render";
  3825. }
  3826. } else if (commitCountInCurrentWorkLoop > 1) {
  3827. warning = "There were cascading updates";
  3828. }
  3829. commitCountInCurrentWorkLoop = 0;
  3830. var label = didCompleteRoot
  3831. ? "(React Tree Reconciliation: Completed Root)"
  3832. : "(React Tree Reconciliation: Yielded)"; // Pause any measurements until the next loop.
  3833. pauseTimers();
  3834. endMark(label, "(React Tree Reconciliation)", warning);
  3835. }
  3836. }
  3837. function startCommitTimer() {
  3838. {
  3839. if (!supportsUserTiming) {
  3840. return;
  3841. }
  3842. isCommitting = true;
  3843. hasScheduledUpdateInCurrentCommit = false;
  3844. labelsInCurrentCommit.clear();
  3845. beginMark("(Committing Changes)");
  3846. }
  3847. }
  3848. function stopCommitTimer() {
  3849. {
  3850. if (!supportsUserTiming) {
  3851. return;
  3852. }
  3853. var warning = null;
  3854. if (hasScheduledUpdateInCurrentCommit) {
  3855. warning = "Lifecycle hook scheduled a cascading update";
  3856. } else if (commitCountInCurrentWorkLoop > 0) {
  3857. warning = "Caused by a cascading update in earlier commit";
  3858. }
  3859. hasScheduledUpdateInCurrentCommit = false;
  3860. commitCountInCurrentWorkLoop++;
  3861. isCommitting = false;
  3862. labelsInCurrentCommit.clear();
  3863. endMark("(Committing Changes)", "(Committing Changes)", warning);
  3864. }
  3865. }
  3866. function startCommitSnapshotEffectsTimer() {
  3867. {
  3868. if (!supportsUserTiming) {
  3869. return;
  3870. }
  3871. effectCountInCurrentCommit = 0;
  3872. beginMark("(Committing Snapshot Effects)");
  3873. }
  3874. }
  3875. function stopCommitSnapshotEffectsTimer() {
  3876. {
  3877. if (!supportsUserTiming) {
  3878. return;
  3879. }
  3880. var count = effectCountInCurrentCommit;
  3881. effectCountInCurrentCommit = 0;
  3882. endMark(
  3883. "(Committing Snapshot Effects: " + count + " Total)",
  3884. "(Committing Snapshot Effects)",
  3885. null
  3886. );
  3887. }
  3888. }
  3889. function startCommitHostEffectsTimer() {
  3890. {
  3891. if (!supportsUserTiming) {
  3892. return;
  3893. }
  3894. effectCountInCurrentCommit = 0;
  3895. beginMark("(Committing Host Effects)");
  3896. }
  3897. }
  3898. function stopCommitHostEffectsTimer() {
  3899. {
  3900. if (!supportsUserTiming) {
  3901. return;
  3902. }
  3903. var count = effectCountInCurrentCommit;
  3904. effectCountInCurrentCommit = 0;
  3905. endMark(
  3906. "(Committing Host Effects: " + count + " Total)",
  3907. "(Committing Host Effects)",
  3908. null
  3909. );
  3910. }
  3911. }
  3912. function startCommitLifeCyclesTimer() {
  3913. {
  3914. if (!supportsUserTiming) {
  3915. return;
  3916. }
  3917. effectCountInCurrentCommit = 0;
  3918. beginMark("(Calling Lifecycle Methods)");
  3919. }
  3920. }
  3921. function stopCommitLifeCyclesTimer() {
  3922. {
  3923. if (!supportsUserTiming) {
  3924. return;
  3925. }
  3926. var count = effectCountInCurrentCommit;
  3927. effectCountInCurrentCommit = 0;
  3928. endMark(
  3929. "(Calling Lifecycle Methods: " + count + " Total)",
  3930. "(Calling Lifecycle Methods)",
  3931. null
  3932. );
  3933. }
  3934. }
  3935. var valueStack = [];
  3936. var fiberStack;
  3937. {
  3938. fiberStack = [];
  3939. }
  3940. var index = -1;
  3941. function createCursor(defaultValue) {
  3942. return {
  3943. current: defaultValue
  3944. };
  3945. }
  3946. function pop(cursor, fiber) {
  3947. if (index < 0) {
  3948. {
  3949. error("Unexpected pop.");
  3950. }
  3951. return;
  3952. }
  3953. {
  3954. if (fiber !== fiberStack[index]) {
  3955. error("Unexpected Fiber popped.");
  3956. }
  3957. }
  3958. cursor.current = valueStack[index];
  3959. valueStack[index] = null;
  3960. {
  3961. fiberStack[index] = null;
  3962. }
  3963. index--;
  3964. }
  3965. function push(cursor, value, fiber) {
  3966. index++;
  3967. valueStack[index] = cursor.current;
  3968. {
  3969. fiberStack[index] = fiber;
  3970. }
  3971. cursor.current = value;
  3972. }
  3973. var warnedAboutMissingGetChildContext;
  3974. {
  3975. warnedAboutMissingGetChildContext = {};
  3976. }
  3977. var emptyContextObject = {};
  3978. {
  3979. Object.freeze(emptyContextObject);
  3980. } // A cursor to the current merged context object on the stack.
  3981. var contextStackCursor = createCursor(emptyContextObject); // A cursor to a boolean indicating whether the context has changed.
  3982. var didPerformWorkStackCursor = createCursor(false); // Keep track of the previous context object that was on the stack.
  3983. // We use this to get access to the parent context after we have already
  3984. // pushed the next context provider, and now need to merge their contexts.
  3985. var previousContext = emptyContextObject;
  3986. function getUnmaskedContext(
  3987. workInProgress,
  3988. Component,
  3989. didPushOwnContextIfProvider
  3990. ) {
  3991. {
  3992. if (didPushOwnContextIfProvider && isContextProvider(Component)) {
  3993. // If the fiber is a context provider itself, when we read its context
  3994. // we may have already pushed its own child context on the stack. A context
  3995. // provider should not "see" its own child context. Therefore we read the
  3996. // previous (parent) context instead for a context provider.
  3997. return previousContext;
  3998. }
  3999. return contextStackCursor.current;
  4000. }
  4001. }
  4002. function cacheContext(workInProgress, unmaskedContext, maskedContext) {
  4003. {
  4004. var instance = workInProgress.stateNode;
  4005. instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
  4006. instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
  4007. }
  4008. }
  4009. function getMaskedContext(workInProgress, unmaskedContext) {
  4010. {
  4011. var type = workInProgress.type;
  4012. var contextTypes = type.contextTypes;
  4013. if (!contextTypes) {
  4014. return emptyContextObject;
  4015. } // Avoid recreating masked context unless unmasked context has changed.
  4016. // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
  4017. // This may trigger infinite loops if componentWillReceiveProps calls setState.
  4018. var instance = workInProgress.stateNode;
  4019. if (
  4020. instance &&
  4021. instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext
  4022. ) {
  4023. return instance.__reactInternalMemoizedMaskedChildContext;
  4024. }
  4025. var context = {};
  4026. for (var key in contextTypes) {
  4027. context[key] = unmaskedContext[key];
  4028. }
  4029. {
  4030. var name = getComponentName(type) || "Unknown";
  4031. checkPropTypes(contextTypes, context, "context", name);
  4032. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  4033. // Context is created before the class component is instantiated so check for instance.
  4034. if (instance) {
  4035. cacheContext(workInProgress, unmaskedContext, context);
  4036. }
  4037. return context;
  4038. }
  4039. }
  4040. function hasContextChanged() {
  4041. {
  4042. return didPerformWorkStackCursor.current;
  4043. }
  4044. }
  4045. function isContextProvider(type) {
  4046. {
  4047. var childContextTypes = type.childContextTypes;
  4048. return childContextTypes !== null && childContextTypes !== undefined;
  4049. }
  4050. }
  4051. function popContext(fiber) {
  4052. {
  4053. pop(didPerformWorkStackCursor, fiber);
  4054. pop(contextStackCursor, fiber);
  4055. }
  4056. }
  4057. function popTopLevelContextObject(fiber) {
  4058. {
  4059. pop(didPerformWorkStackCursor, fiber);
  4060. pop(contextStackCursor, fiber);
  4061. }
  4062. }
  4063. function pushTopLevelContextObject(fiber, context, didChange) {
  4064. {
  4065. if (!(contextStackCursor.current === emptyContextObject)) {
  4066. throw Error(
  4067. "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue."
  4068. );
  4069. }
  4070. push(contextStackCursor, context, fiber);
  4071. push(didPerformWorkStackCursor, didChange, fiber);
  4072. }
  4073. }
  4074. function processChildContext(fiber, type, parentContext) {
  4075. {
  4076. var instance = fiber.stateNode;
  4077. var childContextTypes = type.childContextTypes; // TODO (bvaughn) Replace this behavior with an invariant() in the future.
  4078. // It has only been added in Fiber to match the (unintentional) behavior in Stack.
  4079. if (typeof instance.getChildContext !== "function") {
  4080. {
  4081. var componentName = getComponentName(type) || "Unknown";
  4082. if (!warnedAboutMissingGetChildContext[componentName]) {
  4083. warnedAboutMissingGetChildContext[componentName] = true;
  4084. error(
  4085. "%s.childContextTypes is specified but there is no getChildContext() method " +
  4086. "on the instance. You can either define getChildContext() on %s or remove " +
  4087. "childContextTypes from it.",
  4088. componentName,
  4089. componentName
  4090. );
  4091. }
  4092. }
  4093. return parentContext;
  4094. }
  4095. var childContext;
  4096. startPhaseTimer(fiber, "getChildContext");
  4097. childContext = instance.getChildContext();
  4098. stopPhaseTimer();
  4099. for (var contextKey in childContext) {
  4100. if (!(contextKey in childContextTypes)) {
  4101. throw Error(
  4102. (getComponentName(type) || "Unknown") +
  4103. '.getChildContext(): key "' +
  4104. contextKey +
  4105. '" is not defined in childContextTypes.'
  4106. );
  4107. }
  4108. }
  4109. {
  4110. var name = getComponentName(type) || "Unknown";
  4111. checkPropTypes(childContextTypes, childContext, "child context", name);
  4112. }
  4113. return Object.assign({}, parentContext, {}, childContext);
  4114. }
  4115. }
  4116. function pushContextProvider(workInProgress) {
  4117. {
  4118. var instance = workInProgress.stateNode; // We push the context as early as possible to ensure stack integrity.
  4119. // If the instance does not exist yet, we will push null at first,
  4120. // and replace it on the stack later when invalidating the context.
  4121. var memoizedMergedChildContext =
  4122. (instance && instance.__reactInternalMemoizedMergedChildContext) ||
  4123. emptyContextObject; // Remember the parent context so we can merge with it later.
  4124. // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
  4125. previousContext = contextStackCursor.current;
  4126. push(contextStackCursor, memoizedMergedChildContext, workInProgress);
  4127. push(
  4128. didPerformWorkStackCursor,
  4129. didPerformWorkStackCursor.current,
  4130. workInProgress
  4131. );
  4132. return true;
  4133. }
  4134. }
  4135. function invalidateContextProvider(workInProgress, type, didChange) {
  4136. {
  4137. var instance = workInProgress.stateNode;
  4138. if (!instance) {
  4139. throw Error(
  4140. "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue."
  4141. );
  4142. }
  4143. if (didChange) {
  4144. // Merge parent and own context.
  4145. // Skip this if we're not updating due to sCU.
  4146. // This avoids unnecessarily recomputing memoized values.
  4147. var mergedContext = processChildContext(
  4148. workInProgress,
  4149. type,
  4150. previousContext
  4151. );
  4152. instance.__reactInternalMemoizedMergedChildContext = mergedContext; // Replace the old (or empty) context with the new one.
  4153. // It is important to unwind the context in the reverse order.
  4154. pop(didPerformWorkStackCursor, workInProgress);
  4155. pop(contextStackCursor, workInProgress); // Now push the new context and mark that it has changed.
  4156. push(contextStackCursor, mergedContext, workInProgress);
  4157. push(didPerformWorkStackCursor, didChange, workInProgress);
  4158. } else {
  4159. pop(didPerformWorkStackCursor, workInProgress);
  4160. push(didPerformWorkStackCursor, didChange, workInProgress);
  4161. }
  4162. }
  4163. }
  4164. function findCurrentUnmaskedContext(fiber) {
  4165. {
  4166. // Currently this is only used with renderSubtreeIntoContainer; not sure if it
  4167. // makes sense elsewhere
  4168. if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) {
  4169. throw Error(
  4170. "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue."
  4171. );
  4172. }
  4173. var node = fiber;
  4174. do {
  4175. switch (node.tag) {
  4176. case HostRoot:
  4177. return node.stateNode.context;
  4178. case ClassComponent: {
  4179. var Component = node.type;
  4180. if (isContextProvider(Component)) {
  4181. return node.stateNode.__reactInternalMemoizedMergedChildContext;
  4182. }
  4183. break;
  4184. }
  4185. }
  4186. node = node.return;
  4187. } while (node !== null);
  4188. {
  4189. throw Error(
  4190. "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue."
  4191. );
  4192. }
  4193. }
  4194. }
  4195. var LegacyRoot = 0;
  4196. var BlockingRoot = 1;
  4197. var ConcurrentRoot = 2;
  4198. // Intentionally not named imports because Rollup would use dynamic dispatch for
  4199. var Scheduler_runWithPriority = Scheduler.unstable_runWithPriority,
  4200. Scheduler_scheduleCallback = Scheduler.unstable_scheduleCallback,
  4201. Scheduler_cancelCallback = Scheduler.unstable_cancelCallback,
  4202. Scheduler_shouldYield = Scheduler.unstable_shouldYield,
  4203. Scheduler_requestPaint = Scheduler.unstable_requestPaint,
  4204. Scheduler_now = Scheduler.unstable_now,
  4205. Scheduler_getCurrentPriorityLevel =
  4206. Scheduler.unstable_getCurrentPriorityLevel,
  4207. Scheduler_ImmediatePriority = Scheduler.unstable_ImmediatePriority,
  4208. Scheduler_UserBlockingPriority = Scheduler.unstable_UserBlockingPriority,
  4209. Scheduler_NormalPriority = Scheduler.unstable_NormalPriority,
  4210. Scheduler_LowPriority = Scheduler.unstable_LowPriority,
  4211. Scheduler_IdlePriority = Scheduler.unstable_IdlePriority;
  4212. {
  4213. // Provide explicit error message when production+profiling bundle of e.g.
  4214. // react-dom is used with production (non-profiling) bundle of
  4215. // scheduler/tracing
  4216. if (
  4217. !(
  4218. tracing.__interactionsRef != null &&
  4219. tracing.__interactionsRef.current != null
  4220. )
  4221. ) {
  4222. throw Error(
  4223. "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"
  4224. );
  4225. }
  4226. }
  4227. var fakeCallbackNode = {}; // Except for NoPriority, these correspond to Scheduler priorities. We use
  4228. // ascending numbers so we can compare them like numbers. They start at 90 to
  4229. // avoid clashing with Scheduler's priorities.
  4230. var ImmediatePriority = 99;
  4231. var UserBlockingPriority = 98;
  4232. var NormalPriority = 97;
  4233. var LowPriority = 96;
  4234. var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only.
  4235. var NoPriority = 90;
  4236. var shouldYield = Scheduler_shouldYield;
  4237. var requestPaint = // Fall back gracefully if we're running an older version of Scheduler.
  4238. Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : function() {};
  4239. var syncQueue = null;
  4240. var immediateQueueCallbackNode = null;
  4241. var isFlushingSyncQueue = false;
  4242. var initialTimeMs = Scheduler_now(); // If the initial timestamp is reasonably small, use Scheduler's `now` directly.
  4243. // This will be the case for modern browsers that support `performance.now`. In
  4244. // older browsers, Scheduler falls back to `Date.now`, which returns a Unix
  4245. // timestamp. In that case, subtract the module initialization time to simulate
  4246. // the behavior of performance.now and keep our times small enough to fit
  4247. // within 32 bits.
  4248. // TODO: Consider lifting this into Scheduler.
  4249. var now =
  4250. initialTimeMs < 10000
  4251. ? Scheduler_now
  4252. : function() {
  4253. return Scheduler_now() - initialTimeMs;
  4254. };
  4255. function getCurrentPriorityLevel() {
  4256. switch (Scheduler_getCurrentPriorityLevel()) {
  4257. case Scheduler_ImmediatePriority:
  4258. return ImmediatePriority;
  4259. case Scheduler_UserBlockingPriority:
  4260. return UserBlockingPriority;
  4261. case Scheduler_NormalPriority:
  4262. return NormalPriority;
  4263. case Scheduler_LowPriority:
  4264. return LowPriority;
  4265. case Scheduler_IdlePriority:
  4266. return IdlePriority;
  4267. default: {
  4268. throw Error("Unknown priority level.");
  4269. }
  4270. }
  4271. }
  4272. function reactPriorityToSchedulerPriority(reactPriorityLevel) {
  4273. switch (reactPriorityLevel) {
  4274. case ImmediatePriority:
  4275. return Scheduler_ImmediatePriority;
  4276. case UserBlockingPriority:
  4277. return Scheduler_UserBlockingPriority;
  4278. case NormalPriority:
  4279. return Scheduler_NormalPriority;
  4280. case LowPriority:
  4281. return Scheduler_LowPriority;
  4282. case IdlePriority:
  4283. return Scheduler_IdlePriority;
  4284. default: {
  4285. throw Error("Unknown priority level.");
  4286. }
  4287. }
  4288. }
  4289. function runWithPriority(reactPriorityLevel, fn) {
  4290. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  4291. return Scheduler_runWithPriority(priorityLevel, fn);
  4292. }
  4293. function scheduleCallback(reactPriorityLevel, callback, options) {
  4294. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  4295. return Scheduler_scheduleCallback(priorityLevel, callback, options);
  4296. }
  4297. function scheduleSyncCallback(callback) {
  4298. // Push this callback into an internal queue. We'll flush these either in
  4299. // the next tick, or earlier if something calls `flushSyncCallbackQueue`.
  4300. if (syncQueue === null) {
  4301. syncQueue = [callback]; // Flush the queue in the next tick, at the earliest.
  4302. immediateQueueCallbackNode = Scheduler_scheduleCallback(
  4303. Scheduler_ImmediatePriority,
  4304. flushSyncCallbackQueueImpl
  4305. );
  4306. } else {
  4307. // Push onto existing queue. Don't need to schedule a callback because
  4308. // we already scheduled one when we created the queue.
  4309. syncQueue.push(callback);
  4310. }
  4311. return fakeCallbackNode;
  4312. }
  4313. function cancelCallback(callbackNode) {
  4314. if (callbackNode !== fakeCallbackNode) {
  4315. Scheduler_cancelCallback(callbackNode);
  4316. }
  4317. }
  4318. function flushSyncCallbackQueue() {
  4319. if (immediateQueueCallbackNode !== null) {
  4320. var node = immediateQueueCallbackNode;
  4321. immediateQueueCallbackNode = null;
  4322. Scheduler_cancelCallback(node);
  4323. }
  4324. flushSyncCallbackQueueImpl();
  4325. }
  4326. function flushSyncCallbackQueueImpl() {
  4327. if (!isFlushingSyncQueue && syncQueue !== null) {
  4328. // Prevent re-entrancy.
  4329. isFlushingSyncQueue = true;
  4330. var i = 0;
  4331. try {
  4332. var _isSync = true;
  4333. var queue = syncQueue;
  4334. runWithPriority(ImmediatePriority, function() {
  4335. for (; i < queue.length; i++) {
  4336. var callback = queue[i];
  4337. do {
  4338. callback = callback(_isSync);
  4339. } while (callback !== null);
  4340. }
  4341. });
  4342. syncQueue = null;
  4343. } catch (error) {
  4344. // If something throws, leave the remaining callbacks on the queue.
  4345. if (syncQueue !== null) {
  4346. syncQueue = syncQueue.slice(i + 1);
  4347. } // Resume flushing in the next tick
  4348. Scheduler_scheduleCallback(
  4349. Scheduler_ImmediatePriority,
  4350. flushSyncCallbackQueue
  4351. );
  4352. throw error;
  4353. } finally {
  4354. isFlushingSyncQueue = false;
  4355. }
  4356. }
  4357. }
  4358. var NoMode = 0;
  4359. var StrictMode = 1; // TODO: Remove BlockingMode and ConcurrentMode by reading from the root
  4360. // tag instead
  4361. var BlockingMode = 2;
  4362. var ConcurrentMode = 4;
  4363. var ProfileMode = 8;
  4364. // Max 31 bit integer. The max integer size in V8 for 32-bit systems.
  4365. // Math.pow(2, 30) - 1
  4366. // 0b111111111111111111111111111111
  4367. var MAX_SIGNED_31_BIT_INT = 1073741823;
  4368. var NoWork = 0; // TODO: Think of a better name for Never. The key difference with Idle is that
  4369. // Never work can be committed in an inconsistent state without tearing the UI.
  4370. // The main example is offscreen content, like a hidden subtree. So one possible
  4371. // name is Offscreen. However, it also includes dehydrated Suspense boundaries,
  4372. // which are inconsistent in the sense that they haven't finished yet, but
  4373. // aren't visibly inconsistent because the server rendered HTML matches what the
  4374. // hydrated tree would look like.
  4375. var Never = 1; // Idle is slightly higher priority than Never. It must completely finish in
  4376. // order to be consistent.
  4377. var Idle = 2; // Continuous Hydration is slightly higher than Idle and is used to increase
  4378. var Sync = MAX_SIGNED_31_BIT_INT;
  4379. var Batched = Sync - 1;
  4380. var UNIT_SIZE = 10;
  4381. var MAGIC_NUMBER_OFFSET = Batched - 1; // 1 unit of expiration time represents 10ms.
  4382. function msToExpirationTime(ms) {
  4383. // Always subtract from the offset so that we don't clash with the magic number for NoWork.
  4384. return MAGIC_NUMBER_OFFSET - ((ms / UNIT_SIZE) | 0);
  4385. }
  4386. function expirationTimeToMs(expirationTime) {
  4387. return (MAGIC_NUMBER_OFFSET - expirationTime) * UNIT_SIZE;
  4388. }
  4389. function ceiling(num, precision) {
  4390. return (((num / precision) | 0) + 1) * precision;
  4391. }
  4392. function computeExpirationBucket(currentTime, expirationInMs, bucketSizeMs) {
  4393. return (
  4394. MAGIC_NUMBER_OFFSET -
  4395. ceiling(
  4396. MAGIC_NUMBER_OFFSET - currentTime + expirationInMs / UNIT_SIZE,
  4397. bucketSizeMs / UNIT_SIZE
  4398. )
  4399. );
  4400. } // TODO: This corresponds to Scheduler's NormalPriority, not LowPriority. Update
  4401. // the names to reflect.
  4402. var LOW_PRIORITY_EXPIRATION = 5000;
  4403. var LOW_PRIORITY_BATCH_SIZE = 250;
  4404. function computeAsyncExpiration(currentTime) {
  4405. return computeExpirationBucket(
  4406. currentTime,
  4407. LOW_PRIORITY_EXPIRATION,
  4408. LOW_PRIORITY_BATCH_SIZE
  4409. );
  4410. }
  4411. function computeSuspenseExpiration(currentTime, timeoutMs) {
  4412. // TODO: Should we warn if timeoutMs is lower than the normal pri expiration time?
  4413. return computeExpirationBucket(
  4414. currentTime,
  4415. timeoutMs,
  4416. LOW_PRIORITY_BATCH_SIZE
  4417. );
  4418. } // We intentionally set a higher expiration time for interactive updates in
  4419. // dev than in production.
  4420. //
  4421. // If the main thread is being blocked so long that you hit the expiration,
  4422. // it's a problem that could be solved with better scheduling.
  4423. //
  4424. // People will be more likely to notice this and fix it with the long
  4425. // expiration time in development.
  4426. //
  4427. // In production we opt for better UX at the risk of masking scheduling
  4428. // problems, by expiring fast.
  4429. var HIGH_PRIORITY_EXPIRATION = 500;
  4430. var HIGH_PRIORITY_BATCH_SIZE = 100;
  4431. function computeInteractiveExpiration(currentTime) {
  4432. return computeExpirationBucket(
  4433. currentTime,
  4434. HIGH_PRIORITY_EXPIRATION,
  4435. HIGH_PRIORITY_BATCH_SIZE
  4436. );
  4437. }
  4438. function inferPriorityFromExpirationTime(currentTime, expirationTime) {
  4439. if (expirationTime === Sync) {
  4440. return ImmediatePriority;
  4441. }
  4442. if (expirationTime === Never || expirationTime === Idle) {
  4443. return IdlePriority;
  4444. }
  4445. var msUntil =
  4446. expirationTimeToMs(expirationTime) - expirationTimeToMs(currentTime);
  4447. if (msUntil <= 0) {
  4448. return ImmediatePriority;
  4449. }
  4450. if (msUntil <= HIGH_PRIORITY_EXPIRATION + HIGH_PRIORITY_BATCH_SIZE) {
  4451. return UserBlockingPriority;
  4452. }
  4453. if (msUntil <= LOW_PRIORITY_EXPIRATION + LOW_PRIORITY_BATCH_SIZE) {
  4454. return NormalPriority;
  4455. } // TODO: Handle LowPriority
  4456. // Assume anything lower has idle priority
  4457. return IdlePriority;
  4458. }
  4459. /**
  4460. * inlined Object.is polyfill to avoid requiring consumers ship their own
  4461. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  4462. */
  4463. function is(x, y) {
  4464. return (
  4465. (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare
  4466. );
  4467. }
  4468. var objectIs = typeof Object.is === "function" ? Object.is : is;
  4469. var hasOwnProperty = Object.prototype.hasOwnProperty;
  4470. /**
  4471. * Performs equality by iterating through keys on an object and returning false
  4472. * when any key has values which are not strictly equal between the arguments.
  4473. * Returns true when the values of all keys are strictly equal.
  4474. */
  4475. function shallowEqual(objA, objB) {
  4476. if (objectIs(objA, objB)) {
  4477. return true;
  4478. }
  4479. if (
  4480. typeof objA !== "object" ||
  4481. objA === null ||
  4482. typeof objB !== "object" ||
  4483. objB === null
  4484. ) {
  4485. return false;
  4486. }
  4487. var keysA = Object.keys(objA);
  4488. var keysB = Object.keys(objB);
  4489. if (keysA.length !== keysB.length) {
  4490. return false;
  4491. } // Test for A's keys different from B.
  4492. for (var i = 0; i < keysA.length; i++) {
  4493. if (
  4494. !hasOwnProperty.call(objB, keysA[i]) ||
  4495. !objectIs(objA[keysA[i]], objB[keysA[i]])
  4496. ) {
  4497. return false;
  4498. }
  4499. }
  4500. return true;
  4501. }
  4502. var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
  4503. function describeComponentFrame(name, source, ownerName) {
  4504. var sourceInfo = "";
  4505. if (source) {
  4506. var path = source.fileName;
  4507. var fileName = path.replace(BEFORE_SLASH_RE, "");
  4508. {
  4509. // In DEV, include code for a common special case:
  4510. // prefer "folder/index.js" instead of just "index.js".
  4511. if (/^index\./.test(fileName)) {
  4512. var match = path.match(BEFORE_SLASH_RE);
  4513. if (match) {
  4514. var pathBeforeSlash = match[1];
  4515. if (pathBeforeSlash) {
  4516. var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, "");
  4517. fileName = folderName + "/" + fileName;
  4518. }
  4519. }
  4520. }
  4521. }
  4522. sourceInfo = " (at " + fileName + ":" + source.lineNumber + ")";
  4523. } else if (ownerName) {
  4524. sourceInfo = " (created by " + ownerName + ")";
  4525. }
  4526. return "\n in " + (name || "Unknown") + sourceInfo;
  4527. }
  4528. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  4529. function describeFiber(fiber) {
  4530. switch (fiber.tag) {
  4531. case HostRoot:
  4532. case HostPortal:
  4533. case HostText:
  4534. case Fragment:
  4535. case ContextProvider:
  4536. case ContextConsumer:
  4537. return "";
  4538. default:
  4539. var owner = fiber._debugOwner;
  4540. var source = fiber._debugSource;
  4541. var name = getComponentName(fiber.type);
  4542. var ownerName = null;
  4543. if (owner) {
  4544. ownerName = getComponentName(owner.type);
  4545. }
  4546. return describeComponentFrame(name, source, ownerName);
  4547. }
  4548. }
  4549. function getStackByFiberInDevAndProd(workInProgress) {
  4550. var info = "";
  4551. var node = workInProgress;
  4552. do {
  4553. info += describeFiber(node);
  4554. node = node.return;
  4555. } while (node);
  4556. return info;
  4557. }
  4558. var current = null;
  4559. var isRendering = false;
  4560. function getCurrentFiberOwnerNameInDevOrNull() {
  4561. {
  4562. if (current === null) {
  4563. return null;
  4564. }
  4565. var owner = current._debugOwner;
  4566. if (owner !== null && typeof owner !== "undefined") {
  4567. return getComponentName(owner.type);
  4568. }
  4569. }
  4570. return null;
  4571. }
  4572. function getCurrentFiberStackInDev() {
  4573. {
  4574. if (current === null) {
  4575. return "";
  4576. } // Safe because if current fiber exists, we are reconciling,
  4577. // and it is guaranteed to be the work-in-progress version.
  4578. return getStackByFiberInDevAndProd(current);
  4579. }
  4580. }
  4581. function resetCurrentFiber() {
  4582. {
  4583. ReactDebugCurrentFrame.getCurrentStack = null;
  4584. current = null;
  4585. isRendering = false;
  4586. }
  4587. }
  4588. function setCurrentFiber(fiber) {
  4589. {
  4590. ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
  4591. current = fiber;
  4592. isRendering = false;
  4593. }
  4594. }
  4595. function setIsRendering(rendering) {
  4596. {
  4597. isRendering = rendering;
  4598. }
  4599. }
  4600. var ReactStrictModeWarnings = {
  4601. recordUnsafeLifecycleWarnings: function(fiber, instance) {},
  4602. flushPendingUnsafeLifecycleWarnings: function() {},
  4603. recordLegacyContextWarning: function(fiber, instance) {},
  4604. flushLegacyContextWarning: function() {},
  4605. discardPendingWarnings: function() {}
  4606. };
  4607. {
  4608. var findStrictRoot = function(fiber) {
  4609. var maybeStrictRoot = null;
  4610. var node = fiber;
  4611. while (node !== null) {
  4612. if (node.mode & StrictMode) {
  4613. maybeStrictRoot = node;
  4614. }
  4615. node = node.return;
  4616. }
  4617. return maybeStrictRoot;
  4618. };
  4619. var setToSortedString = function(set) {
  4620. var array = [];
  4621. set.forEach(function(value) {
  4622. array.push(value);
  4623. });
  4624. return array.sort().join(", ");
  4625. };
  4626. var pendingComponentWillMountWarnings = [];
  4627. var pendingUNSAFE_ComponentWillMountWarnings = [];
  4628. var pendingComponentWillReceivePropsWarnings = [];
  4629. var pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  4630. var pendingComponentWillUpdateWarnings = [];
  4631. var pendingUNSAFE_ComponentWillUpdateWarnings = []; // Tracks components we have already warned about.
  4632. var didWarnAboutUnsafeLifecycles = new Set();
  4633. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function(
  4634. fiber,
  4635. instance
  4636. ) {
  4637. // Dedup strategy: Warn once per component.
  4638. if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
  4639. return;
  4640. }
  4641. if (
  4642. typeof instance.componentWillMount === "function" && // Don't warn about react-lifecycles-compat polyfilled components.
  4643. instance.componentWillMount.__suppressDeprecationWarning !== true
  4644. ) {
  4645. pendingComponentWillMountWarnings.push(fiber);
  4646. }
  4647. if (
  4648. fiber.mode & StrictMode &&
  4649. typeof instance.UNSAFE_componentWillMount === "function"
  4650. ) {
  4651. pendingUNSAFE_ComponentWillMountWarnings.push(fiber);
  4652. }
  4653. if (
  4654. typeof instance.componentWillReceiveProps === "function" &&
  4655. instance.componentWillReceiveProps.__suppressDeprecationWarning !== true
  4656. ) {
  4657. pendingComponentWillReceivePropsWarnings.push(fiber);
  4658. }
  4659. if (
  4660. fiber.mode & StrictMode &&
  4661. typeof instance.UNSAFE_componentWillReceiveProps === "function"
  4662. ) {
  4663. pendingUNSAFE_ComponentWillReceivePropsWarnings.push(fiber);
  4664. }
  4665. if (
  4666. typeof instance.componentWillUpdate === "function" &&
  4667. instance.componentWillUpdate.__suppressDeprecationWarning !== true
  4668. ) {
  4669. pendingComponentWillUpdateWarnings.push(fiber);
  4670. }
  4671. if (
  4672. fiber.mode & StrictMode &&
  4673. typeof instance.UNSAFE_componentWillUpdate === "function"
  4674. ) {
  4675. pendingUNSAFE_ComponentWillUpdateWarnings.push(fiber);
  4676. }
  4677. };
  4678. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function() {
  4679. // We do an initial pass to gather component names
  4680. var componentWillMountUniqueNames = new Set();
  4681. if (pendingComponentWillMountWarnings.length > 0) {
  4682. pendingComponentWillMountWarnings.forEach(function(fiber) {
  4683. componentWillMountUniqueNames.add(
  4684. getComponentName(fiber.type) || "Component"
  4685. );
  4686. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4687. });
  4688. pendingComponentWillMountWarnings = [];
  4689. }
  4690. var UNSAFE_componentWillMountUniqueNames = new Set();
  4691. if (pendingUNSAFE_ComponentWillMountWarnings.length > 0) {
  4692. pendingUNSAFE_ComponentWillMountWarnings.forEach(function(fiber) {
  4693. UNSAFE_componentWillMountUniqueNames.add(
  4694. getComponentName(fiber.type) || "Component"
  4695. );
  4696. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4697. });
  4698. pendingUNSAFE_ComponentWillMountWarnings = [];
  4699. }
  4700. var componentWillReceivePropsUniqueNames = new Set();
  4701. if (pendingComponentWillReceivePropsWarnings.length > 0) {
  4702. pendingComponentWillReceivePropsWarnings.forEach(function(fiber) {
  4703. componentWillReceivePropsUniqueNames.add(
  4704. getComponentName(fiber.type) || "Component"
  4705. );
  4706. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4707. });
  4708. pendingComponentWillReceivePropsWarnings = [];
  4709. }
  4710. var UNSAFE_componentWillReceivePropsUniqueNames = new Set();
  4711. if (pendingUNSAFE_ComponentWillReceivePropsWarnings.length > 0) {
  4712. pendingUNSAFE_ComponentWillReceivePropsWarnings.forEach(function(fiber) {
  4713. UNSAFE_componentWillReceivePropsUniqueNames.add(
  4714. getComponentName(fiber.type) || "Component"
  4715. );
  4716. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4717. });
  4718. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  4719. }
  4720. var componentWillUpdateUniqueNames = new Set();
  4721. if (pendingComponentWillUpdateWarnings.length > 0) {
  4722. pendingComponentWillUpdateWarnings.forEach(function(fiber) {
  4723. componentWillUpdateUniqueNames.add(
  4724. getComponentName(fiber.type) || "Component"
  4725. );
  4726. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4727. });
  4728. pendingComponentWillUpdateWarnings = [];
  4729. }
  4730. var UNSAFE_componentWillUpdateUniqueNames = new Set();
  4731. if (pendingUNSAFE_ComponentWillUpdateWarnings.length > 0) {
  4732. pendingUNSAFE_ComponentWillUpdateWarnings.forEach(function(fiber) {
  4733. UNSAFE_componentWillUpdateUniqueNames.add(
  4734. getComponentName(fiber.type) || "Component"
  4735. );
  4736. didWarnAboutUnsafeLifecycles.add(fiber.type);
  4737. });
  4738. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  4739. } // Finally, we flush all the warnings
  4740. // UNSAFE_ ones before the deprecated ones, since they'll be 'louder'
  4741. if (UNSAFE_componentWillMountUniqueNames.size > 0) {
  4742. var sortedNames = setToSortedString(UNSAFE_componentWillMountUniqueNames);
  4743. error(
  4744. "Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. " +
  4745. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  4746. "* Move code with side effects to componentDidMount, and set initial state in the constructor.\n" +
  4747. "\nPlease update the following components: %s",
  4748. sortedNames
  4749. );
  4750. }
  4751. if (UNSAFE_componentWillReceivePropsUniqueNames.size > 0) {
  4752. var _sortedNames = setToSortedString(
  4753. UNSAFE_componentWillReceivePropsUniqueNames
  4754. );
  4755. error(
  4756. "Using UNSAFE_componentWillReceiveProps in strict mode is not recommended " +
  4757. "and may indicate bugs in your code. " +
  4758. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  4759. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  4760. "* If you're updating state whenever props change, " +
  4761. "refactor your code to use memoization techniques or move it to " +
  4762. "static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state\n" +
  4763. "\nPlease update the following components: %s",
  4764. _sortedNames
  4765. );
  4766. }
  4767. if (UNSAFE_componentWillUpdateUniqueNames.size > 0) {
  4768. var _sortedNames2 = setToSortedString(
  4769. UNSAFE_componentWillUpdateUniqueNames
  4770. );
  4771. error(
  4772. "Using UNSAFE_componentWillUpdate in strict mode is not recommended " +
  4773. "and may indicate bugs in your code. " +
  4774. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  4775. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  4776. "\nPlease update the following components: %s",
  4777. _sortedNames2
  4778. );
  4779. }
  4780. if (componentWillMountUniqueNames.size > 0) {
  4781. var _sortedNames3 = setToSortedString(componentWillMountUniqueNames);
  4782. warn(
  4783. "componentWillMount has been renamed, and is not recommended for use. " +
  4784. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  4785. "* Move code with side effects to componentDidMount, and set initial state in the constructor.\n" +
  4786. "* Rename componentWillMount to UNSAFE_componentWillMount to suppress " +
  4787. "this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. " +
  4788. "To rename all deprecated lifecycles to their new names, you can run " +
  4789. "`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n" +
  4790. "\nPlease update the following components: %s",
  4791. _sortedNames3
  4792. );
  4793. }
  4794. if (componentWillReceivePropsUniqueNames.size > 0) {
  4795. var _sortedNames4 = setToSortedString(
  4796. componentWillReceivePropsUniqueNames
  4797. );
  4798. warn(
  4799. "componentWillReceiveProps has been renamed, and is not recommended for use. " +
  4800. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  4801. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  4802. "* If you're updating state whenever props change, refactor your " +
  4803. "code to use memoization techniques or move it to " +
  4804. "static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state\n" +
  4805. "* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress " +
  4806. "this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. " +
  4807. "To rename all deprecated lifecycles to their new names, you can run " +
  4808. "`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n" +
  4809. "\nPlease update the following components: %s",
  4810. _sortedNames4
  4811. );
  4812. }
  4813. if (componentWillUpdateUniqueNames.size > 0) {
  4814. var _sortedNames5 = setToSortedString(componentWillUpdateUniqueNames);
  4815. warn(
  4816. "componentWillUpdate has been renamed, and is not recommended for use. " +
  4817. "See https://fb.me/react-unsafe-component-lifecycles for details.\n\n" +
  4818. "* Move data fetching code or side effects to componentDidUpdate.\n" +
  4819. "* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress " +
  4820. "this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. " +
  4821. "To rename all deprecated lifecycles to their new names, you can run " +
  4822. "`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n" +
  4823. "\nPlease update the following components: %s",
  4824. _sortedNames5
  4825. );
  4826. }
  4827. };
  4828. var pendingLegacyContextWarning = new Map(); // Tracks components we have already warned about.
  4829. var didWarnAboutLegacyContext = new Set();
  4830. ReactStrictModeWarnings.recordLegacyContextWarning = function(
  4831. fiber,
  4832. instance
  4833. ) {
  4834. var strictRoot = findStrictRoot(fiber);
  4835. if (strictRoot === null) {
  4836. error(
  4837. "Expected to find a StrictMode component in a strict mode tree. " +
  4838. "This error is likely caused by a bug in React. Please file an issue."
  4839. );
  4840. return;
  4841. } // Dedup strategy: Warn once per component.
  4842. if (didWarnAboutLegacyContext.has(fiber.type)) {
  4843. return;
  4844. }
  4845. var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
  4846. if (
  4847. fiber.type.contextTypes != null ||
  4848. fiber.type.childContextTypes != null ||
  4849. (instance !== null && typeof instance.getChildContext === "function")
  4850. ) {
  4851. if (warningsForRoot === undefined) {
  4852. warningsForRoot = [];
  4853. pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
  4854. }
  4855. warningsForRoot.push(fiber);
  4856. }
  4857. };
  4858. ReactStrictModeWarnings.flushLegacyContextWarning = function() {
  4859. pendingLegacyContextWarning.forEach(function(fiberArray, strictRoot) {
  4860. if (fiberArray.length === 0) {
  4861. return;
  4862. }
  4863. var firstFiber = fiberArray[0];
  4864. var uniqueNames = new Set();
  4865. fiberArray.forEach(function(fiber) {
  4866. uniqueNames.add(getComponentName(fiber.type) || "Component");
  4867. didWarnAboutLegacyContext.add(fiber.type);
  4868. });
  4869. var sortedNames = setToSortedString(uniqueNames);
  4870. var firstComponentStack = getStackByFiberInDevAndProd(firstFiber);
  4871. error(
  4872. "Legacy context API has been detected within a strict-mode tree." +
  4873. "\n\nThe old API will be supported in all 16.x releases, but applications " +
  4874. "using it should migrate to the new version." +
  4875. "\n\nPlease update the following components: %s" +
  4876. "\n\nLearn more about this warning here: https://fb.me/react-legacy-context" +
  4877. "%s",
  4878. sortedNames,
  4879. firstComponentStack
  4880. );
  4881. });
  4882. };
  4883. ReactStrictModeWarnings.discardPendingWarnings = function() {
  4884. pendingComponentWillMountWarnings = [];
  4885. pendingUNSAFE_ComponentWillMountWarnings = [];
  4886. pendingComponentWillReceivePropsWarnings = [];
  4887. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  4888. pendingComponentWillUpdateWarnings = [];
  4889. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  4890. pendingLegacyContextWarning = new Map();
  4891. };
  4892. }
  4893. var resolveFamily = null; // $FlowFixMe Flow gets confused by a WeakSet feature check below.
  4894. var failedBoundaries = null;
  4895. var setRefreshHandler = function(handler) {
  4896. {
  4897. resolveFamily = handler;
  4898. }
  4899. };
  4900. function resolveFunctionForHotReloading(type) {
  4901. {
  4902. if (resolveFamily === null) {
  4903. // Hot reloading is disabled.
  4904. return type;
  4905. }
  4906. var family = resolveFamily(type);
  4907. if (family === undefined) {
  4908. return type;
  4909. } // Use the latest known implementation.
  4910. return family.current;
  4911. }
  4912. }
  4913. function resolveClassForHotReloading(type) {
  4914. // No implementation differences.
  4915. return resolveFunctionForHotReloading(type);
  4916. }
  4917. function resolveForwardRefForHotReloading(type) {
  4918. {
  4919. if (resolveFamily === null) {
  4920. // Hot reloading is disabled.
  4921. return type;
  4922. }
  4923. var family = resolveFamily(type);
  4924. if (family === undefined) {
  4925. // Check if we're dealing with a real forwardRef. Don't want to crash early.
  4926. if (
  4927. type !== null &&
  4928. type !== undefined &&
  4929. typeof type.render === "function"
  4930. ) {
  4931. // ForwardRef is special because its resolved .type is an object,
  4932. // but it's possible that we only have its inner render function in the map.
  4933. // If that inner render function is different, we'll build a new forwardRef type.
  4934. var currentRender = resolveFunctionForHotReloading(type.render);
  4935. if (type.render !== currentRender) {
  4936. var syntheticType = {
  4937. $$typeof: REACT_FORWARD_REF_TYPE,
  4938. render: currentRender
  4939. };
  4940. if (type.displayName !== undefined) {
  4941. syntheticType.displayName = type.displayName;
  4942. }
  4943. return syntheticType;
  4944. }
  4945. }
  4946. return type;
  4947. } // Use the latest known implementation.
  4948. return family.current;
  4949. }
  4950. }
  4951. function isCompatibleFamilyForHotReloading(fiber, element) {
  4952. {
  4953. if (resolveFamily === null) {
  4954. // Hot reloading is disabled.
  4955. return false;
  4956. }
  4957. var prevType = fiber.elementType;
  4958. var nextType = element.type; // If we got here, we know types aren't === equal.
  4959. var needsCompareFamilies = false;
  4960. var $$typeofNextType =
  4961. typeof nextType === "object" && nextType !== null
  4962. ? nextType.$$typeof
  4963. : null;
  4964. switch (fiber.tag) {
  4965. case ClassComponent: {
  4966. if (typeof nextType === "function") {
  4967. needsCompareFamilies = true;
  4968. }
  4969. break;
  4970. }
  4971. case FunctionComponent: {
  4972. if (typeof nextType === "function") {
  4973. needsCompareFamilies = true;
  4974. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  4975. // We don't know the inner type yet.
  4976. // We're going to assume that the lazy inner type is stable,
  4977. // and so it is sufficient to avoid reconciling it away.
  4978. // We're not going to unwrap or actually use the new lazy type.
  4979. needsCompareFamilies = true;
  4980. }
  4981. break;
  4982. }
  4983. case ForwardRef: {
  4984. if ($$typeofNextType === REACT_FORWARD_REF_TYPE) {
  4985. needsCompareFamilies = true;
  4986. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  4987. needsCompareFamilies = true;
  4988. }
  4989. break;
  4990. }
  4991. case MemoComponent:
  4992. case SimpleMemoComponent: {
  4993. if ($$typeofNextType === REACT_MEMO_TYPE) {
  4994. // TODO: if it was but can no longer be simple,
  4995. // we shouldn't set this.
  4996. needsCompareFamilies = true;
  4997. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  4998. needsCompareFamilies = true;
  4999. }
  5000. break;
  5001. }
  5002. default:
  5003. return false;
  5004. } // Check if both types have a family and it's the same one.
  5005. if (needsCompareFamilies) {
  5006. // Note: memo() and forwardRef() we'll compare outer rather than inner type.
  5007. // This means both of them need to be registered to preserve state.
  5008. // If we unwrapped and compared the inner types for wrappers instead,
  5009. // then we would risk falsely saying two separate memo(Foo)
  5010. // calls are equivalent because they wrap the same Foo function.
  5011. var prevFamily = resolveFamily(prevType);
  5012. if (prevFamily !== undefined && prevFamily === resolveFamily(nextType)) {
  5013. return true;
  5014. }
  5015. }
  5016. return false;
  5017. }
  5018. }
  5019. function markFailedErrorBoundaryForHotReloading(fiber) {
  5020. {
  5021. if (resolveFamily === null) {
  5022. // Hot reloading is disabled.
  5023. return;
  5024. }
  5025. if (typeof WeakSet !== "function") {
  5026. return;
  5027. }
  5028. if (failedBoundaries === null) {
  5029. failedBoundaries = new WeakSet();
  5030. }
  5031. failedBoundaries.add(fiber);
  5032. }
  5033. }
  5034. var scheduleRefresh = function(root, update) {
  5035. {
  5036. if (resolveFamily === null) {
  5037. // Hot reloading is disabled.
  5038. return;
  5039. }
  5040. var staleFamilies = update.staleFamilies,
  5041. updatedFamilies = update.updatedFamilies;
  5042. flushPassiveEffects();
  5043. flushSync(function() {
  5044. scheduleFibersWithFamiliesRecursively(
  5045. root.current,
  5046. updatedFamilies,
  5047. staleFamilies
  5048. );
  5049. });
  5050. }
  5051. };
  5052. var scheduleRoot = function(root, element) {
  5053. {
  5054. if (root.context !== emptyContextObject) {
  5055. // Super edge case: root has a legacy _renderSubtree context
  5056. // but we don't know the parentComponent so we can't pass it.
  5057. // Just ignore. We'll delete this with _renderSubtree code path later.
  5058. return;
  5059. }
  5060. flushPassiveEffects();
  5061. syncUpdates(function() {
  5062. updateContainer(element, root, null, null);
  5063. });
  5064. }
  5065. };
  5066. function scheduleFibersWithFamiliesRecursively(
  5067. fiber,
  5068. updatedFamilies,
  5069. staleFamilies
  5070. ) {
  5071. {
  5072. var alternate = fiber.alternate,
  5073. child = fiber.child,
  5074. sibling = fiber.sibling,
  5075. tag = fiber.tag,
  5076. type = fiber.type;
  5077. var candidateType = null;
  5078. switch (tag) {
  5079. case FunctionComponent:
  5080. case SimpleMemoComponent:
  5081. case ClassComponent:
  5082. candidateType = type;
  5083. break;
  5084. case ForwardRef:
  5085. candidateType = type.render;
  5086. break;
  5087. }
  5088. if (resolveFamily === null) {
  5089. throw new Error("Expected resolveFamily to be set during hot reload.");
  5090. }
  5091. var needsRender = false;
  5092. var needsRemount = false;
  5093. if (candidateType !== null) {
  5094. var family = resolveFamily(candidateType);
  5095. if (family !== undefined) {
  5096. if (staleFamilies.has(family)) {
  5097. needsRemount = true;
  5098. } else if (updatedFamilies.has(family)) {
  5099. if (tag === ClassComponent) {
  5100. needsRemount = true;
  5101. } else {
  5102. needsRender = true;
  5103. }
  5104. }
  5105. }
  5106. }
  5107. if (failedBoundaries !== null) {
  5108. if (
  5109. failedBoundaries.has(fiber) ||
  5110. (alternate !== null && failedBoundaries.has(alternate))
  5111. ) {
  5112. needsRemount = true;
  5113. }
  5114. }
  5115. if (needsRemount) {
  5116. fiber._debugNeedsRemount = true;
  5117. }
  5118. if (needsRemount || needsRender) {
  5119. scheduleWork(fiber, Sync);
  5120. }
  5121. if (child !== null && !needsRemount) {
  5122. scheduleFibersWithFamiliesRecursively(
  5123. child,
  5124. updatedFamilies,
  5125. staleFamilies
  5126. );
  5127. }
  5128. if (sibling !== null) {
  5129. scheduleFibersWithFamiliesRecursively(
  5130. sibling,
  5131. updatedFamilies,
  5132. staleFamilies
  5133. );
  5134. }
  5135. }
  5136. }
  5137. var findHostInstancesForRefresh = function(root, families) {
  5138. {
  5139. var hostInstances = new Set();
  5140. var types = new Set(
  5141. families.map(function(family) {
  5142. return family.current;
  5143. })
  5144. );
  5145. findHostInstancesForMatchingFibersRecursively(
  5146. root.current,
  5147. types,
  5148. hostInstances
  5149. );
  5150. return hostInstances;
  5151. }
  5152. };
  5153. function findHostInstancesForMatchingFibersRecursively(
  5154. fiber,
  5155. types,
  5156. hostInstances
  5157. ) {
  5158. {
  5159. var child = fiber.child,
  5160. sibling = fiber.sibling,
  5161. tag = fiber.tag,
  5162. type = fiber.type;
  5163. var candidateType = null;
  5164. switch (tag) {
  5165. case FunctionComponent:
  5166. case SimpleMemoComponent:
  5167. case ClassComponent:
  5168. candidateType = type;
  5169. break;
  5170. case ForwardRef:
  5171. candidateType = type.render;
  5172. break;
  5173. }
  5174. var didMatch = false;
  5175. if (candidateType !== null) {
  5176. if (types.has(candidateType)) {
  5177. didMatch = true;
  5178. }
  5179. }
  5180. if (didMatch) {
  5181. // We have a match. This only drills down to the closest host components.
  5182. // There's no need to search deeper because for the purpose of giving
  5183. // visual feedback, "flashing" outermost parent rectangles is sufficient.
  5184. findHostInstancesForFiberShallowly(fiber, hostInstances);
  5185. } else {
  5186. // If there's no match, maybe there will be one further down in the child tree.
  5187. if (child !== null) {
  5188. findHostInstancesForMatchingFibersRecursively(
  5189. child,
  5190. types,
  5191. hostInstances
  5192. );
  5193. }
  5194. }
  5195. if (sibling !== null) {
  5196. findHostInstancesForMatchingFibersRecursively(
  5197. sibling,
  5198. types,
  5199. hostInstances
  5200. );
  5201. }
  5202. }
  5203. }
  5204. function findHostInstancesForFiberShallowly(fiber, hostInstances) {
  5205. {
  5206. var foundHostInstances = findChildHostInstancesForFiberShallowly(
  5207. fiber,
  5208. hostInstances
  5209. );
  5210. if (foundHostInstances) {
  5211. return;
  5212. } // If we didn't find any host children, fallback to closest host parent.
  5213. var node = fiber;
  5214. while (true) {
  5215. switch (node.tag) {
  5216. case HostComponent:
  5217. hostInstances.add(node.stateNode);
  5218. return;
  5219. case HostPortal:
  5220. hostInstances.add(node.stateNode.containerInfo);
  5221. return;
  5222. case HostRoot:
  5223. hostInstances.add(node.stateNode.containerInfo);
  5224. return;
  5225. }
  5226. if (node.return === null) {
  5227. throw new Error("Expected to reach root first.");
  5228. }
  5229. node = node.return;
  5230. }
  5231. }
  5232. }
  5233. function findChildHostInstancesForFiberShallowly(fiber, hostInstances) {
  5234. {
  5235. var node = fiber;
  5236. var foundHostInstances = false;
  5237. while (true) {
  5238. if (node.tag === HostComponent) {
  5239. // We got a match.
  5240. foundHostInstances = true;
  5241. hostInstances.add(node.stateNode); // There may still be more, so keep searching.
  5242. } else if (node.child !== null) {
  5243. node.child.return = node;
  5244. node = node.child;
  5245. continue;
  5246. }
  5247. if (node === fiber) {
  5248. return foundHostInstances;
  5249. }
  5250. while (node.sibling === null) {
  5251. if (node.return === null || node.return === fiber) {
  5252. return foundHostInstances;
  5253. }
  5254. node = node.return;
  5255. }
  5256. node.sibling.return = node.return;
  5257. node = node.sibling;
  5258. }
  5259. }
  5260. return false;
  5261. }
  5262. function resolveDefaultProps(Component, baseProps) {
  5263. if (Component && Component.defaultProps) {
  5264. // Resolve default props. Taken from ReactElement
  5265. var props = Object.assign({}, baseProps);
  5266. var defaultProps = Component.defaultProps;
  5267. for (var propName in defaultProps) {
  5268. if (props[propName] === undefined) {
  5269. props[propName] = defaultProps[propName];
  5270. }
  5271. }
  5272. return props;
  5273. }
  5274. return baseProps;
  5275. }
  5276. function readLazyComponentType(lazyComponent) {
  5277. initializeLazyComponentType(lazyComponent);
  5278. if (lazyComponent._status !== Resolved) {
  5279. throw lazyComponent._result;
  5280. }
  5281. return lazyComponent._result;
  5282. }
  5283. var valueCursor = createCursor(null);
  5284. var rendererSigil;
  5285. {
  5286. // Use this to detect multiple renderers using the same context
  5287. rendererSigil = {};
  5288. }
  5289. var currentlyRenderingFiber = null;
  5290. var lastContextDependency = null;
  5291. var lastContextWithAllBitsObserved = null;
  5292. var isDisallowedContextReadInDEV = false;
  5293. function resetContextDependencies() {
  5294. // This is called right before React yields execution, to ensure `readContext`
  5295. // cannot be called outside the render phase.
  5296. currentlyRenderingFiber = null;
  5297. lastContextDependency = null;
  5298. lastContextWithAllBitsObserved = null;
  5299. {
  5300. isDisallowedContextReadInDEV = false;
  5301. }
  5302. }
  5303. function enterDisallowedContextReadInDEV() {
  5304. {
  5305. isDisallowedContextReadInDEV = true;
  5306. }
  5307. }
  5308. function exitDisallowedContextReadInDEV() {
  5309. {
  5310. isDisallowedContextReadInDEV = false;
  5311. }
  5312. }
  5313. function pushProvider(providerFiber, nextValue) {
  5314. var context = providerFiber.type._context;
  5315. {
  5316. push(valueCursor, context._currentValue2, providerFiber);
  5317. context._currentValue2 = nextValue;
  5318. {
  5319. if (
  5320. context._currentRenderer2 !== undefined &&
  5321. context._currentRenderer2 !== null &&
  5322. context._currentRenderer2 !== rendererSigil
  5323. ) {
  5324. error(
  5325. "Detected multiple renderers concurrently rendering the " +
  5326. "same context provider. This is currently unsupported."
  5327. );
  5328. }
  5329. context._currentRenderer2 = rendererSigil;
  5330. }
  5331. }
  5332. }
  5333. function popProvider(providerFiber) {
  5334. var currentValue = valueCursor.current;
  5335. pop(valueCursor, providerFiber);
  5336. var context = providerFiber.type._context;
  5337. {
  5338. context._currentValue2 = currentValue;
  5339. }
  5340. }
  5341. function calculateChangedBits(context, newValue, oldValue) {
  5342. if (objectIs(oldValue, newValue)) {
  5343. // No change
  5344. return 0;
  5345. } else {
  5346. var changedBits =
  5347. typeof context._calculateChangedBits === "function"
  5348. ? context._calculateChangedBits(oldValue, newValue)
  5349. : MAX_SIGNED_31_BIT_INT;
  5350. {
  5351. if ((changedBits & MAX_SIGNED_31_BIT_INT) !== changedBits) {
  5352. error(
  5353. "calculateChangedBits: Expected the return value to be a " +
  5354. "31-bit integer. Instead received: %s",
  5355. changedBits
  5356. );
  5357. }
  5358. }
  5359. return changedBits | 0;
  5360. }
  5361. }
  5362. function scheduleWorkOnParentPath(parent, renderExpirationTime) {
  5363. // Update the child expiration time of all the ancestors, including
  5364. // the alternates.
  5365. var node = parent;
  5366. while (node !== null) {
  5367. var alternate = node.alternate;
  5368. if (node.childExpirationTime < renderExpirationTime) {
  5369. node.childExpirationTime = renderExpirationTime;
  5370. if (
  5371. alternate !== null &&
  5372. alternate.childExpirationTime < renderExpirationTime
  5373. ) {
  5374. alternate.childExpirationTime = renderExpirationTime;
  5375. }
  5376. } else if (
  5377. alternate !== null &&
  5378. alternate.childExpirationTime < renderExpirationTime
  5379. ) {
  5380. alternate.childExpirationTime = renderExpirationTime;
  5381. } else {
  5382. // Neither alternate was updated, which means the rest of the
  5383. // ancestor path already has sufficient priority.
  5384. break;
  5385. }
  5386. node = node.return;
  5387. }
  5388. }
  5389. function propagateContextChange(
  5390. workInProgress,
  5391. context,
  5392. changedBits,
  5393. renderExpirationTime
  5394. ) {
  5395. var fiber = workInProgress.child;
  5396. if (fiber !== null) {
  5397. // Set the return pointer of the child to the work-in-progress fiber.
  5398. fiber.return = workInProgress;
  5399. }
  5400. while (fiber !== null) {
  5401. var nextFiber = void 0; // Visit this fiber.
  5402. var list = fiber.dependencies;
  5403. if (list !== null) {
  5404. nextFiber = fiber.child;
  5405. var dependency = list.firstContext;
  5406. while (dependency !== null) {
  5407. // Check if the context matches.
  5408. if (
  5409. dependency.context === context &&
  5410. (dependency.observedBits & changedBits) !== 0
  5411. ) {
  5412. // Match! Schedule an update on this fiber.
  5413. if (fiber.tag === ClassComponent) {
  5414. // Schedule a force update on the work-in-progress.
  5415. var update = createUpdate(renderExpirationTime, null);
  5416. update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
  5417. // update to the current fiber, too, which means it will persist even if
  5418. // this render is thrown away. Since it's a race condition, not sure it's
  5419. // worth fixing.
  5420. enqueueUpdate(fiber, update);
  5421. }
  5422. if (fiber.expirationTime < renderExpirationTime) {
  5423. fiber.expirationTime = renderExpirationTime;
  5424. }
  5425. var alternate = fiber.alternate;
  5426. if (
  5427. alternate !== null &&
  5428. alternate.expirationTime < renderExpirationTime
  5429. ) {
  5430. alternate.expirationTime = renderExpirationTime;
  5431. }
  5432. scheduleWorkOnParentPath(fiber.return, renderExpirationTime); // Mark the expiration time on the list, too.
  5433. if (list.expirationTime < renderExpirationTime) {
  5434. list.expirationTime = renderExpirationTime;
  5435. } // Since we already found a match, we can stop traversing the
  5436. // dependency list.
  5437. break;
  5438. }
  5439. dependency = dependency.next;
  5440. }
  5441. } else if (fiber.tag === ContextProvider) {
  5442. // Don't scan deeper if this is a matching provider
  5443. nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
  5444. } else {
  5445. // Traverse down.
  5446. nextFiber = fiber.child;
  5447. }
  5448. if (nextFiber !== null) {
  5449. // Set the return pointer of the child to the work-in-progress fiber.
  5450. nextFiber.return = fiber;
  5451. } else {
  5452. // No child. Traverse to next sibling.
  5453. nextFiber = fiber;
  5454. while (nextFiber !== null) {
  5455. if (nextFiber === workInProgress) {
  5456. // We're back to the root of this subtree. Exit.
  5457. nextFiber = null;
  5458. break;
  5459. }
  5460. var sibling = nextFiber.sibling;
  5461. if (sibling !== null) {
  5462. // Set the return pointer of the sibling to the work-in-progress fiber.
  5463. sibling.return = nextFiber.return;
  5464. nextFiber = sibling;
  5465. break;
  5466. } // No more siblings. Traverse up.
  5467. nextFiber = nextFiber.return;
  5468. }
  5469. }
  5470. fiber = nextFiber;
  5471. }
  5472. }
  5473. function prepareToReadContext(workInProgress, renderExpirationTime) {
  5474. currentlyRenderingFiber = workInProgress;
  5475. lastContextDependency = null;
  5476. lastContextWithAllBitsObserved = null;
  5477. var dependencies = workInProgress.dependencies;
  5478. if (dependencies !== null) {
  5479. var firstContext = dependencies.firstContext;
  5480. if (firstContext !== null) {
  5481. if (dependencies.expirationTime >= renderExpirationTime) {
  5482. // Context list has a pending update. Mark that this fiber performed work.
  5483. markWorkInProgressReceivedUpdate();
  5484. } // Reset the work-in-progress list
  5485. dependencies.firstContext = null;
  5486. }
  5487. }
  5488. }
  5489. function readContext(context, observedBits) {
  5490. {
  5491. // This warning would fire if you read context inside a Hook like useMemo.
  5492. // Unlike the class check below, it's not enforced in production for perf.
  5493. if (isDisallowedContextReadInDEV) {
  5494. error(
  5495. "Context can only be read while React is rendering. " +
  5496. "In classes, you can read it in the render method or getDerivedStateFromProps. " +
  5497. "In function components, you can read it directly in the function body, but not " +
  5498. "inside Hooks like useReducer() or useMemo()."
  5499. );
  5500. }
  5501. }
  5502. if (lastContextWithAllBitsObserved === context);
  5503. else if (observedBits === false || observedBits === 0);
  5504. else {
  5505. var resolvedObservedBits; // Avoid deopting on observable arguments or heterogeneous types.
  5506. if (
  5507. typeof observedBits !== "number" ||
  5508. observedBits === MAX_SIGNED_31_BIT_INT
  5509. ) {
  5510. // Observe all updates.
  5511. lastContextWithAllBitsObserved = context;
  5512. resolvedObservedBits = MAX_SIGNED_31_BIT_INT;
  5513. } else {
  5514. resolvedObservedBits = observedBits;
  5515. }
  5516. var contextItem = {
  5517. context: context,
  5518. observedBits: resolvedObservedBits,
  5519. next: null
  5520. };
  5521. if (lastContextDependency === null) {
  5522. if (!(currentlyRenderingFiber !== null)) {
  5523. throw Error(
  5524. "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()."
  5525. );
  5526. } // This is the first dependency for this component. Create a new list.
  5527. lastContextDependency = contextItem;
  5528. currentlyRenderingFiber.dependencies = {
  5529. expirationTime: NoWork,
  5530. firstContext: contextItem,
  5531. responders: null
  5532. };
  5533. } else {
  5534. // Append a new context item.
  5535. lastContextDependency = lastContextDependency.next = contextItem;
  5536. }
  5537. }
  5538. return context._currentValue2;
  5539. }
  5540. var UpdateState = 0;
  5541. var ReplaceState = 1;
  5542. var ForceUpdate = 2;
  5543. var CaptureUpdate = 3; // Global state that is reset at the beginning of calling `processUpdateQueue`.
  5544. // It should only be read right after calling `processUpdateQueue`, via
  5545. // `checkHasForceUpdateAfterProcessing`.
  5546. var hasForceUpdate = false;
  5547. var didWarnUpdateInsideUpdate;
  5548. var currentlyProcessingQueue;
  5549. {
  5550. didWarnUpdateInsideUpdate = false;
  5551. currentlyProcessingQueue = null;
  5552. }
  5553. function initializeUpdateQueue(fiber) {
  5554. var queue = {
  5555. baseState: fiber.memoizedState,
  5556. baseQueue: null,
  5557. shared: {
  5558. pending: null
  5559. },
  5560. effects: null
  5561. };
  5562. fiber.updateQueue = queue;
  5563. }
  5564. function cloneUpdateQueue(current, workInProgress) {
  5565. // Clone the update queue from current. Unless it's already a clone.
  5566. var queue = workInProgress.updateQueue;
  5567. var currentQueue = current.updateQueue;
  5568. if (queue === currentQueue) {
  5569. var clone = {
  5570. baseState: currentQueue.baseState,
  5571. baseQueue: currentQueue.baseQueue,
  5572. shared: currentQueue.shared,
  5573. effects: currentQueue.effects
  5574. };
  5575. workInProgress.updateQueue = clone;
  5576. }
  5577. }
  5578. function createUpdate(expirationTime, suspenseConfig) {
  5579. var update = {
  5580. expirationTime: expirationTime,
  5581. suspenseConfig: suspenseConfig,
  5582. tag: UpdateState,
  5583. payload: null,
  5584. callback: null,
  5585. next: null
  5586. };
  5587. update.next = update;
  5588. {
  5589. update.priority = getCurrentPriorityLevel();
  5590. }
  5591. return update;
  5592. }
  5593. function enqueueUpdate(fiber, update) {
  5594. var updateQueue = fiber.updateQueue;
  5595. if (updateQueue === null) {
  5596. // Only occurs if the fiber has been unmounted.
  5597. return;
  5598. }
  5599. var sharedQueue = updateQueue.shared;
  5600. var pending = sharedQueue.pending;
  5601. if (pending === null) {
  5602. // This is the first update. Create a circular list.
  5603. update.next = update;
  5604. } else {
  5605. update.next = pending.next;
  5606. pending.next = update;
  5607. }
  5608. sharedQueue.pending = update;
  5609. {
  5610. if (
  5611. currentlyProcessingQueue === sharedQueue &&
  5612. !didWarnUpdateInsideUpdate
  5613. ) {
  5614. error(
  5615. "An update (setState, replaceState, or forceUpdate) was scheduled " +
  5616. "from inside an update function. Update functions should be pure, " +
  5617. "with zero side-effects. Consider using componentDidUpdate or a " +
  5618. "callback."
  5619. );
  5620. didWarnUpdateInsideUpdate = true;
  5621. }
  5622. }
  5623. }
  5624. function enqueueCapturedUpdate(workInProgress, update) {
  5625. var current = workInProgress.alternate;
  5626. if (current !== null) {
  5627. // Ensure the work-in-progress queue is a clone
  5628. cloneUpdateQueue(current, workInProgress);
  5629. } // Captured updates go only on the work-in-progress queue.
  5630. var queue = workInProgress.updateQueue; // Append the update to the end of the list.
  5631. var last = queue.baseQueue;
  5632. if (last === null) {
  5633. queue.baseQueue = update.next = update;
  5634. update.next = update;
  5635. } else {
  5636. update.next = last.next;
  5637. last.next = update;
  5638. }
  5639. }
  5640. function getStateFromUpdate(
  5641. workInProgress,
  5642. queue,
  5643. update,
  5644. prevState,
  5645. nextProps,
  5646. instance
  5647. ) {
  5648. switch (update.tag) {
  5649. case ReplaceState: {
  5650. var payload = update.payload;
  5651. if (typeof payload === "function") {
  5652. // Updater function
  5653. {
  5654. enterDisallowedContextReadInDEV();
  5655. }
  5656. var nextState = payload.call(instance, prevState, nextProps);
  5657. {
  5658. exitDisallowedContextReadInDEV();
  5659. }
  5660. return nextState;
  5661. } // State object
  5662. return payload;
  5663. }
  5664. case CaptureUpdate: {
  5665. workInProgress.effectTag =
  5666. (workInProgress.effectTag & ~ShouldCapture) | DidCapture;
  5667. }
  5668. // Intentional fallthrough
  5669. case UpdateState: {
  5670. var _payload = update.payload;
  5671. var partialState;
  5672. if (typeof _payload === "function") {
  5673. // Updater function
  5674. {
  5675. enterDisallowedContextReadInDEV();
  5676. }
  5677. partialState = _payload.call(instance, prevState, nextProps);
  5678. {
  5679. exitDisallowedContextReadInDEV();
  5680. }
  5681. } else {
  5682. // Partial state object
  5683. partialState = _payload;
  5684. }
  5685. if (partialState === null || partialState === undefined) {
  5686. // Null and undefined are treated as no-ops.
  5687. return prevState;
  5688. } // Merge the partial state and the previous state.
  5689. return Object.assign({}, prevState, partialState);
  5690. }
  5691. case ForceUpdate: {
  5692. hasForceUpdate = true;
  5693. return prevState;
  5694. }
  5695. }
  5696. return prevState;
  5697. }
  5698. function processUpdateQueue(
  5699. workInProgress,
  5700. props,
  5701. instance,
  5702. renderExpirationTime
  5703. ) {
  5704. // This is always non-null on a ClassComponent or HostRoot
  5705. var queue = workInProgress.updateQueue;
  5706. hasForceUpdate = false;
  5707. {
  5708. currentlyProcessingQueue = queue.shared;
  5709. } // The last rebase update that is NOT part of the base state.
  5710. var baseQueue = queue.baseQueue; // The last pending update that hasn't been processed yet.
  5711. var pendingQueue = queue.shared.pending;
  5712. if (pendingQueue !== null) {
  5713. // We have new updates that haven't been processed yet.
  5714. // We'll add them to the base queue.
  5715. if (baseQueue !== null) {
  5716. // Merge the pending queue and the base queue.
  5717. var baseFirst = baseQueue.next;
  5718. var pendingFirst = pendingQueue.next;
  5719. baseQueue.next = pendingFirst;
  5720. pendingQueue.next = baseFirst;
  5721. }
  5722. baseQueue = pendingQueue;
  5723. queue.shared.pending = null; // TODO: Pass `current` as argument
  5724. var current = workInProgress.alternate;
  5725. if (current !== null) {
  5726. var currentQueue = current.updateQueue;
  5727. if (currentQueue !== null) {
  5728. currentQueue.baseQueue = pendingQueue;
  5729. }
  5730. }
  5731. } // These values may change as we process the queue.
  5732. if (baseQueue !== null) {
  5733. var first = baseQueue.next; // Iterate through the list of updates to compute the result.
  5734. var newState = queue.baseState;
  5735. var newExpirationTime = NoWork;
  5736. var newBaseState = null;
  5737. var newBaseQueueFirst = null;
  5738. var newBaseQueueLast = null;
  5739. if (first !== null) {
  5740. var update = first;
  5741. do {
  5742. var updateExpirationTime = update.expirationTime;
  5743. if (updateExpirationTime < renderExpirationTime) {
  5744. // Priority is insufficient. Skip this update. If this is the first
  5745. // skipped update, the previous update/state is the new base
  5746. // update/state.
  5747. var clone = {
  5748. expirationTime: update.expirationTime,
  5749. suspenseConfig: update.suspenseConfig,
  5750. tag: update.tag,
  5751. payload: update.payload,
  5752. callback: update.callback,
  5753. next: null
  5754. };
  5755. if (newBaseQueueLast === null) {
  5756. newBaseQueueFirst = newBaseQueueLast = clone;
  5757. newBaseState = newState;
  5758. } else {
  5759. newBaseQueueLast = newBaseQueueLast.next = clone;
  5760. } // Update the remaining priority in the queue.
  5761. if (updateExpirationTime > newExpirationTime) {
  5762. newExpirationTime = updateExpirationTime;
  5763. }
  5764. } else {
  5765. // This update does have sufficient priority.
  5766. if (newBaseQueueLast !== null) {
  5767. var _clone = {
  5768. expirationTime: Sync,
  5769. // This update is going to be committed so we never want uncommit it.
  5770. suspenseConfig: update.suspenseConfig,
  5771. tag: update.tag,
  5772. payload: update.payload,
  5773. callback: update.callback,
  5774. next: null
  5775. };
  5776. newBaseQueueLast = newBaseQueueLast.next = _clone;
  5777. } // Mark the event time of this update as relevant to this render pass.
  5778. // TODO: This should ideally use the true event time of this update rather than
  5779. // its priority which is a derived and not reverseable value.
  5780. // TODO: We should skip this update if it was already committed but currently
  5781. // we have no way of detecting the difference between a committed and suspended
  5782. // update here.
  5783. markRenderEventTimeAndConfig(
  5784. updateExpirationTime,
  5785. update.suspenseConfig
  5786. ); // Process this update.
  5787. newState = getStateFromUpdate(
  5788. workInProgress,
  5789. queue,
  5790. update,
  5791. newState,
  5792. props,
  5793. instance
  5794. );
  5795. var callback = update.callback;
  5796. if (callback !== null) {
  5797. workInProgress.effectTag |= Callback;
  5798. var effects = queue.effects;
  5799. if (effects === null) {
  5800. queue.effects = [update];
  5801. } else {
  5802. effects.push(update);
  5803. }
  5804. }
  5805. }
  5806. update = update.next;
  5807. if (update === null || update === first) {
  5808. pendingQueue = queue.shared.pending;
  5809. if (pendingQueue === null) {
  5810. break;
  5811. } else {
  5812. // An update was scheduled from inside a reducer. Add the new
  5813. // pending updates to the end of the list and keep processing.
  5814. update = baseQueue.next = pendingQueue.next;
  5815. pendingQueue.next = first;
  5816. queue.baseQueue = baseQueue = pendingQueue;
  5817. queue.shared.pending = null;
  5818. }
  5819. }
  5820. } while (true);
  5821. }
  5822. if (newBaseQueueLast === null) {
  5823. newBaseState = newState;
  5824. } else {
  5825. newBaseQueueLast.next = newBaseQueueFirst;
  5826. }
  5827. queue.baseState = newBaseState;
  5828. queue.baseQueue = newBaseQueueLast; // Set the remaining expiration time to be whatever is remaining in the queue.
  5829. // This should be fine because the only two other things that contribute to
  5830. // expiration time are props and context. We're already in the middle of the
  5831. // begin phase by the time we start processing the queue, so we've already
  5832. // dealt with the props. Context in components that specify
  5833. // shouldComponentUpdate is tricky; but we'll have to account for
  5834. // that regardless.
  5835. markUnprocessedUpdateTime(newExpirationTime);
  5836. workInProgress.expirationTime = newExpirationTime;
  5837. workInProgress.memoizedState = newState;
  5838. }
  5839. {
  5840. currentlyProcessingQueue = null;
  5841. }
  5842. }
  5843. function callCallback(callback, context) {
  5844. if (!(typeof callback === "function")) {
  5845. throw Error(
  5846. "Invalid argument passed as callback. Expected a function. Instead received: " +
  5847. callback
  5848. );
  5849. }
  5850. callback.call(context);
  5851. }
  5852. function resetHasForceUpdateBeforeProcessing() {
  5853. hasForceUpdate = false;
  5854. }
  5855. function checkHasForceUpdateAfterProcessing() {
  5856. return hasForceUpdate;
  5857. }
  5858. function commitUpdateQueue(finishedWork, finishedQueue, instance) {
  5859. // Commit the effects
  5860. var effects = finishedQueue.effects;
  5861. finishedQueue.effects = null;
  5862. if (effects !== null) {
  5863. for (var i = 0; i < effects.length; i++) {
  5864. var effect = effects[i];
  5865. var callback = effect.callback;
  5866. if (callback !== null) {
  5867. effect.callback = null;
  5868. callCallback(callback, instance);
  5869. }
  5870. }
  5871. }
  5872. }
  5873. var ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig;
  5874. function requestCurrentSuspenseConfig() {
  5875. return ReactCurrentBatchConfig.suspense;
  5876. }
  5877. var fakeInternalInstance = {};
  5878. var isArray = Array.isArray; // React.Component uses a shared frozen object by default.
  5879. // We'll use it to determine whether we need to initialize legacy refs.
  5880. var emptyRefsObject = new React.Component().refs;
  5881. var didWarnAboutStateAssignmentForComponent;
  5882. var didWarnAboutUninitializedState;
  5883. var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
  5884. var didWarnAboutLegacyLifecyclesAndDerivedState;
  5885. var didWarnAboutUndefinedDerivedState;
  5886. var warnOnUndefinedDerivedState;
  5887. var warnOnInvalidCallback;
  5888. var didWarnAboutDirectlyAssigningPropsToState;
  5889. var didWarnAboutContextTypeAndContextTypes;
  5890. var didWarnAboutInvalidateContextType;
  5891. {
  5892. didWarnAboutStateAssignmentForComponent = new Set();
  5893. didWarnAboutUninitializedState = new Set();
  5894. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
  5895. didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
  5896. didWarnAboutDirectlyAssigningPropsToState = new Set();
  5897. didWarnAboutUndefinedDerivedState = new Set();
  5898. didWarnAboutContextTypeAndContextTypes = new Set();
  5899. didWarnAboutInvalidateContextType = new Set();
  5900. var didWarnOnInvalidCallback = new Set();
  5901. warnOnInvalidCallback = function(callback, callerName) {
  5902. if (callback === null || typeof callback === "function") {
  5903. return;
  5904. }
  5905. var key = callerName + "_" + callback;
  5906. if (!didWarnOnInvalidCallback.has(key)) {
  5907. didWarnOnInvalidCallback.add(key);
  5908. error(
  5909. "%s(...): Expected the last optional `callback` argument to be a " +
  5910. "function. Instead received: %s.",
  5911. callerName,
  5912. callback
  5913. );
  5914. }
  5915. };
  5916. warnOnUndefinedDerivedState = function(type, partialState) {
  5917. if (partialState === undefined) {
  5918. var componentName = getComponentName(type) || "Component";
  5919. if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
  5920. didWarnAboutUndefinedDerivedState.add(componentName);
  5921. error(
  5922. "%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. " +
  5923. "You have returned undefined.",
  5924. componentName
  5925. );
  5926. }
  5927. }
  5928. }; // This is so gross but it's at least non-critical and can be removed if
  5929. // it causes problems. This is meant to give a nicer error message for
  5930. // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
  5931. // ...)) which otherwise throws a "_processChildContext is not a function"
  5932. // exception.
  5933. Object.defineProperty(fakeInternalInstance, "_processChildContext", {
  5934. enumerable: false,
  5935. value: function() {
  5936. {
  5937. throw Error(
  5938. "_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)."
  5939. );
  5940. }
  5941. }
  5942. });
  5943. Object.freeze(fakeInternalInstance);
  5944. }
  5945. function applyDerivedStateFromProps(
  5946. workInProgress,
  5947. ctor,
  5948. getDerivedStateFromProps,
  5949. nextProps
  5950. ) {
  5951. var prevState = workInProgress.memoizedState;
  5952. var partialState = getDerivedStateFromProps(nextProps, prevState);
  5953. {
  5954. warnOnUndefinedDerivedState(ctor, partialState);
  5955. } // Merge the partial state and the previous state.
  5956. var memoizedState =
  5957. partialState === null || partialState === undefined
  5958. ? prevState
  5959. : Object.assign({}, prevState, partialState);
  5960. workInProgress.memoizedState = memoizedState; // Once the update queue is empty, persist the derived state onto the
  5961. // base state.
  5962. if (workInProgress.expirationTime === NoWork) {
  5963. // Queue is always non-null for classes
  5964. var updateQueue = workInProgress.updateQueue;
  5965. updateQueue.baseState = memoizedState;
  5966. }
  5967. }
  5968. var classComponentUpdater = {
  5969. isMounted: isMounted,
  5970. enqueueSetState: function(inst, payload, callback) {
  5971. var fiber = get(inst);
  5972. var currentTime = requestCurrentTimeForUpdate();
  5973. var suspenseConfig = requestCurrentSuspenseConfig();
  5974. var expirationTime = computeExpirationForFiber(
  5975. currentTime,
  5976. fiber,
  5977. suspenseConfig
  5978. );
  5979. var update = createUpdate(expirationTime, suspenseConfig);
  5980. update.payload = payload;
  5981. if (callback !== undefined && callback !== null) {
  5982. {
  5983. warnOnInvalidCallback(callback, "setState");
  5984. }
  5985. update.callback = callback;
  5986. }
  5987. enqueueUpdate(fiber, update);
  5988. scheduleWork(fiber, expirationTime);
  5989. },
  5990. enqueueReplaceState: function(inst, payload, callback) {
  5991. var fiber = get(inst);
  5992. var currentTime = requestCurrentTimeForUpdate();
  5993. var suspenseConfig = requestCurrentSuspenseConfig();
  5994. var expirationTime = computeExpirationForFiber(
  5995. currentTime,
  5996. fiber,
  5997. suspenseConfig
  5998. );
  5999. var update = createUpdate(expirationTime, suspenseConfig);
  6000. update.tag = ReplaceState;
  6001. update.payload = payload;
  6002. if (callback !== undefined && callback !== null) {
  6003. {
  6004. warnOnInvalidCallback(callback, "replaceState");
  6005. }
  6006. update.callback = callback;
  6007. }
  6008. enqueueUpdate(fiber, update);
  6009. scheduleWork(fiber, expirationTime);
  6010. },
  6011. enqueueForceUpdate: function(inst, callback) {
  6012. var fiber = get(inst);
  6013. var currentTime = requestCurrentTimeForUpdate();
  6014. var suspenseConfig = requestCurrentSuspenseConfig();
  6015. var expirationTime = computeExpirationForFiber(
  6016. currentTime,
  6017. fiber,
  6018. suspenseConfig
  6019. );
  6020. var update = createUpdate(expirationTime, suspenseConfig);
  6021. update.tag = ForceUpdate;
  6022. if (callback !== undefined && callback !== null) {
  6023. {
  6024. warnOnInvalidCallback(callback, "forceUpdate");
  6025. }
  6026. update.callback = callback;
  6027. }
  6028. enqueueUpdate(fiber, update);
  6029. scheduleWork(fiber, expirationTime);
  6030. }
  6031. };
  6032. function checkShouldComponentUpdate(
  6033. workInProgress,
  6034. ctor,
  6035. oldProps,
  6036. newProps,
  6037. oldState,
  6038. newState,
  6039. nextContext
  6040. ) {
  6041. var instance = workInProgress.stateNode;
  6042. if (typeof instance.shouldComponentUpdate === "function") {
  6043. startPhaseTimer(workInProgress, "shouldComponentUpdate");
  6044. var shouldUpdate = instance.shouldComponentUpdate(
  6045. newProps,
  6046. newState,
  6047. nextContext
  6048. );
  6049. stopPhaseTimer();
  6050. {
  6051. if (shouldUpdate === undefined) {
  6052. error(
  6053. "%s.shouldComponentUpdate(): Returned undefined instead of a " +
  6054. "boolean value. Make sure to return true or false.",
  6055. getComponentName(ctor) || "Component"
  6056. );
  6057. }
  6058. }
  6059. return shouldUpdate;
  6060. }
  6061. if (ctor.prototype && ctor.prototype.isPureReactComponent) {
  6062. return (
  6063. !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState)
  6064. );
  6065. }
  6066. return true;
  6067. }
  6068. function checkClassInstance(workInProgress, ctor, newProps) {
  6069. var instance = workInProgress.stateNode;
  6070. {
  6071. var name = getComponentName(ctor) || "Component";
  6072. var renderPresent = instance.render;
  6073. if (!renderPresent) {
  6074. if (ctor.prototype && typeof ctor.prototype.render === "function") {
  6075. error(
  6076. "%s(...): No `render` method found on the returned component " +
  6077. "instance: did you accidentally return an object from the constructor?",
  6078. name
  6079. );
  6080. } else {
  6081. error(
  6082. "%s(...): No `render` method found on the returned component " +
  6083. "instance: you may have forgotten to define `render`.",
  6084. name
  6085. );
  6086. }
  6087. }
  6088. if (
  6089. instance.getInitialState &&
  6090. !instance.getInitialState.isReactClassApproved &&
  6091. !instance.state
  6092. ) {
  6093. error(
  6094. "getInitialState was defined on %s, a plain JavaScript class. " +
  6095. "This is only supported for classes created using React.createClass. " +
  6096. "Did you mean to define a state property instead?",
  6097. name
  6098. );
  6099. }
  6100. if (
  6101. instance.getDefaultProps &&
  6102. !instance.getDefaultProps.isReactClassApproved
  6103. ) {
  6104. error(
  6105. "getDefaultProps was defined on %s, a plain JavaScript class. " +
  6106. "This is only supported for classes created using React.createClass. " +
  6107. "Use a static property to define defaultProps instead.",
  6108. name
  6109. );
  6110. }
  6111. if (instance.propTypes) {
  6112. error(
  6113. "propTypes was defined as an instance property on %s. Use a static " +
  6114. "property to define propTypes instead.",
  6115. name
  6116. );
  6117. }
  6118. if (instance.contextType) {
  6119. error(
  6120. "contextType was defined as an instance property on %s. Use a static " +
  6121. "property to define contextType instead.",
  6122. name
  6123. );
  6124. }
  6125. {
  6126. if (instance.contextTypes) {
  6127. error(
  6128. "contextTypes was defined as an instance property on %s. Use a static " +
  6129. "property to define contextTypes instead.",
  6130. name
  6131. );
  6132. }
  6133. if (
  6134. ctor.contextType &&
  6135. ctor.contextTypes &&
  6136. !didWarnAboutContextTypeAndContextTypes.has(ctor)
  6137. ) {
  6138. didWarnAboutContextTypeAndContextTypes.add(ctor);
  6139. error(
  6140. "%s declares both contextTypes and contextType static properties. " +
  6141. "The legacy contextTypes property will be ignored.",
  6142. name
  6143. );
  6144. }
  6145. }
  6146. if (typeof instance.componentShouldUpdate === "function") {
  6147. error(
  6148. "%s has a method called " +
  6149. "componentShouldUpdate(). Did you mean shouldComponentUpdate()? " +
  6150. "The name is phrased as a question because the function is " +
  6151. "expected to return a value.",
  6152. name
  6153. );
  6154. }
  6155. if (
  6156. ctor.prototype &&
  6157. ctor.prototype.isPureReactComponent &&
  6158. typeof instance.shouldComponentUpdate !== "undefined"
  6159. ) {
  6160. error(
  6161. "%s has a method called shouldComponentUpdate(). " +
  6162. "shouldComponentUpdate should not be used when extending React.PureComponent. " +
  6163. "Please extend React.Component if shouldComponentUpdate is used.",
  6164. getComponentName(ctor) || "A pure component"
  6165. );
  6166. }
  6167. if (typeof instance.componentDidUnmount === "function") {
  6168. error(
  6169. "%s has a method called " +
  6170. "componentDidUnmount(). But there is no such lifecycle method. " +
  6171. "Did you mean componentWillUnmount()?",
  6172. name
  6173. );
  6174. }
  6175. if (typeof instance.componentDidReceiveProps === "function") {
  6176. error(
  6177. "%s has a method called " +
  6178. "componentDidReceiveProps(). But there is no such lifecycle method. " +
  6179. "If you meant to update the state in response to changing props, " +
  6180. "use componentWillReceiveProps(). If you meant to fetch data or " +
  6181. "run side-effects or mutations after React has updated the UI, use componentDidUpdate().",
  6182. name
  6183. );
  6184. }
  6185. if (typeof instance.componentWillRecieveProps === "function") {
  6186. error(
  6187. "%s has a method called " +
  6188. "componentWillRecieveProps(). Did you mean componentWillReceiveProps()?",
  6189. name
  6190. );
  6191. }
  6192. if (typeof instance.UNSAFE_componentWillRecieveProps === "function") {
  6193. error(
  6194. "%s has a method called " +
  6195. "UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?",
  6196. name
  6197. );
  6198. }
  6199. var hasMutatedProps = instance.props !== newProps;
  6200. if (instance.props !== undefined && hasMutatedProps) {
  6201. error(
  6202. "%s(...): When calling super() in `%s`, make sure to pass " +
  6203. "up the same props that your component's constructor was passed.",
  6204. name,
  6205. name
  6206. );
  6207. }
  6208. if (instance.defaultProps) {
  6209. error(
  6210. "Setting defaultProps as an instance property on %s is not supported and will be ignored." +
  6211. " Instead, define defaultProps as a static property on %s.",
  6212. name,
  6213. name
  6214. );
  6215. }
  6216. if (
  6217. typeof instance.getSnapshotBeforeUpdate === "function" &&
  6218. typeof instance.componentDidUpdate !== "function" &&
  6219. !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)
  6220. ) {
  6221. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
  6222. error(
  6223. "%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). " +
  6224. "This component defines getSnapshotBeforeUpdate() only.",
  6225. getComponentName(ctor)
  6226. );
  6227. }
  6228. if (typeof instance.getDerivedStateFromProps === "function") {
  6229. error(
  6230. "%s: getDerivedStateFromProps() is defined as an instance method " +
  6231. "and will be ignored. Instead, declare it as a static method.",
  6232. name
  6233. );
  6234. }
  6235. if (typeof instance.getDerivedStateFromError === "function") {
  6236. error(
  6237. "%s: getDerivedStateFromError() is defined as an instance method " +
  6238. "and will be ignored. Instead, declare it as a static method.",
  6239. name
  6240. );
  6241. }
  6242. if (typeof ctor.getSnapshotBeforeUpdate === "function") {
  6243. error(
  6244. "%s: getSnapshotBeforeUpdate() is defined as a static method " +
  6245. "and will be ignored. Instead, declare it as an instance method.",
  6246. name
  6247. );
  6248. }
  6249. var _state = instance.state;
  6250. if (_state && (typeof _state !== "object" || isArray(_state))) {
  6251. error("%s.state: must be set to an object or null", name);
  6252. }
  6253. if (
  6254. typeof instance.getChildContext === "function" &&
  6255. typeof ctor.childContextTypes !== "object"
  6256. ) {
  6257. error(
  6258. "%s.getChildContext(): childContextTypes must be defined in order to " +
  6259. "use getChildContext().",
  6260. name
  6261. );
  6262. }
  6263. }
  6264. }
  6265. function adoptClassInstance(workInProgress, instance) {
  6266. instance.updater = classComponentUpdater;
  6267. workInProgress.stateNode = instance; // The instance needs access to the fiber so that it can schedule updates
  6268. set(instance, workInProgress);
  6269. {
  6270. instance._reactInternalInstance = fakeInternalInstance;
  6271. }
  6272. }
  6273. function constructClassInstance(workInProgress, ctor, props) {
  6274. var isLegacyContextConsumer = false;
  6275. var unmaskedContext = emptyContextObject;
  6276. var context = emptyContextObject;
  6277. var contextType = ctor.contextType;
  6278. {
  6279. if ("contextType" in ctor) {
  6280. var isValid = // Allow null for conditional declaration
  6281. contextType === null ||
  6282. (contextType !== undefined &&
  6283. contextType.$$typeof === REACT_CONTEXT_TYPE &&
  6284. contextType._context === undefined); // Not a <Context.Consumer>
  6285. if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
  6286. didWarnAboutInvalidateContextType.add(ctor);
  6287. var addendum = "";
  6288. if (contextType === undefined) {
  6289. addendum =
  6290. " However, it is set to undefined. " +
  6291. "This can be caused by a typo or by mixing up named and default imports. " +
  6292. "This can also happen due to a circular dependency, so " +
  6293. "try moving the createContext() call to a separate file.";
  6294. } else if (typeof contextType !== "object") {
  6295. addendum = " However, it is set to a " + typeof contextType + ".";
  6296. } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
  6297. addendum = " Did you accidentally pass the Context.Provider instead?";
  6298. } else if (contextType._context !== undefined) {
  6299. // <Context.Consumer>
  6300. addendum = " Did you accidentally pass the Context.Consumer instead?";
  6301. } else {
  6302. addendum =
  6303. " However, it is set to an object with keys {" +
  6304. Object.keys(contextType).join(", ") +
  6305. "}.";
  6306. }
  6307. error(
  6308. "%s defines an invalid contextType. " +
  6309. "contextType should point to the Context object returned by React.createContext().%s",
  6310. getComponentName(ctor) || "Component",
  6311. addendum
  6312. );
  6313. }
  6314. }
  6315. }
  6316. if (typeof contextType === "object" && contextType !== null) {
  6317. context = readContext(contextType);
  6318. } else {
  6319. unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  6320. var contextTypes = ctor.contextTypes;
  6321. isLegacyContextConsumer =
  6322. contextTypes !== null && contextTypes !== undefined;
  6323. context = isLegacyContextConsumer
  6324. ? getMaskedContext(workInProgress, unmaskedContext)
  6325. : emptyContextObject;
  6326. } // Instantiate twice to help detect side-effects.
  6327. var instance = new ctor(props, context);
  6328. var state = (workInProgress.memoizedState =
  6329. instance.state !== null && instance.state !== undefined
  6330. ? instance.state
  6331. : null);
  6332. adoptClassInstance(workInProgress, instance);
  6333. {
  6334. if (typeof ctor.getDerivedStateFromProps === "function" && state === null) {
  6335. var componentName = getComponentName(ctor) || "Component";
  6336. if (!didWarnAboutUninitializedState.has(componentName)) {
  6337. didWarnAboutUninitializedState.add(componentName);
  6338. error(
  6339. "`%s` uses `getDerivedStateFromProps` but its initial state is " +
  6340. "%s. This is not recommended. Instead, define the initial state by " +
  6341. "assigning an object to `this.state` in the constructor of `%s`. " +
  6342. "This ensures that `getDerivedStateFromProps` arguments have a consistent shape.",
  6343. componentName,
  6344. instance.state === null ? "null" : "undefined",
  6345. componentName
  6346. );
  6347. }
  6348. } // If new component APIs are defined, "unsafe" lifecycles won't be called.
  6349. // Warn about these lifecycles if they are present.
  6350. // Don't warn about react-lifecycles-compat polyfilled methods though.
  6351. if (
  6352. typeof ctor.getDerivedStateFromProps === "function" ||
  6353. typeof instance.getSnapshotBeforeUpdate === "function"
  6354. ) {
  6355. var foundWillMountName = null;
  6356. var foundWillReceivePropsName = null;
  6357. var foundWillUpdateName = null;
  6358. if (
  6359. typeof instance.componentWillMount === "function" &&
  6360. instance.componentWillMount.__suppressDeprecationWarning !== true
  6361. ) {
  6362. foundWillMountName = "componentWillMount";
  6363. } else if (typeof instance.UNSAFE_componentWillMount === "function") {
  6364. foundWillMountName = "UNSAFE_componentWillMount";
  6365. }
  6366. if (
  6367. typeof instance.componentWillReceiveProps === "function" &&
  6368. instance.componentWillReceiveProps.__suppressDeprecationWarning !== true
  6369. ) {
  6370. foundWillReceivePropsName = "componentWillReceiveProps";
  6371. } else if (
  6372. typeof instance.UNSAFE_componentWillReceiveProps === "function"
  6373. ) {
  6374. foundWillReceivePropsName = "UNSAFE_componentWillReceiveProps";
  6375. }
  6376. if (
  6377. typeof instance.componentWillUpdate === "function" &&
  6378. instance.componentWillUpdate.__suppressDeprecationWarning !== true
  6379. ) {
  6380. foundWillUpdateName = "componentWillUpdate";
  6381. } else if (typeof instance.UNSAFE_componentWillUpdate === "function") {
  6382. foundWillUpdateName = "UNSAFE_componentWillUpdate";
  6383. }
  6384. if (
  6385. foundWillMountName !== null ||
  6386. foundWillReceivePropsName !== null ||
  6387. foundWillUpdateName !== null
  6388. ) {
  6389. var _componentName = getComponentName(ctor) || "Component";
  6390. var newApiName =
  6391. typeof ctor.getDerivedStateFromProps === "function"
  6392. ? "getDerivedStateFromProps()"
  6393. : "getSnapshotBeforeUpdate()";
  6394. if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
  6395. didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
  6396. error(
  6397. "Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n" +
  6398. "%s uses %s but also contains the following legacy lifecycles:%s%s%s\n\n" +
  6399. "The above lifecycles should be removed. Learn more about this warning here:\n" +
  6400. "https://fb.me/react-unsafe-component-lifecycles",
  6401. _componentName,
  6402. newApiName,
  6403. foundWillMountName !== null ? "\n " + foundWillMountName : "",
  6404. foundWillReceivePropsName !== null
  6405. ? "\n " + foundWillReceivePropsName
  6406. : "",
  6407. foundWillUpdateName !== null ? "\n " + foundWillUpdateName : ""
  6408. );
  6409. }
  6410. }
  6411. }
  6412. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  6413. // ReactFiberContext usually updates this cache but can't for newly-created instances.
  6414. if (isLegacyContextConsumer) {
  6415. cacheContext(workInProgress, unmaskedContext, context);
  6416. }
  6417. return instance;
  6418. }
  6419. function callComponentWillMount(workInProgress, instance) {
  6420. startPhaseTimer(workInProgress, "componentWillMount");
  6421. var oldState = instance.state;
  6422. if (typeof instance.componentWillMount === "function") {
  6423. instance.componentWillMount();
  6424. }
  6425. if (typeof instance.UNSAFE_componentWillMount === "function") {
  6426. instance.UNSAFE_componentWillMount();
  6427. }
  6428. stopPhaseTimer();
  6429. if (oldState !== instance.state) {
  6430. {
  6431. error(
  6432. "%s.componentWillMount(): Assigning directly to this.state is " +
  6433. "deprecated (except inside a component's " +
  6434. "constructor). Use setState instead.",
  6435. getComponentName(workInProgress.type) || "Component"
  6436. );
  6437. }
  6438. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  6439. }
  6440. }
  6441. function callComponentWillReceiveProps(
  6442. workInProgress,
  6443. instance,
  6444. newProps,
  6445. nextContext
  6446. ) {
  6447. var oldState = instance.state;
  6448. startPhaseTimer(workInProgress, "componentWillReceiveProps");
  6449. if (typeof instance.componentWillReceiveProps === "function") {
  6450. instance.componentWillReceiveProps(newProps, nextContext);
  6451. }
  6452. if (typeof instance.UNSAFE_componentWillReceiveProps === "function") {
  6453. instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
  6454. }
  6455. stopPhaseTimer();
  6456. if (instance.state !== oldState) {
  6457. {
  6458. var componentName = getComponentName(workInProgress.type) || "Component";
  6459. if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
  6460. didWarnAboutStateAssignmentForComponent.add(componentName);
  6461. error(
  6462. "%s.componentWillReceiveProps(): Assigning directly to " +
  6463. "this.state is deprecated (except inside a component's " +
  6464. "constructor). Use setState instead.",
  6465. componentName
  6466. );
  6467. }
  6468. }
  6469. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  6470. }
  6471. } // Invokes the mount life-cycles on a previously never rendered instance.
  6472. function mountClassInstance(
  6473. workInProgress,
  6474. ctor,
  6475. newProps,
  6476. renderExpirationTime
  6477. ) {
  6478. {
  6479. checkClassInstance(workInProgress, ctor, newProps);
  6480. }
  6481. var instance = workInProgress.stateNode;
  6482. instance.props = newProps;
  6483. instance.state = workInProgress.memoizedState;
  6484. instance.refs = emptyRefsObject;
  6485. initializeUpdateQueue(workInProgress);
  6486. var contextType = ctor.contextType;
  6487. if (typeof contextType === "object" && contextType !== null) {
  6488. instance.context = readContext(contextType);
  6489. } else {
  6490. var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  6491. instance.context = getMaskedContext(workInProgress, unmaskedContext);
  6492. }
  6493. {
  6494. if (instance.state === newProps) {
  6495. var componentName = getComponentName(ctor) || "Component";
  6496. if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
  6497. didWarnAboutDirectlyAssigningPropsToState.add(componentName);
  6498. error(
  6499. "%s: It is not recommended to assign props directly to state " +
  6500. "because updates to props won't be reflected in state. " +
  6501. "In most cases, it is better to use props directly.",
  6502. componentName
  6503. );
  6504. }
  6505. }
  6506. if (workInProgress.mode & StrictMode) {
  6507. ReactStrictModeWarnings.recordLegacyContextWarning(
  6508. workInProgress,
  6509. instance
  6510. );
  6511. }
  6512. {
  6513. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(
  6514. workInProgress,
  6515. instance
  6516. );
  6517. }
  6518. }
  6519. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  6520. instance.state = workInProgress.memoizedState;
  6521. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  6522. if (typeof getDerivedStateFromProps === "function") {
  6523. applyDerivedStateFromProps(
  6524. workInProgress,
  6525. ctor,
  6526. getDerivedStateFromProps,
  6527. newProps
  6528. );
  6529. instance.state = workInProgress.memoizedState;
  6530. } // In order to support react-lifecycles-compat polyfilled components,
  6531. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6532. if (
  6533. typeof ctor.getDerivedStateFromProps !== "function" &&
  6534. typeof instance.getSnapshotBeforeUpdate !== "function" &&
  6535. (typeof instance.UNSAFE_componentWillMount === "function" ||
  6536. typeof instance.componentWillMount === "function")
  6537. ) {
  6538. callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's
  6539. // process them now.
  6540. processUpdateQueue(
  6541. workInProgress,
  6542. newProps,
  6543. instance,
  6544. renderExpirationTime
  6545. );
  6546. instance.state = workInProgress.memoizedState;
  6547. }
  6548. if (typeof instance.componentDidMount === "function") {
  6549. workInProgress.effectTag |= Update;
  6550. }
  6551. }
  6552. function resumeMountClassInstance(
  6553. workInProgress,
  6554. ctor,
  6555. newProps,
  6556. renderExpirationTime
  6557. ) {
  6558. var instance = workInProgress.stateNode;
  6559. var oldProps = workInProgress.memoizedProps;
  6560. instance.props = oldProps;
  6561. var oldContext = instance.context;
  6562. var contextType = ctor.contextType;
  6563. var nextContext = emptyContextObject;
  6564. if (typeof contextType === "object" && contextType !== null) {
  6565. nextContext = readContext(contextType);
  6566. } else {
  6567. var nextLegacyUnmaskedContext = getUnmaskedContext(
  6568. workInProgress,
  6569. ctor,
  6570. true
  6571. );
  6572. nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
  6573. }
  6574. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  6575. var hasNewLifecycles =
  6576. typeof getDerivedStateFromProps === "function" ||
  6577. typeof instance.getSnapshotBeforeUpdate === "function"; // Note: During these life-cycles, instance.props/instance.state are what
  6578. // ever the previously attempted to render - not the "current". However,
  6579. // during componentDidUpdate we pass the "current" props.
  6580. // In order to support react-lifecycles-compat polyfilled components,
  6581. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6582. if (
  6583. !hasNewLifecycles &&
  6584. (typeof instance.UNSAFE_componentWillReceiveProps === "function" ||
  6585. typeof instance.componentWillReceiveProps === "function")
  6586. ) {
  6587. if (oldProps !== newProps || oldContext !== nextContext) {
  6588. callComponentWillReceiveProps(
  6589. workInProgress,
  6590. instance,
  6591. newProps,
  6592. nextContext
  6593. );
  6594. }
  6595. }
  6596. resetHasForceUpdateBeforeProcessing();
  6597. var oldState = workInProgress.memoizedState;
  6598. var newState = (instance.state = oldState);
  6599. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  6600. newState = workInProgress.memoizedState;
  6601. if (
  6602. oldProps === newProps &&
  6603. oldState === newState &&
  6604. !hasContextChanged() &&
  6605. !checkHasForceUpdateAfterProcessing()
  6606. ) {
  6607. // If an update was already in progress, we should schedule an Update
  6608. // effect even though we're bailing out, so that cWU/cDU are called.
  6609. if (typeof instance.componentDidMount === "function") {
  6610. workInProgress.effectTag |= Update;
  6611. }
  6612. return false;
  6613. }
  6614. if (typeof getDerivedStateFromProps === "function") {
  6615. applyDerivedStateFromProps(
  6616. workInProgress,
  6617. ctor,
  6618. getDerivedStateFromProps,
  6619. newProps
  6620. );
  6621. newState = workInProgress.memoizedState;
  6622. }
  6623. var shouldUpdate =
  6624. checkHasForceUpdateAfterProcessing() ||
  6625. checkShouldComponentUpdate(
  6626. workInProgress,
  6627. ctor,
  6628. oldProps,
  6629. newProps,
  6630. oldState,
  6631. newState,
  6632. nextContext
  6633. );
  6634. if (shouldUpdate) {
  6635. // In order to support react-lifecycles-compat polyfilled components,
  6636. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6637. if (
  6638. !hasNewLifecycles &&
  6639. (typeof instance.UNSAFE_componentWillMount === "function" ||
  6640. typeof instance.componentWillMount === "function")
  6641. ) {
  6642. startPhaseTimer(workInProgress, "componentWillMount");
  6643. if (typeof instance.componentWillMount === "function") {
  6644. instance.componentWillMount();
  6645. }
  6646. if (typeof instance.UNSAFE_componentWillMount === "function") {
  6647. instance.UNSAFE_componentWillMount();
  6648. }
  6649. stopPhaseTimer();
  6650. }
  6651. if (typeof instance.componentDidMount === "function") {
  6652. workInProgress.effectTag |= Update;
  6653. }
  6654. } else {
  6655. // If an update was already in progress, we should schedule an Update
  6656. // effect even though we're bailing out, so that cWU/cDU are called.
  6657. if (typeof instance.componentDidMount === "function") {
  6658. workInProgress.effectTag |= Update;
  6659. } // If shouldComponentUpdate returned false, we should still update the
  6660. // memoized state to indicate that this work can be reused.
  6661. workInProgress.memoizedProps = newProps;
  6662. workInProgress.memoizedState = newState;
  6663. } // Update the existing instance's state, props, and context pointers even
  6664. // if shouldComponentUpdate returns false.
  6665. instance.props = newProps;
  6666. instance.state = newState;
  6667. instance.context = nextContext;
  6668. return shouldUpdate;
  6669. } // Invokes the update life-cycles and returns false if it shouldn't rerender.
  6670. function updateClassInstance(
  6671. current,
  6672. workInProgress,
  6673. ctor,
  6674. newProps,
  6675. renderExpirationTime
  6676. ) {
  6677. var instance = workInProgress.stateNode;
  6678. cloneUpdateQueue(current, workInProgress);
  6679. var oldProps = workInProgress.memoizedProps;
  6680. instance.props =
  6681. workInProgress.type === workInProgress.elementType
  6682. ? oldProps
  6683. : resolveDefaultProps(workInProgress.type, oldProps);
  6684. var oldContext = instance.context;
  6685. var contextType = ctor.contextType;
  6686. var nextContext = emptyContextObject;
  6687. if (typeof contextType === "object" && contextType !== null) {
  6688. nextContext = readContext(contextType);
  6689. } else {
  6690. var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  6691. nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
  6692. }
  6693. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  6694. var hasNewLifecycles =
  6695. typeof getDerivedStateFromProps === "function" ||
  6696. typeof instance.getSnapshotBeforeUpdate === "function"; // Note: During these life-cycles, instance.props/instance.state are what
  6697. // ever the previously attempted to render - not the "current". However,
  6698. // during componentDidUpdate we pass the "current" props.
  6699. // In order to support react-lifecycles-compat polyfilled components,
  6700. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6701. if (
  6702. !hasNewLifecycles &&
  6703. (typeof instance.UNSAFE_componentWillReceiveProps === "function" ||
  6704. typeof instance.componentWillReceiveProps === "function")
  6705. ) {
  6706. if (oldProps !== newProps || oldContext !== nextContext) {
  6707. callComponentWillReceiveProps(
  6708. workInProgress,
  6709. instance,
  6710. newProps,
  6711. nextContext
  6712. );
  6713. }
  6714. }
  6715. resetHasForceUpdateBeforeProcessing();
  6716. var oldState = workInProgress.memoizedState;
  6717. var newState = (instance.state = oldState);
  6718. processUpdateQueue(workInProgress, newProps, instance, renderExpirationTime);
  6719. newState = workInProgress.memoizedState;
  6720. if (
  6721. oldProps === newProps &&
  6722. oldState === newState &&
  6723. !hasContextChanged() &&
  6724. !checkHasForceUpdateAfterProcessing()
  6725. ) {
  6726. // If an update was already in progress, we should schedule an Update
  6727. // effect even though we're bailing out, so that cWU/cDU are called.
  6728. if (typeof instance.componentDidUpdate === "function") {
  6729. if (
  6730. oldProps !== current.memoizedProps ||
  6731. oldState !== current.memoizedState
  6732. ) {
  6733. workInProgress.effectTag |= Update;
  6734. }
  6735. }
  6736. if (typeof instance.getSnapshotBeforeUpdate === "function") {
  6737. if (
  6738. oldProps !== current.memoizedProps ||
  6739. oldState !== current.memoizedState
  6740. ) {
  6741. workInProgress.effectTag |= Snapshot;
  6742. }
  6743. }
  6744. return false;
  6745. }
  6746. if (typeof getDerivedStateFromProps === "function") {
  6747. applyDerivedStateFromProps(
  6748. workInProgress,
  6749. ctor,
  6750. getDerivedStateFromProps,
  6751. newProps
  6752. );
  6753. newState = workInProgress.memoizedState;
  6754. }
  6755. var shouldUpdate =
  6756. checkHasForceUpdateAfterProcessing() ||
  6757. checkShouldComponentUpdate(
  6758. workInProgress,
  6759. ctor,
  6760. oldProps,
  6761. newProps,
  6762. oldState,
  6763. newState,
  6764. nextContext
  6765. );
  6766. if (shouldUpdate) {
  6767. // In order to support react-lifecycles-compat polyfilled components,
  6768. // Unsafe lifecycles should not be invoked for components using the new APIs.
  6769. if (
  6770. !hasNewLifecycles &&
  6771. (typeof instance.UNSAFE_componentWillUpdate === "function" ||
  6772. typeof instance.componentWillUpdate === "function")
  6773. ) {
  6774. startPhaseTimer(workInProgress, "componentWillUpdate");
  6775. if (typeof instance.componentWillUpdate === "function") {
  6776. instance.componentWillUpdate(newProps, newState, nextContext);
  6777. }
  6778. if (typeof instance.UNSAFE_componentWillUpdate === "function") {
  6779. instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
  6780. }
  6781. stopPhaseTimer();
  6782. }
  6783. if (typeof instance.componentDidUpdate === "function") {
  6784. workInProgress.effectTag |= Update;
  6785. }
  6786. if (typeof instance.getSnapshotBeforeUpdate === "function") {
  6787. workInProgress.effectTag |= Snapshot;
  6788. }
  6789. } else {
  6790. // If an update was already in progress, we should schedule an Update
  6791. // effect even though we're bailing out, so that cWU/cDU are called.
  6792. if (typeof instance.componentDidUpdate === "function") {
  6793. if (
  6794. oldProps !== current.memoizedProps ||
  6795. oldState !== current.memoizedState
  6796. ) {
  6797. workInProgress.effectTag |= Update;
  6798. }
  6799. }
  6800. if (typeof instance.getSnapshotBeforeUpdate === "function") {
  6801. if (
  6802. oldProps !== current.memoizedProps ||
  6803. oldState !== current.memoizedState
  6804. ) {
  6805. workInProgress.effectTag |= Snapshot;
  6806. }
  6807. } // If shouldComponentUpdate returned false, we should still update the
  6808. // memoized props/state to indicate that this work can be reused.
  6809. workInProgress.memoizedProps = newProps;
  6810. workInProgress.memoizedState = newState;
  6811. } // Update the existing instance's state, props, and context pointers even
  6812. // if shouldComponentUpdate returns false.
  6813. instance.props = newProps;
  6814. instance.state = newState;
  6815. instance.context = nextContext;
  6816. return shouldUpdate;
  6817. }
  6818. var didWarnAboutMaps;
  6819. var didWarnAboutGenerators;
  6820. var didWarnAboutStringRefs;
  6821. var ownerHasKeyUseWarning;
  6822. var ownerHasFunctionTypeWarning;
  6823. var warnForMissingKey = function(child) {};
  6824. {
  6825. didWarnAboutMaps = false;
  6826. didWarnAboutGenerators = false;
  6827. didWarnAboutStringRefs = {};
  6828. /**
  6829. * Warn if there's no key explicitly set on dynamic arrays of children or
  6830. * object keys are not valid. This allows us to keep track of children between
  6831. * updates.
  6832. */
  6833. ownerHasKeyUseWarning = {};
  6834. ownerHasFunctionTypeWarning = {};
  6835. warnForMissingKey = function(child) {
  6836. if (child === null || typeof child !== "object") {
  6837. return;
  6838. }
  6839. if (!child._store || child._store.validated || child.key != null) {
  6840. return;
  6841. }
  6842. if (!(typeof child._store === "object")) {
  6843. throw Error(
  6844. "React Component in warnForMissingKey should have a _store. This error is likely caused by a bug in React. Please file an issue."
  6845. );
  6846. }
  6847. child._store.validated = true;
  6848. var currentComponentErrorInfo =
  6849. "Each child in a list should have a unique " +
  6850. '"key" prop. See https://fb.me/react-warning-keys for ' +
  6851. "more information." +
  6852. getCurrentFiberStackInDev();
  6853. if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
  6854. return;
  6855. }
  6856. ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
  6857. error(
  6858. "Each child in a list should have a unique " +
  6859. '"key" prop. See https://fb.me/react-warning-keys for ' +
  6860. "more information."
  6861. );
  6862. };
  6863. }
  6864. var isArray$1 = Array.isArray;
  6865. function coerceRef(returnFiber, current, element) {
  6866. var mixedRef = element.ref;
  6867. if (
  6868. mixedRef !== null &&
  6869. typeof mixedRef !== "function" &&
  6870. typeof mixedRef !== "object"
  6871. ) {
  6872. {
  6873. // TODO: Clean this up once we turn on the string ref warning for
  6874. // everyone, because the strict mode case will no longer be relevant
  6875. if (
  6876. (returnFiber.mode & StrictMode || warnAboutStringRefs) && // We warn in ReactElement.js if owner and self are equal for string refs
  6877. // because these cannot be automatically converted to an arrow function
  6878. // using a codemod. Therefore, we don't have to warn about string refs again.
  6879. !(
  6880. element._owner &&
  6881. element._self &&
  6882. element._owner.stateNode !== element._self
  6883. )
  6884. ) {
  6885. var componentName = getComponentName(returnFiber.type) || "Component";
  6886. if (!didWarnAboutStringRefs[componentName]) {
  6887. {
  6888. error(
  6889. 'A string ref, "%s", has been found within a strict mode tree. ' +
  6890. "String refs are a source of potential bugs and should be avoided. " +
  6891. "We recommend using useRef() or createRef() instead. " +
  6892. "Learn more about using refs safely here: " +
  6893. "https://fb.me/react-strict-mode-string-ref%s",
  6894. mixedRef,
  6895. getStackByFiberInDevAndProd(returnFiber)
  6896. );
  6897. }
  6898. didWarnAboutStringRefs[componentName] = true;
  6899. }
  6900. }
  6901. }
  6902. if (element._owner) {
  6903. var owner = element._owner;
  6904. var inst;
  6905. if (owner) {
  6906. var ownerFiber = owner;
  6907. if (!(ownerFiber.tag === ClassComponent)) {
  6908. throw Error(
  6909. "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"
  6910. );
  6911. }
  6912. inst = ownerFiber.stateNode;
  6913. }
  6914. if (!inst) {
  6915. throw Error(
  6916. "Missing owner for string ref " +
  6917. mixedRef +
  6918. ". This error is likely caused by a bug in React. Please file an issue."
  6919. );
  6920. }
  6921. var stringRef = "" + mixedRef; // Check if previous string ref matches new string ref
  6922. if (
  6923. current !== null &&
  6924. current.ref !== null &&
  6925. typeof current.ref === "function" &&
  6926. current.ref._stringRef === stringRef
  6927. ) {
  6928. return current.ref;
  6929. }
  6930. var ref = function(value) {
  6931. var refs = inst.refs;
  6932. if (refs === emptyRefsObject) {
  6933. // This is a lazy pooled frozen object, so we need to initialize.
  6934. refs = inst.refs = {};
  6935. }
  6936. if (value === null) {
  6937. delete refs[stringRef];
  6938. } else {
  6939. refs[stringRef] = value;
  6940. }
  6941. };
  6942. ref._stringRef = stringRef;
  6943. return ref;
  6944. } else {
  6945. if (!(typeof mixedRef === "string")) {
  6946. throw Error(
  6947. "Expected ref to be a function, a string, an object returned by React.createRef(), or null."
  6948. );
  6949. }
  6950. if (!element._owner) {
  6951. throw Error(
  6952. "Element ref was specified as a string (" +
  6953. mixedRef +
  6954. ") 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."
  6955. );
  6956. }
  6957. }
  6958. }
  6959. return mixedRef;
  6960. }
  6961. function throwOnInvalidObjectType(returnFiber, newChild) {
  6962. if (returnFiber.type !== "textarea") {
  6963. var addendum = "";
  6964. {
  6965. addendum =
  6966. " If you meant to render a collection of children, use an array " +
  6967. "instead." +
  6968. getCurrentFiberStackInDev();
  6969. }
  6970. {
  6971. throw Error(
  6972. "Objects are not valid as a React child (found: " +
  6973. (Object.prototype.toString.call(newChild) === "[object Object]"
  6974. ? "object with keys {" + Object.keys(newChild).join(", ") + "}"
  6975. : newChild) +
  6976. ")." +
  6977. addendum
  6978. );
  6979. }
  6980. }
  6981. }
  6982. function warnOnFunctionType() {
  6983. {
  6984. var currentComponentErrorInfo =
  6985. "Functions are not valid as a React child. This may happen if " +
  6986. "you return a Component instead of <Component /> from render. " +
  6987. "Or maybe you meant to call this function rather than return it." +
  6988. getCurrentFiberStackInDev();
  6989. if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
  6990. return;
  6991. }
  6992. ownerHasFunctionTypeWarning[currentComponentErrorInfo] = true;
  6993. error(
  6994. "Functions are not valid as a React child. This may happen if " +
  6995. "you return a Component instead of <Component /> from render. " +
  6996. "Or maybe you meant to call this function rather than return it."
  6997. );
  6998. }
  6999. } // This wrapper function exists because I expect to clone the code in each path
  7000. // to be able to optimize each path individually by branching early. This needs
  7001. // a compiler or we can do it manually. Helpers that don't need this branching
  7002. // live outside of this function.
  7003. function ChildReconciler(shouldTrackSideEffects) {
  7004. function deleteChild(returnFiber, childToDelete) {
  7005. if (!shouldTrackSideEffects) {
  7006. // Noop.
  7007. return;
  7008. } // Deletions are added in reversed order so we add it to the front.
  7009. // At this point, the return fiber's effect list is empty except for
  7010. // deletions, so we can just append the deletion to the list. The remaining
  7011. // effects aren't added until the complete phase. Once we implement
  7012. // resuming, this may not be true.
  7013. var last = returnFiber.lastEffect;
  7014. if (last !== null) {
  7015. last.nextEffect = childToDelete;
  7016. returnFiber.lastEffect = childToDelete;
  7017. } else {
  7018. returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
  7019. }
  7020. childToDelete.nextEffect = null;
  7021. childToDelete.effectTag = Deletion;
  7022. }
  7023. function deleteRemainingChildren(returnFiber, currentFirstChild) {
  7024. if (!shouldTrackSideEffects) {
  7025. // Noop.
  7026. return null;
  7027. } // TODO: For the shouldClone case, this could be micro-optimized a bit by
  7028. // assuming that after the first child we've already added everything.
  7029. var childToDelete = currentFirstChild;
  7030. while (childToDelete !== null) {
  7031. deleteChild(returnFiber, childToDelete);
  7032. childToDelete = childToDelete.sibling;
  7033. }
  7034. return null;
  7035. }
  7036. function mapRemainingChildren(returnFiber, currentFirstChild) {
  7037. // Add the remaining children to a temporary map so that we can find them by
  7038. // keys quickly. Implicit (null) keys get added to this set with their index
  7039. // instead.
  7040. var existingChildren = new Map();
  7041. var existingChild = currentFirstChild;
  7042. while (existingChild !== null) {
  7043. if (existingChild.key !== null) {
  7044. existingChildren.set(existingChild.key, existingChild);
  7045. } else {
  7046. existingChildren.set(existingChild.index, existingChild);
  7047. }
  7048. existingChild = existingChild.sibling;
  7049. }
  7050. return existingChildren;
  7051. }
  7052. function useFiber(fiber, pendingProps) {
  7053. // We currently set sibling to null and index to 0 here because it is easy
  7054. // to forget to do before returning it. E.g. for the single child case.
  7055. var clone = createWorkInProgress(fiber, pendingProps);
  7056. clone.index = 0;
  7057. clone.sibling = null;
  7058. return clone;
  7059. }
  7060. function placeChild(newFiber, lastPlacedIndex, newIndex) {
  7061. newFiber.index = newIndex;
  7062. if (!shouldTrackSideEffects) {
  7063. // Noop.
  7064. return lastPlacedIndex;
  7065. }
  7066. var current = newFiber.alternate;
  7067. if (current !== null) {
  7068. var oldIndex = current.index;
  7069. if (oldIndex < lastPlacedIndex) {
  7070. // This is a move.
  7071. newFiber.effectTag = Placement;
  7072. return lastPlacedIndex;
  7073. } else {
  7074. // This item can stay in place.
  7075. return oldIndex;
  7076. }
  7077. } else {
  7078. // This is an insertion.
  7079. newFiber.effectTag = Placement;
  7080. return lastPlacedIndex;
  7081. }
  7082. }
  7083. function placeSingleChild(newFiber) {
  7084. // This is simpler for the single child case. We only need to do a
  7085. // placement for inserting new children.
  7086. if (shouldTrackSideEffects && newFiber.alternate === null) {
  7087. newFiber.effectTag = Placement;
  7088. }
  7089. return newFiber;
  7090. }
  7091. function updateTextNode(returnFiber, current, textContent, expirationTime) {
  7092. if (current === null || current.tag !== HostText) {
  7093. // Insert
  7094. var created = createFiberFromText(
  7095. textContent,
  7096. returnFiber.mode,
  7097. expirationTime
  7098. );
  7099. created.return = returnFiber;
  7100. return created;
  7101. } else {
  7102. // Update
  7103. var existing = useFiber(current, textContent);
  7104. existing.return = returnFiber;
  7105. return existing;
  7106. }
  7107. }
  7108. function updateElement(returnFiber, current, element, expirationTime) {
  7109. if (current !== null) {
  7110. if (
  7111. current.elementType === element.type || // Keep this check inline so it only runs on the false path:
  7112. isCompatibleFamilyForHotReloading(current, element)
  7113. ) {
  7114. // Move based on index
  7115. var existing = useFiber(current, element.props);
  7116. existing.ref = coerceRef(returnFiber, current, element);
  7117. existing.return = returnFiber;
  7118. {
  7119. existing._debugSource = element._source;
  7120. existing._debugOwner = element._owner;
  7121. }
  7122. return existing;
  7123. }
  7124. } // Insert
  7125. var created = createFiberFromElement(
  7126. element,
  7127. returnFiber.mode,
  7128. expirationTime
  7129. );
  7130. created.ref = coerceRef(returnFiber, current, element);
  7131. created.return = returnFiber;
  7132. return created;
  7133. }
  7134. function updatePortal(returnFiber, current, portal, expirationTime) {
  7135. if (
  7136. current === null ||
  7137. current.tag !== HostPortal ||
  7138. current.stateNode.containerInfo !== portal.containerInfo ||
  7139. current.stateNode.implementation !== portal.implementation
  7140. ) {
  7141. // Insert
  7142. var created = createFiberFromPortal(
  7143. portal,
  7144. returnFiber.mode,
  7145. expirationTime
  7146. );
  7147. created.return = returnFiber;
  7148. return created;
  7149. } else {
  7150. // Update
  7151. var existing = useFiber(current, portal.children || []);
  7152. existing.return = returnFiber;
  7153. return existing;
  7154. }
  7155. }
  7156. function updateFragment(returnFiber, current, fragment, expirationTime, key) {
  7157. if (current === null || current.tag !== Fragment) {
  7158. // Insert
  7159. var created = createFiberFromFragment(
  7160. fragment,
  7161. returnFiber.mode,
  7162. expirationTime,
  7163. key
  7164. );
  7165. created.return = returnFiber;
  7166. return created;
  7167. } else {
  7168. // Update
  7169. var existing = useFiber(current, fragment);
  7170. existing.return = returnFiber;
  7171. return existing;
  7172. }
  7173. }
  7174. function createChild(returnFiber, newChild, expirationTime) {
  7175. if (typeof newChild === "string" || typeof newChild === "number") {
  7176. // Text nodes don't have keys. If the previous node is implicitly keyed
  7177. // we can continue to replace it without aborting even if it is not a text
  7178. // node.
  7179. var created = createFiberFromText(
  7180. "" + newChild,
  7181. returnFiber.mode,
  7182. expirationTime
  7183. );
  7184. created.return = returnFiber;
  7185. return created;
  7186. }
  7187. if (typeof newChild === "object" && newChild !== null) {
  7188. switch (newChild.$$typeof) {
  7189. case REACT_ELEMENT_TYPE: {
  7190. var _created = createFiberFromElement(
  7191. newChild,
  7192. returnFiber.mode,
  7193. expirationTime
  7194. );
  7195. _created.ref = coerceRef(returnFiber, null, newChild);
  7196. _created.return = returnFiber;
  7197. return _created;
  7198. }
  7199. case REACT_PORTAL_TYPE: {
  7200. var _created2 = createFiberFromPortal(
  7201. newChild,
  7202. returnFiber.mode,
  7203. expirationTime
  7204. );
  7205. _created2.return = returnFiber;
  7206. return _created2;
  7207. }
  7208. }
  7209. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  7210. var _created3 = createFiberFromFragment(
  7211. newChild,
  7212. returnFiber.mode,
  7213. expirationTime,
  7214. null
  7215. );
  7216. _created3.return = returnFiber;
  7217. return _created3;
  7218. }
  7219. throwOnInvalidObjectType(returnFiber, newChild);
  7220. }
  7221. {
  7222. if (typeof newChild === "function") {
  7223. warnOnFunctionType();
  7224. }
  7225. }
  7226. return null;
  7227. }
  7228. function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {
  7229. // Update the fiber if the keys match, otherwise return null.
  7230. var key = oldFiber !== null ? oldFiber.key : null;
  7231. if (typeof newChild === "string" || typeof newChild === "number") {
  7232. // Text nodes don't have keys. If the previous node is implicitly keyed
  7233. // we can continue to replace it without aborting even if it is not a text
  7234. // node.
  7235. if (key !== null) {
  7236. return null;
  7237. }
  7238. return updateTextNode(
  7239. returnFiber,
  7240. oldFiber,
  7241. "" + newChild,
  7242. expirationTime
  7243. );
  7244. }
  7245. if (typeof newChild === "object" && newChild !== null) {
  7246. switch (newChild.$$typeof) {
  7247. case REACT_ELEMENT_TYPE: {
  7248. if (newChild.key === key) {
  7249. if (newChild.type === REACT_FRAGMENT_TYPE) {
  7250. return updateFragment(
  7251. returnFiber,
  7252. oldFiber,
  7253. newChild.props.children,
  7254. expirationTime,
  7255. key
  7256. );
  7257. }
  7258. return updateElement(
  7259. returnFiber,
  7260. oldFiber,
  7261. newChild,
  7262. expirationTime
  7263. );
  7264. } else {
  7265. return null;
  7266. }
  7267. }
  7268. case REACT_PORTAL_TYPE: {
  7269. if (newChild.key === key) {
  7270. return updatePortal(
  7271. returnFiber,
  7272. oldFiber,
  7273. newChild,
  7274. expirationTime
  7275. );
  7276. } else {
  7277. return null;
  7278. }
  7279. }
  7280. }
  7281. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  7282. if (key !== null) {
  7283. return null;
  7284. }
  7285. return updateFragment(
  7286. returnFiber,
  7287. oldFiber,
  7288. newChild,
  7289. expirationTime,
  7290. null
  7291. );
  7292. }
  7293. throwOnInvalidObjectType(returnFiber, newChild);
  7294. }
  7295. {
  7296. if (typeof newChild === "function") {
  7297. warnOnFunctionType();
  7298. }
  7299. }
  7300. return null;
  7301. }
  7302. function updateFromMap(
  7303. existingChildren,
  7304. returnFiber,
  7305. newIdx,
  7306. newChild,
  7307. expirationTime
  7308. ) {
  7309. if (typeof newChild === "string" || typeof newChild === "number") {
  7310. // Text nodes don't have keys, so we neither have to check the old nor
  7311. // new node for the key. If both are text nodes, they match.
  7312. var matchedFiber = existingChildren.get(newIdx) || null;
  7313. return updateTextNode(
  7314. returnFiber,
  7315. matchedFiber,
  7316. "" + newChild,
  7317. expirationTime
  7318. );
  7319. }
  7320. if (typeof newChild === "object" && newChild !== null) {
  7321. switch (newChild.$$typeof) {
  7322. case REACT_ELEMENT_TYPE: {
  7323. var _matchedFiber =
  7324. existingChildren.get(
  7325. newChild.key === null ? newIdx : newChild.key
  7326. ) || null;
  7327. if (newChild.type === REACT_FRAGMENT_TYPE) {
  7328. return updateFragment(
  7329. returnFiber,
  7330. _matchedFiber,
  7331. newChild.props.children,
  7332. expirationTime,
  7333. newChild.key
  7334. );
  7335. }
  7336. return updateElement(
  7337. returnFiber,
  7338. _matchedFiber,
  7339. newChild,
  7340. expirationTime
  7341. );
  7342. }
  7343. case REACT_PORTAL_TYPE: {
  7344. var _matchedFiber2 =
  7345. existingChildren.get(
  7346. newChild.key === null ? newIdx : newChild.key
  7347. ) || null;
  7348. return updatePortal(
  7349. returnFiber,
  7350. _matchedFiber2,
  7351. newChild,
  7352. expirationTime
  7353. );
  7354. }
  7355. }
  7356. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  7357. var _matchedFiber3 = existingChildren.get(newIdx) || null;
  7358. return updateFragment(
  7359. returnFiber,
  7360. _matchedFiber3,
  7361. newChild,
  7362. expirationTime,
  7363. null
  7364. );
  7365. }
  7366. throwOnInvalidObjectType(returnFiber, newChild);
  7367. }
  7368. {
  7369. if (typeof newChild === "function") {
  7370. warnOnFunctionType();
  7371. }
  7372. }
  7373. return null;
  7374. }
  7375. /**
  7376. * Warns if there is a duplicate or missing key
  7377. */
  7378. function warnOnInvalidKey(child, knownKeys) {
  7379. {
  7380. if (typeof child !== "object" || child === null) {
  7381. return knownKeys;
  7382. }
  7383. switch (child.$$typeof) {
  7384. case REACT_ELEMENT_TYPE:
  7385. case REACT_PORTAL_TYPE:
  7386. warnForMissingKey(child);
  7387. var key = child.key;
  7388. if (typeof key !== "string") {
  7389. break;
  7390. }
  7391. if (knownKeys === null) {
  7392. knownKeys = new Set();
  7393. knownKeys.add(key);
  7394. break;
  7395. }
  7396. if (!knownKeys.has(key)) {
  7397. knownKeys.add(key);
  7398. break;
  7399. }
  7400. error(
  7401. "Encountered two children with the same key, `%s`. " +
  7402. "Keys should be unique so that components maintain their identity " +
  7403. "across updates. Non-unique keys may cause children to be " +
  7404. "duplicated and/or omitted — the behavior is unsupported and " +
  7405. "could change in a future version.",
  7406. key
  7407. );
  7408. break;
  7409. }
  7410. }
  7411. return knownKeys;
  7412. }
  7413. function reconcileChildrenArray(
  7414. returnFiber,
  7415. currentFirstChild,
  7416. newChildren,
  7417. expirationTime
  7418. ) {
  7419. // This algorithm can't optimize by searching from both ends since we
  7420. // don't have backpointers on fibers. I'm trying to see how far we can get
  7421. // with that model. If it ends up not being worth the tradeoffs, we can
  7422. // add it later.
  7423. // Even with a two ended optimization, we'd want to optimize for the case
  7424. // where there are few changes and brute force the comparison instead of
  7425. // going for the Map. It'd like to explore hitting that path first in
  7426. // forward-only mode and only go for the Map once we notice that we need
  7427. // lots of look ahead. This doesn't handle reversal as well as two ended
  7428. // search but that's unusual. Besides, for the two ended optimization to
  7429. // work on Iterables, we'd need to copy the whole set.
  7430. // In this first iteration, we'll just live with hitting the bad case
  7431. // (adding everything to a Map) in for every insert/move.
  7432. // If you change this code, also update reconcileChildrenIterator() which
  7433. // uses the same algorithm.
  7434. {
  7435. // First, validate keys.
  7436. var knownKeys = null;
  7437. for (var i = 0; i < newChildren.length; i++) {
  7438. var child = newChildren[i];
  7439. knownKeys = warnOnInvalidKey(child, knownKeys);
  7440. }
  7441. }
  7442. var resultingFirstChild = null;
  7443. var previousNewFiber = null;
  7444. var oldFiber = currentFirstChild;
  7445. var lastPlacedIndex = 0;
  7446. var newIdx = 0;
  7447. var nextOldFiber = null;
  7448. for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
  7449. if (oldFiber.index > newIdx) {
  7450. nextOldFiber = oldFiber;
  7451. oldFiber = null;
  7452. } else {
  7453. nextOldFiber = oldFiber.sibling;
  7454. }
  7455. var newFiber = updateSlot(
  7456. returnFiber,
  7457. oldFiber,
  7458. newChildren[newIdx],
  7459. expirationTime
  7460. );
  7461. if (newFiber === null) {
  7462. // TODO: This breaks on empty slots like null children. That's
  7463. // unfortunate because it triggers the slow path all the time. We need
  7464. // a better way to communicate whether this was a miss or null,
  7465. // boolean, undefined, etc.
  7466. if (oldFiber === null) {
  7467. oldFiber = nextOldFiber;
  7468. }
  7469. break;
  7470. }
  7471. if (shouldTrackSideEffects) {
  7472. if (oldFiber && newFiber.alternate === null) {
  7473. // We matched the slot, but we didn't reuse the existing fiber, so we
  7474. // need to delete the existing child.
  7475. deleteChild(returnFiber, oldFiber);
  7476. }
  7477. }
  7478. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  7479. if (previousNewFiber === null) {
  7480. // TODO: Move out of the loop. This only happens for the first run.
  7481. resultingFirstChild = newFiber;
  7482. } else {
  7483. // TODO: Defer siblings if we're not at the right index for this slot.
  7484. // I.e. if we had null values before, then we want to defer this
  7485. // for each null value. However, we also don't want to call updateSlot
  7486. // with the previous one.
  7487. previousNewFiber.sibling = newFiber;
  7488. }
  7489. previousNewFiber = newFiber;
  7490. oldFiber = nextOldFiber;
  7491. }
  7492. if (newIdx === newChildren.length) {
  7493. // We've reached the end of the new children. We can delete the rest.
  7494. deleteRemainingChildren(returnFiber, oldFiber);
  7495. return resultingFirstChild;
  7496. }
  7497. if (oldFiber === null) {
  7498. // If we don't have any more existing children we can choose a fast path
  7499. // since the rest will all be insertions.
  7500. for (; newIdx < newChildren.length; newIdx++) {
  7501. var _newFiber = createChild(
  7502. returnFiber,
  7503. newChildren[newIdx],
  7504. expirationTime
  7505. );
  7506. if (_newFiber === null) {
  7507. continue;
  7508. }
  7509. lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
  7510. if (previousNewFiber === null) {
  7511. // TODO: Move out of the loop. This only happens for the first run.
  7512. resultingFirstChild = _newFiber;
  7513. } else {
  7514. previousNewFiber.sibling = _newFiber;
  7515. }
  7516. previousNewFiber = _newFiber;
  7517. }
  7518. return resultingFirstChild;
  7519. } // Add all children to a key map for quick lookups.
  7520. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  7521. for (; newIdx < newChildren.length; newIdx++) {
  7522. var _newFiber2 = updateFromMap(
  7523. existingChildren,
  7524. returnFiber,
  7525. newIdx,
  7526. newChildren[newIdx],
  7527. expirationTime
  7528. );
  7529. if (_newFiber2 !== null) {
  7530. if (shouldTrackSideEffects) {
  7531. if (_newFiber2.alternate !== null) {
  7532. // The new fiber is a work in progress, but if there exists a
  7533. // current, that means that we reused the fiber. We need to delete
  7534. // it from the child list so that we don't add it to the deletion
  7535. // list.
  7536. existingChildren.delete(
  7537. _newFiber2.key === null ? newIdx : _newFiber2.key
  7538. );
  7539. }
  7540. }
  7541. lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
  7542. if (previousNewFiber === null) {
  7543. resultingFirstChild = _newFiber2;
  7544. } else {
  7545. previousNewFiber.sibling = _newFiber2;
  7546. }
  7547. previousNewFiber = _newFiber2;
  7548. }
  7549. }
  7550. if (shouldTrackSideEffects) {
  7551. // Any existing children that weren't consumed above were deleted. We need
  7552. // to add them to the deletion list.
  7553. existingChildren.forEach(function(child) {
  7554. return deleteChild(returnFiber, child);
  7555. });
  7556. }
  7557. return resultingFirstChild;
  7558. }
  7559. function reconcileChildrenIterator(
  7560. returnFiber,
  7561. currentFirstChild,
  7562. newChildrenIterable,
  7563. expirationTime
  7564. ) {
  7565. // This is the same implementation as reconcileChildrenArray(),
  7566. // but using the iterator instead.
  7567. var iteratorFn = getIteratorFn(newChildrenIterable);
  7568. if (!(typeof iteratorFn === "function")) {
  7569. throw Error(
  7570. "An object is not an iterable. This error is likely caused by a bug in React. Please file an issue."
  7571. );
  7572. }
  7573. {
  7574. // We don't support rendering Generators because it's a mutation.
  7575. // See https://github.com/facebook/react/issues/12995
  7576. if (
  7577. typeof Symbol === "function" && // $FlowFixMe Flow doesn't know about toStringTag
  7578. newChildrenIterable[Symbol.toStringTag] === "Generator"
  7579. ) {
  7580. if (!didWarnAboutGenerators) {
  7581. error(
  7582. "Using Generators as children is unsupported and will likely yield " +
  7583. "unexpected results because enumerating a generator mutates it. " +
  7584. "You may convert it to an array with `Array.from()` or the " +
  7585. "`[...spread]` operator before rendering. Keep in mind " +
  7586. "you might need to polyfill these features for older browsers."
  7587. );
  7588. }
  7589. didWarnAboutGenerators = true;
  7590. } // Warn about using Maps as children
  7591. if (newChildrenIterable.entries === iteratorFn) {
  7592. if (!didWarnAboutMaps) {
  7593. error(
  7594. "Using Maps as children is unsupported and will likely yield " +
  7595. "unexpected results. Convert it to a sequence/iterable of keyed " +
  7596. "ReactElements instead."
  7597. );
  7598. }
  7599. didWarnAboutMaps = true;
  7600. } // First, validate keys.
  7601. // We'll get a different iterator later for the main pass.
  7602. var _newChildren = iteratorFn.call(newChildrenIterable);
  7603. if (_newChildren) {
  7604. var knownKeys = null;
  7605. var _step = _newChildren.next();
  7606. for (; !_step.done; _step = _newChildren.next()) {
  7607. var child = _step.value;
  7608. knownKeys = warnOnInvalidKey(child, knownKeys);
  7609. }
  7610. }
  7611. }
  7612. var newChildren = iteratorFn.call(newChildrenIterable);
  7613. if (!(newChildren != null)) {
  7614. throw Error("An iterable object provided no iterator.");
  7615. }
  7616. var resultingFirstChild = null;
  7617. var previousNewFiber = null;
  7618. var oldFiber = currentFirstChild;
  7619. var lastPlacedIndex = 0;
  7620. var newIdx = 0;
  7621. var nextOldFiber = null;
  7622. var step = newChildren.next();
  7623. for (
  7624. ;
  7625. oldFiber !== null && !step.done;
  7626. newIdx++, step = newChildren.next()
  7627. ) {
  7628. if (oldFiber.index > newIdx) {
  7629. nextOldFiber = oldFiber;
  7630. oldFiber = null;
  7631. } else {
  7632. nextOldFiber = oldFiber.sibling;
  7633. }
  7634. var newFiber = updateSlot(
  7635. returnFiber,
  7636. oldFiber,
  7637. step.value,
  7638. expirationTime
  7639. );
  7640. if (newFiber === null) {
  7641. // TODO: This breaks on empty slots like null children. That's
  7642. // unfortunate because it triggers the slow path all the time. We need
  7643. // a better way to communicate whether this was a miss or null,
  7644. // boolean, undefined, etc.
  7645. if (oldFiber === null) {
  7646. oldFiber = nextOldFiber;
  7647. }
  7648. break;
  7649. }
  7650. if (shouldTrackSideEffects) {
  7651. if (oldFiber && newFiber.alternate === null) {
  7652. // We matched the slot, but we didn't reuse the existing fiber, so we
  7653. // need to delete the existing child.
  7654. deleteChild(returnFiber, oldFiber);
  7655. }
  7656. }
  7657. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  7658. if (previousNewFiber === null) {
  7659. // TODO: Move out of the loop. This only happens for the first run.
  7660. resultingFirstChild = newFiber;
  7661. } else {
  7662. // TODO: Defer siblings if we're not at the right index for this slot.
  7663. // I.e. if we had null values before, then we want to defer this
  7664. // for each null value. However, we also don't want to call updateSlot
  7665. // with the previous one.
  7666. previousNewFiber.sibling = newFiber;
  7667. }
  7668. previousNewFiber = newFiber;
  7669. oldFiber = nextOldFiber;
  7670. }
  7671. if (step.done) {
  7672. // We've reached the end of the new children. We can delete the rest.
  7673. deleteRemainingChildren(returnFiber, oldFiber);
  7674. return resultingFirstChild;
  7675. }
  7676. if (oldFiber === null) {
  7677. // If we don't have any more existing children we can choose a fast path
  7678. // since the rest will all be insertions.
  7679. for (; !step.done; newIdx++, step = newChildren.next()) {
  7680. var _newFiber3 = createChild(returnFiber, step.value, expirationTime);
  7681. if (_newFiber3 === null) {
  7682. continue;
  7683. }
  7684. lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
  7685. if (previousNewFiber === null) {
  7686. // TODO: Move out of the loop. This only happens for the first run.
  7687. resultingFirstChild = _newFiber3;
  7688. } else {
  7689. previousNewFiber.sibling = _newFiber3;
  7690. }
  7691. previousNewFiber = _newFiber3;
  7692. }
  7693. return resultingFirstChild;
  7694. } // Add all children to a key map for quick lookups.
  7695. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  7696. for (; !step.done; newIdx++, step = newChildren.next()) {
  7697. var _newFiber4 = updateFromMap(
  7698. existingChildren,
  7699. returnFiber,
  7700. newIdx,
  7701. step.value,
  7702. expirationTime
  7703. );
  7704. if (_newFiber4 !== null) {
  7705. if (shouldTrackSideEffects) {
  7706. if (_newFiber4.alternate !== null) {
  7707. // The new fiber is a work in progress, but if there exists a
  7708. // current, that means that we reused the fiber. We need to delete
  7709. // it from the child list so that we don't add it to the deletion
  7710. // list.
  7711. existingChildren.delete(
  7712. _newFiber4.key === null ? newIdx : _newFiber4.key
  7713. );
  7714. }
  7715. }
  7716. lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
  7717. if (previousNewFiber === null) {
  7718. resultingFirstChild = _newFiber4;
  7719. } else {
  7720. previousNewFiber.sibling = _newFiber4;
  7721. }
  7722. previousNewFiber = _newFiber4;
  7723. }
  7724. }
  7725. if (shouldTrackSideEffects) {
  7726. // Any existing children that weren't consumed above were deleted. We need
  7727. // to add them to the deletion list.
  7728. existingChildren.forEach(function(child) {
  7729. return deleteChild(returnFiber, child);
  7730. });
  7731. }
  7732. return resultingFirstChild;
  7733. }
  7734. function reconcileSingleTextNode(
  7735. returnFiber,
  7736. currentFirstChild,
  7737. textContent,
  7738. expirationTime
  7739. ) {
  7740. // There's no need to check for keys on text nodes since we don't have a
  7741. // way to define them.
  7742. if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
  7743. // We already have an existing node so let's just update it and delete
  7744. // the rest.
  7745. deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
  7746. var existing = useFiber(currentFirstChild, textContent);
  7747. existing.return = returnFiber;
  7748. return existing;
  7749. } // The existing first child is not a text node so we need to create one
  7750. // and delete the existing ones.
  7751. deleteRemainingChildren(returnFiber, currentFirstChild);
  7752. var created = createFiberFromText(
  7753. textContent,
  7754. returnFiber.mode,
  7755. expirationTime
  7756. );
  7757. created.return = returnFiber;
  7758. return created;
  7759. }
  7760. function reconcileSingleElement(
  7761. returnFiber,
  7762. currentFirstChild,
  7763. element,
  7764. expirationTime
  7765. ) {
  7766. var key = element.key;
  7767. var child = currentFirstChild;
  7768. while (child !== null) {
  7769. // TODO: If key === null and child.key === null, then this only applies to
  7770. // the first item in the list.
  7771. if (child.key === key) {
  7772. switch (child.tag) {
  7773. case Fragment: {
  7774. if (element.type === REACT_FRAGMENT_TYPE) {
  7775. deleteRemainingChildren(returnFiber, child.sibling);
  7776. var existing = useFiber(child, element.props.children);
  7777. existing.return = returnFiber;
  7778. {
  7779. existing._debugSource = element._source;
  7780. existing._debugOwner = element._owner;
  7781. }
  7782. return existing;
  7783. }
  7784. break;
  7785. }
  7786. case Block:
  7787. // We intentionally fallthrough here if enableBlocksAPI is not on.
  7788. // eslint-disable-next-lined no-fallthrough
  7789. default: {
  7790. if (
  7791. child.elementType === element.type || // Keep this check inline so it only runs on the false path:
  7792. isCompatibleFamilyForHotReloading(child, element)
  7793. ) {
  7794. deleteRemainingChildren(returnFiber, child.sibling);
  7795. var _existing3 = useFiber(child, element.props);
  7796. _existing3.ref = coerceRef(returnFiber, child, element);
  7797. _existing3.return = returnFiber;
  7798. {
  7799. _existing3._debugSource = element._source;
  7800. _existing3._debugOwner = element._owner;
  7801. }
  7802. return _existing3;
  7803. }
  7804. break;
  7805. }
  7806. } // Didn't match.
  7807. deleteRemainingChildren(returnFiber, child);
  7808. break;
  7809. } else {
  7810. deleteChild(returnFiber, child);
  7811. }
  7812. child = child.sibling;
  7813. }
  7814. if (element.type === REACT_FRAGMENT_TYPE) {
  7815. var created = createFiberFromFragment(
  7816. element.props.children,
  7817. returnFiber.mode,
  7818. expirationTime,
  7819. element.key
  7820. );
  7821. created.return = returnFiber;
  7822. return created;
  7823. } else {
  7824. var _created4 = createFiberFromElement(
  7825. element,
  7826. returnFiber.mode,
  7827. expirationTime
  7828. );
  7829. _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
  7830. _created4.return = returnFiber;
  7831. return _created4;
  7832. }
  7833. }
  7834. function reconcileSinglePortal(
  7835. returnFiber,
  7836. currentFirstChild,
  7837. portal,
  7838. expirationTime
  7839. ) {
  7840. var key = portal.key;
  7841. var child = currentFirstChild;
  7842. while (child !== null) {
  7843. // TODO: If key === null and child.key === null, then this only applies to
  7844. // the first item in the list.
  7845. if (child.key === key) {
  7846. if (
  7847. child.tag === HostPortal &&
  7848. child.stateNode.containerInfo === portal.containerInfo &&
  7849. child.stateNode.implementation === portal.implementation
  7850. ) {
  7851. deleteRemainingChildren(returnFiber, child.sibling);
  7852. var existing = useFiber(child, portal.children || []);
  7853. existing.return = returnFiber;
  7854. return existing;
  7855. } else {
  7856. deleteRemainingChildren(returnFiber, child);
  7857. break;
  7858. }
  7859. } else {
  7860. deleteChild(returnFiber, child);
  7861. }
  7862. child = child.sibling;
  7863. }
  7864. var created = createFiberFromPortal(
  7865. portal,
  7866. returnFiber.mode,
  7867. expirationTime
  7868. );
  7869. created.return = returnFiber;
  7870. return created;
  7871. } // This API will tag the children with the side-effect of the reconciliation
  7872. // itself. They will be added to the side-effect list as we pass through the
  7873. // children and the parent.
  7874. function reconcileChildFibers(
  7875. returnFiber,
  7876. currentFirstChild,
  7877. newChild,
  7878. expirationTime
  7879. ) {
  7880. // This function is not recursive.
  7881. // If the top level item is an array, we treat it as a set of children,
  7882. // not as a fragment. Nested arrays on the other hand will be treated as
  7883. // fragment nodes. Recursion happens at the normal flow.
  7884. // Handle top level unkeyed fragments as if they were arrays.
  7885. // This leads to an ambiguity between <>{[...]}</> and <>...</>.
  7886. // We treat the ambiguous cases above the same.
  7887. var isUnkeyedTopLevelFragment =
  7888. typeof newChild === "object" &&
  7889. newChild !== null &&
  7890. newChild.type === REACT_FRAGMENT_TYPE &&
  7891. newChild.key === null;
  7892. if (isUnkeyedTopLevelFragment) {
  7893. newChild = newChild.props.children;
  7894. } // Handle object types
  7895. var isObject = typeof newChild === "object" && newChild !== null;
  7896. if (isObject) {
  7897. switch (newChild.$$typeof) {
  7898. case REACT_ELEMENT_TYPE:
  7899. return placeSingleChild(
  7900. reconcileSingleElement(
  7901. returnFiber,
  7902. currentFirstChild,
  7903. newChild,
  7904. expirationTime
  7905. )
  7906. );
  7907. case REACT_PORTAL_TYPE:
  7908. return placeSingleChild(
  7909. reconcileSinglePortal(
  7910. returnFiber,
  7911. currentFirstChild,
  7912. newChild,
  7913. expirationTime
  7914. )
  7915. );
  7916. }
  7917. }
  7918. if (typeof newChild === "string" || typeof newChild === "number") {
  7919. return placeSingleChild(
  7920. reconcileSingleTextNode(
  7921. returnFiber,
  7922. currentFirstChild,
  7923. "" + newChild,
  7924. expirationTime
  7925. )
  7926. );
  7927. }
  7928. if (isArray$1(newChild)) {
  7929. return reconcileChildrenArray(
  7930. returnFiber,
  7931. currentFirstChild,
  7932. newChild,
  7933. expirationTime
  7934. );
  7935. }
  7936. if (getIteratorFn(newChild)) {
  7937. return reconcileChildrenIterator(
  7938. returnFiber,
  7939. currentFirstChild,
  7940. newChild,
  7941. expirationTime
  7942. );
  7943. }
  7944. if (isObject) {
  7945. throwOnInvalidObjectType(returnFiber, newChild);
  7946. }
  7947. {
  7948. if (typeof newChild === "function") {
  7949. warnOnFunctionType();
  7950. }
  7951. }
  7952. if (typeof newChild === "undefined" && !isUnkeyedTopLevelFragment) {
  7953. // If the new child is undefined, and the return fiber is a composite
  7954. // component, throw an error. If Fiber return types are disabled,
  7955. // we already threw above.
  7956. switch (returnFiber.tag) {
  7957. case ClassComponent: {
  7958. {
  7959. var instance = returnFiber.stateNode;
  7960. if (instance.render._isMockFunction) {
  7961. // We allow auto-mocks to proceed as if they're returning null.
  7962. break;
  7963. }
  7964. }
  7965. }
  7966. // Intentionally fall through to the next case, which handles both
  7967. // functions and classes
  7968. // eslint-disable-next-lined no-fallthrough
  7969. case FunctionComponent: {
  7970. var Component = returnFiber.type;
  7971. {
  7972. throw Error(
  7973. (Component.displayName || Component.name || "Component") +
  7974. "(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null."
  7975. );
  7976. }
  7977. }
  7978. }
  7979. } // Remaining cases are all treated as empty.
  7980. return deleteRemainingChildren(returnFiber, currentFirstChild);
  7981. }
  7982. return reconcileChildFibers;
  7983. }
  7984. var reconcileChildFibers = ChildReconciler(true);
  7985. var mountChildFibers = ChildReconciler(false);
  7986. function cloneChildFibers(current, workInProgress) {
  7987. if (!(current === null || workInProgress.child === current.child)) {
  7988. throw Error("Resuming work not yet implemented.");
  7989. }
  7990. if (workInProgress.child === null) {
  7991. return;
  7992. }
  7993. var currentChild = workInProgress.child;
  7994. var newChild = createWorkInProgress(currentChild, currentChild.pendingProps);
  7995. workInProgress.child = newChild;
  7996. newChild.return = workInProgress;
  7997. while (currentChild.sibling !== null) {
  7998. currentChild = currentChild.sibling;
  7999. newChild = newChild.sibling = createWorkInProgress(
  8000. currentChild,
  8001. currentChild.pendingProps
  8002. );
  8003. newChild.return = workInProgress;
  8004. }
  8005. newChild.sibling = null;
  8006. } // Reset a workInProgress child set to prepare it for a second pass.
  8007. function resetChildFibers(workInProgress, renderExpirationTime) {
  8008. var child = workInProgress.child;
  8009. while (child !== null) {
  8010. resetWorkInProgress(child, renderExpirationTime);
  8011. child = child.sibling;
  8012. }
  8013. }
  8014. var NO_CONTEXT = {};
  8015. var contextStackCursor$1 = createCursor(NO_CONTEXT);
  8016. var contextFiberStackCursor = createCursor(NO_CONTEXT);
  8017. var rootInstanceStackCursor = createCursor(NO_CONTEXT);
  8018. function requiredContext(c) {
  8019. if (!(c !== NO_CONTEXT)) {
  8020. throw Error(
  8021. "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue."
  8022. );
  8023. }
  8024. return c;
  8025. }
  8026. function getRootHostContainer() {
  8027. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  8028. return rootInstance;
  8029. }
  8030. function pushHostContainer(fiber, nextRootInstance) {
  8031. // Push current root instance onto the stack;
  8032. // This allows us to reset root when portals are popped.
  8033. push(rootInstanceStackCursor, nextRootInstance, fiber); // Track the context and the Fiber that provided it.
  8034. // This enables us to pop only Fibers that provide unique contexts.
  8035. push(contextFiberStackCursor, fiber, fiber); // Finally, we need to push the host context to the stack.
  8036. // However, we can't just call getRootHostContext() and push it because
  8037. // we'd have a different number of entries on the stack depending on
  8038. // whether getRootHostContext() throws somewhere in renderer code or not.
  8039. // So we push an empty value first. This lets us safely unwind on errors.
  8040. push(contextStackCursor$1, NO_CONTEXT, fiber);
  8041. var nextRootContext = getRootHostContext(); // Now that we know this function doesn't throw, replace it.
  8042. pop(contextStackCursor$1, fiber);
  8043. push(contextStackCursor$1, nextRootContext, fiber);
  8044. }
  8045. function popHostContainer(fiber) {
  8046. pop(contextStackCursor$1, fiber);
  8047. pop(contextFiberStackCursor, fiber);
  8048. pop(rootInstanceStackCursor, fiber);
  8049. }
  8050. function getHostContext() {
  8051. var context = requiredContext(contextStackCursor$1.current);
  8052. return context;
  8053. }
  8054. function pushHostContext(fiber) {
  8055. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  8056. var context = requiredContext(contextStackCursor$1.current);
  8057. var nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique.
  8058. if (context === nextContext) {
  8059. return;
  8060. } // Track the context and the Fiber that provided it.
  8061. // This enables us to pop only Fibers that provide unique contexts.
  8062. push(contextFiberStackCursor, fiber, fiber);
  8063. push(contextStackCursor$1, nextContext, fiber);
  8064. }
  8065. function popHostContext(fiber) {
  8066. // Do not pop unless this Fiber provided the current context.
  8067. // pushHostContext() only pushes Fibers that provide unique contexts.
  8068. if (contextFiberStackCursor.current !== fiber) {
  8069. return;
  8070. }
  8071. pop(contextStackCursor$1, fiber);
  8072. pop(contextFiberStackCursor, fiber);
  8073. }
  8074. var DefaultSuspenseContext = 0; // The Suspense Context is split into two parts. The lower bits is
  8075. // inherited deeply down the subtree. The upper bits only affect
  8076. // this immediate suspense boundary and gets reset each new
  8077. // boundary or suspense list.
  8078. var SubtreeSuspenseContextMask = 1; // Subtree Flags:
  8079. // InvisibleParentSuspenseContext indicates that one of our parent Suspense
  8080. // boundaries is not currently showing visible main content.
  8081. // Either because it is already showing a fallback or is not mounted at all.
  8082. // We can use this to determine if it is desirable to trigger a fallback at
  8083. // the parent. If not, then we might need to trigger undesirable boundaries
  8084. // and/or suspend the commit to avoid hiding the parent content.
  8085. var InvisibleParentSuspenseContext = 1; // Shallow Flags:
  8086. // ForceSuspenseFallback can be used by SuspenseList to force newly added
  8087. // items into their fallback state during one of the render passes.
  8088. var ForceSuspenseFallback = 2;
  8089. var suspenseStackCursor = createCursor(DefaultSuspenseContext);
  8090. function hasSuspenseContext(parentContext, flag) {
  8091. return (parentContext & flag) !== 0;
  8092. }
  8093. function setDefaultShallowSuspenseContext(parentContext) {
  8094. return parentContext & SubtreeSuspenseContextMask;
  8095. }
  8096. function setShallowSuspenseContext(parentContext, shallowContext) {
  8097. return (parentContext & SubtreeSuspenseContextMask) | shallowContext;
  8098. }
  8099. function addSubtreeSuspenseContext(parentContext, subtreeContext) {
  8100. return parentContext | subtreeContext;
  8101. }
  8102. function pushSuspenseContext(fiber, newContext) {
  8103. push(suspenseStackCursor, newContext, fiber);
  8104. }
  8105. function popSuspenseContext(fiber) {
  8106. pop(suspenseStackCursor, fiber);
  8107. }
  8108. function shouldCaptureSuspense(workInProgress, hasInvisibleParent) {
  8109. // If it was the primary children that just suspended, capture and render the
  8110. // fallback. Otherwise, don't capture and bubble to the next boundary.
  8111. var nextState = workInProgress.memoizedState;
  8112. if (nextState !== null) {
  8113. if (nextState.dehydrated !== null) {
  8114. // A dehydrated boundary always captures.
  8115. return true;
  8116. }
  8117. return false;
  8118. }
  8119. var props = workInProgress.memoizedProps; // In order to capture, the Suspense component must have a fallback prop.
  8120. if (props.fallback === undefined) {
  8121. return false;
  8122. } // Regular boundaries always capture.
  8123. if (props.unstable_avoidThisFallback !== true) {
  8124. return true;
  8125. } // If it's a boundary we should avoid, then we prefer to bubble up to the
  8126. // parent boundary if it is currently invisible.
  8127. if (hasInvisibleParent) {
  8128. return false;
  8129. } // If the parent is not able to handle it, we must handle it.
  8130. return true;
  8131. }
  8132. function findFirstSuspended(row) {
  8133. var node = row;
  8134. while (node !== null) {
  8135. if (node.tag === SuspenseComponent) {
  8136. var state = node.memoizedState;
  8137. if (state !== null) {
  8138. var dehydrated = state.dehydrated;
  8139. if (
  8140. dehydrated === null ||
  8141. isSuspenseInstancePending() ||
  8142. isSuspenseInstanceFallback()
  8143. ) {
  8144. return node;
  8145. }
  8146. }
  8147. } else if (
  8148. node.tag === SuspenseListComponent && // revealOrder undefined can't be trusted because it don't
  8149. // keep track of whether it suspended or not.
  8150. node.memoizedProps.revealOrder !== undefined
  8151. ) {
  8152. var didSuspend = (node.effectTag & DidCapture) !== NoEffect;
  8153. if (didSuspend) {
  8154. return node;
  8155. }
  8156. } else if (node.child !== null) {
  8157. node.child.return = node;
  8158. node = node.child;
  8159. continue;
  8160. }
  8161. if (node === row) {
  8162. return null;
  8163. }
  8164. while (node.sibling === null) {
  8165. if (node.return === null || node.return === row) {
  8166. return null;
  8167. }
  8168. node = node.return;
  8169. }
  8170. node.sibling.return = node.return;
  8171. node = node.sibling;
  8172. }
  8173. return null;
  8174. }
  8175. function createDeprecatedResponderListener(responder, props) {
  8176. var eventResponderListener = {
  8177. responder: responder,
  8178. props: props
  8179. };
  8180. {
  8181. Object.freeze(eventResponderListener);
  8182. }
  8183. return eventResponderListener;
  8184. }
  8185. var HasEffect =
  8186. /* */
  8187. 1; // Represents the phase in which the effect (not the clean-up) fires.
  8188. var Layout =
  8189. /* */
  8190. 2;
  8191. var Passive$1 =
  8192. /* */
  8193. 4;
  8194. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher,
  8195. ReactCurrentBatchConfig$1 = ReactSharedInternals.ReactCurrentBatchConfig;
  8196. var didWarnAboutMismatchedHooksForComponent;
  8197. {
  8198. didWarnAboutMismatchedHooksForComponent = new Set();
  8199. }
  8200. // These are set right before calling the component.
  8201. var renderExpirationTime = NoWork; // The work-in-progress fiber. I've named it differently to distinguish it from
  8202. // the work-in-progress hook.
  8203. var currentlyRenderingFiber$1 = null; // Hooks are stored as a linked list on the fiber's memoizedState field. The
  8204. // current hook list is the list that belongs to the current fiber. The
  8205. // work-in-progress hook list is a new list that will be added to the
  8206. // work-in-progress fiber.
  8207. var currentHook = null;
  8208. var workInProgressHook = null; // Whether an update was scheduled at any point during the render phase. This
  8209. // does not get reset if we do another render pass; only when we're completely
  8210. // finished evaluating this component. This is an optimization so we know
  8211. // whether we need to clear render phase updates after a throw.
  8212. var didScheduleRenderPhaseUpdate = false;
  8213. var RE_RENDER_LIMIT = 25; // In DEV, this is the name of the currently executing primitive hook
  8214. var currentHookNameInDev = null; // In DEV, this list ensures that hooks are called in the same order between renders.
  8215. // The list stores the order of hooks used during the initial render (mount).
  8216. // Subsequent renders (updates) reference this list.
  8217. var hookTypesDev = null;
  8218. var hookTypesUpdateIndexDev = -1; // In DEV, this tracks whether currently rendering component needs to ignore
  8219. // the dependencies for Hooks that need them (e.g. useEffect or useMemo).
  8220. // When true, such Hooks will always be "remounted". Only used during hot reload.
  8221. var ignorePreviousDependencies = false;
  8222. function mountHookTypesDev() {
  8223. {
  8224. var hookName = currentHookNameInDev;
  8225. if (hookTypesDev === null) {
  8226. hookTypesDev = [hookName];
  8227. } else {
  8228. hookTypesDev.push(hookName);
  8229. }
  8230. }
  8231. }
  8232. function updateHookTypesDev() {
  8233. {
  8234. var hookName = currentHookNameInDev;
  8235. if (hookTypesDev !== null) {
  8236. hookTypesUpdateIndexDev++;
  8237. if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
  8238. warnOnHookMismatchInDev(hookName);
  8239. }
  8240. }
  8241. }
  8242. }
  8243. function checkDepsAreArrayDev(deps) {
  8244. {
  8245. if (deps !== undefined && deps !== null && !Array.isArray(deps)) {
  8246. // Verify deps, but only on mount to avoid extra checks.
  8247. // It's unlikely their type would change as usually you define them inline.
  8248. error(
  8249. "%s received a final argument that is not an array (instead, received `%s`). When " +
  8250. "specified, the final argument must be an array.",
  8251. currentHookNameInDev,
  8252. typeof deps
  8253. );
  8254. }
  8255. }
  8256. }
  8257. function warnOnHookMismatchInDev(currentHookName) {
  8258. {
  8259. var componentName = getComponentName(currentlyRenderingFiber$1.type);
  8260. if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
  8261. didWarnAboutMismatchedHooksForComponent.add(componentName);
  8262. if (hookTypesDev !== null) {
  8263. var table = "";
  8264. var secondColumnStart = 30;
  8265. for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
  8266. var oldHookName = hookTypesDev[i];
  8267. var newHookName =
  8268. i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
  8269. var row = i + 1 + ". " + oldHookName; // Extra space so second column lines up
  8270. // lol @ IE not supporting String#repeat
  8271. while (row.length < secondColumnStart) {
  8272. row += " ";
  8273. }
  8274. row += newHookName + "\n";
  8275. table += row;
  8276. }
  8277. error(
  8278. "React has detected a change in the order of Hooks called by %s. " +
  8279. "This will lead to bugs and errors if not fixed. " +
  8280. "For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks\n\n" +
  8281. " Previous render Next render\n" +
  8282. " ------------------------------------------------------\n" +
  8283. "%s" +
  8284. " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
  8285. componentName,
  8286. table
  8287. );
  8288. }
  8289. }
  8290. }
  8291. }
  8292. function throwInvalidHookError() {
  8293. {
  8294. throw Error(
  8295. "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."
  8296. );
  8297. }
  8298. }
  8299. function areHookInputsEqual(nextDeps, prevDeps) {
  8300. {
  8301. if (ignorePreviousDependencies) {
  8302. // Only true when this component is being hot reloaded.
  8303. return false;
  8304. }
  8305. }
  8306. if (prevDeps === null) {
  8307. {
  8308. error(
  8309. "%s received a final argument during this render, but not during " +
  8310. "the previous render. Even though the final argument is optional, " +
  8311. "its type cannot change between renders.",
  8312. currentHookNameInDev
  8313. );
  8314. }
  8315. return false;
  8316. }
  8317. {
  8318. // Don't bother comparing lengths in prod because these arrays should be
  8319. // passed inline.
  8320. if (nextDeps.length !== prevDeps.length) {
  8321. error(
  8322. "The final argument passed to %s changed size between renders. The " +
  8323. "order and size of this array must remain constant.\n\n" +
  8324. "Previous: %s\n" +
  8325. "Incoming: %s",
  8326. currentHookNameInDev,
  8327. "[" + prevDeps.join(", ") + "]",
  8328. "[" + nextDeps.join(", ") + "]"
  8329. );
  8330. }
  8331. }
  8332. for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
  8333. if (objectIs(nextDeps[i], prevDeps[i])) {
  8334. continue;
  8335. }
  8336. return false;
  8337. }
  8338. return true;
  8339. }
  8340. function renderWithHooks(
  8341. current,
  8342. workInProgress,
  8343. Component,
  8344. props,
  8345. secondArg,
  8346. nextRenderExpirationTime
  8347. ) {
  8348. renderExpirationTime = nextRenderExpirationTime;
  8349. currentlyRenderingFiber$1 = workInProgress;
  8350. {
  8351. hookTypesDev = current !== null ? current._debugHookTypes : null;
  8352. hookTypesUpdateIndexDev = -1; // Used for hot reloading:
  8353. ignorePreviousDependencies =
  8354. current !== null && current.type !== workInProgress.type;
  8355. }
  8356. workInProgress.memoizedState = null;
  8357. workInProgress.updateQueue = null;
  8358. workInProgress.expirationTime = NoWork; // The following should have already been reset
  8359. // currentHook = null;
  8360. // workInProgressHook = null;
  8361. // didScheduleRenderPhaseUpdate = false;
  8362. // TODO Warn if no hooks are used at all during mount, then some are used during update.
  8363. // Currently we will identify the update render as a mount because memoizedState === null.
  8364. // This is tricky because it's valid for certain types of components (e.g. React.lazy)
  8365. // Using memoizedState to differentiate between mount/update only works if at least one stateful hook is used.
  8366. // Non-stateful hooks (e.g. context) don't get added to memoizedState,
  8367. // so memoizedState would be null during updates and mounts.
  8368. {
  8369. if (current !== null && current.memoizedState !== null) {
  8370. ReactCurrentDispatcher.current = HooksDispatcherOnUpdateInDEV;
  8371. } else if (hookTypesDev !== null) {
  8372. // This dispatcher handles an edge case where a component is updating,
  8373. // but no stateful hooks have been used.
  8374. // We want to match the production code behavior (which will use HooksDispatcherOnMount),
  8375. // but with the extra DEV validation to ensure hooks ordering hasn't changed.
  8376. // This dispatcher does that.
  8377. ReactCurrentDispatcher.current = HooksDispatcherOnMountWithHookTypesInDEV;
  8378. } else {
  8379. ReactCurrentDispatcher.current = HooksDispatcherOnMountInDEV;
  8380. }
  8381. }
  8382. var children = Component(props, secondArg); // Check if there was a render phase update
  8383. if (workInProgress.expirationTime === renderExpirationTime) {
  8384. // Keep rendering in a loop for as long as render phase updates continue to
  8385. // be scheduled. Use a counter to prevent infinite loops.
  8386. var numberOfReRenders = 0;
  8387. do {
  8388. workInProgress.expirationTime = NoWork;
  8389. if (!(numberOfReRenders < RE_RENDER_LIMIT)) {
  8390. throw Error(
  8391. "Too many re-renders. React limits the number of renders to prevent an infinite loop."
  8392. );
  8393. }
  8394. numberOfReRenders += 1;
  8395. {
  8396. // Even when hot reloading, allow dependencies to stabilize
  8397. // after first render to prevent infinite render phase updates.
  8398. ignorePreviousDependencies = false;
  8399. } // Start over from the beginning of the list
  8400. currentHook = null;
  8401. workInProgressHook = null;
  8402. workInProgress.updateQueue = null;
  8403. {
  8404. // Also validate hook order for cascading updates.
  8405. hookTypesUpdateIndexDev = -1;
  8406. }
  8407. ReactCurrentDispatcher.current = HooksDispatcherOnRerenderInDEV;
  8408. children = Component(props, secondArg);
  8409. } while (workInProgress.expirationTime === renderExpirationTime);
  8410. } // We can assume the previous dispatcher is always this one, since we set it
  8411. // at the beginning of the render phase and there's no re-entrancy.
  8412. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  8413. {
  8414. workInProgress._debugHookTypes = hookTypesDev;
  8415. } // This check uses currentHook so that it works the same in DEV and prod bundles.
  8416. // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
  8417. var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
  8418. renderExpirationTime = NoWork;
  8419. currentlyRenderingFiber$1 = null;
  8420. currentHook = null;
  8421. workInProgressHook = null;
  8422. {
  8423. currentHookNameInDev = null;
  8424. hookTypesDev = null;
  8425. hookTypesUpdateIndexDev = -1;
  8426. }
  8427. didScheduleRenderPhaseUpdate = false;
  8428. if (!!didRenderTooFewHooks) {
  8429. throw Error(
  8430. "Rendered fewer hooks than expected. This may be caused by an accidental early return statement."
  8431. );
  8432. }
  8433. return children;
  8434. }
  8435. function bailoutHooks(current, workInProgress, expirationTime) {
  8436. workInProgress.updateQueue = current.updateQueue;
  8437. workInProgress.effectTag &= ~(Passive | Update);
  8438. if (current.expirationTime <= expirationTime) {
  8439. current.expirationTime = NoWork;
  8440. }
  8441. }
  8442. function resetHooksAfterThrow() {
  8443. // We can assume the previous dispatcher is always this one, since we set it
  8444. // at the beginning of the render phase and there's no re-entrancy.
  8445. ReactCurrentDispatcher.current = ContextOnlyDispatcher;
  8446. if (didScheduleRenderPhaseUpdate) {
  8447. // There were render phase updates. These are only valid for this render
  8448. // phase, which we are now aborting. Remove the updates from the queues so
  8449. // they do not persist to the next render. Do not remove updates from hooks
  8450. // that weren't processed.
  8451. //
  8452. // Only reset the updates from the queue if it has a clone. If it does
  8453. // not have a clone, that means it wasn't processed, and the updates were
  8454. // scheduled before we entered the render phase.
  8455. var hook = currentlyRenderingFiber$1.memoizedState;
  8456. while (hook !== null) {
  8457. var queue = hook.queue;
  8458. if (queue !== null) {
  8459. queue.pending = null;
  8460. }
  8461. hook = hook.next;
  8462. }
  8463. }
  8464. renderExpirationTime = NoWork;
  8465. currentlyRenderingFiber$1 = null;
  8466. currentHook = null;
  8467. workInProgressHook = null;
  8468. {
  8469. hookTypesDev = null;
  8470. hookTypesUpdateIndexDev = -1;
  8471. currentHookNameInDev = null;
  8472. }
  8473. didScheduleRenderPhaseUpdate = false;
  8474. }
  8475. function mountWorkInProgressHook() {
  8476. var hook = {
  8477. memoizedState: null,
  8478. baseState: null,
  8479. baseQueue: null,
  8480. queue: null,
  8481. next: null
  8482. };
  8483. if (workInProgressHook === null) {
  8484. // This is the first hook in the list
  8485. currentlyRenderingFiber$1.memoizedState = workInProgressHook = hook;
  8486. } else {
  8487. // Append to the end of the list
  8488. workInProgressHook = workInProgressHook.next = hook;
  8489. }
  8490. return workInProgressHook;
  8491. }
  8492. function updateWorkInProgressHook() {
  8493. // This function is used both for updates and for re-renders triggered by a
  8494. // render phase update. It assumes there is either a current hook we can
  8495. // clone, or a work-in-progress hook from a previous render pass that we can
  8496. // use as a base. When we reach the end of the base list, we must switch to
  8497. // the dispatcher used for mounts.
  8498. var nextCurrentHook;
  8499. if (currentHook === null) {
  8500. var current = currentlyRenderingFiber$1.alternate;
  8501. if (current !== null) {
  8502. nextCurrentHook = current.memoizedState;
  8503. } else {
  8504. nextCurrentHook = null;
  8505. }
  8506. } else {
  8507. nextCurrentHook = currentHook.next;
  8508. }
  8509. var nextWorkInProgressHook;
  8510. if (workInProgressHook === null) {
  8511. nextWorkInProgressHook = currentlyRenderingFiber$1.memoizedState;
  8512. } else {
  8513. nextWorkInProgressHook = workInProgressHook.next;
  8514. }
  8515. if (nextWorkInProgressHook !== null) {
  8516. // There's already a work-in-progress. Reuse it.
  8517. workInProgressHook = nextWorkInProgressHook;
  8518. nextWorkInProgressHook = workInProgressHook.next;
  8519. currentHook = nextCurrentHook;
  8520. } else {
  8521. // Clone from the current hook.
  8522. if (!(nextCurrentHook !== null)) {
  8523. throw Error("Rendered more hooks than during the previous render.");
  8524. }
  8525. currentHook = nextCurrentHook;
  8526. var newHook = {
  8527. memoizedState: currentHook.memoizedState,
  8528. baseState: currentHook.baseState,
  8529. baseQueue: currentHook.baseQueue,
  8530. queue: currentHook.queue,
  8531. next: null
  8532. };
  8533. if (workInProgressHook === null) {
  8534. // This is the first hook in the list.
  8535. currentlyRenderingFiber$1.memoizedState = workInProgressHook = newHook;
  8536. } else {
  8537. // Append to the end of the list.
  8538. workInProgressHook = workInProgressHook.next = newHook;
  8539. }
  8540. }
  8541. return workInProgressHook;
  8542. }
  8543. function createFunctionComponentUpdateQueue() {
  8544. return {
  8545. lastEffect: null
  8546. };
  8547. }
  8548. function basicStateReducer(state, action) {
  8549. // $FlowFixMe: Flow doesn't like mixed types
  8550. return typeof action === "function" ? action(state) : action;
  8551. }
  8552. function mountReducer(reducer, initialArg, init) {
  8553. var hook = mountWorkInProgressHook();
  8554. var initialState;
  8555. if (init !== undefined) {
  8556. initialState = init(initialArg);
  8557. } else {
  8558. initialState = initialArg;
  8559. }
  8560. hook.memoizedState = hook.baseState = initialState;
  8561. var queue = (hook.queue = {
  8562. pending: null,
  8563. dispatch: null,
  8564. lastRenderedReducer: reducer,
  8565. lastRenderedState: initialState
  8566. });
  8567. var dispatch = (queue.dispatch = dispatchAction.bind(
  8568. null,
  8569. currentlyRenderingFiber$1,
  8570. queue
  8571. ));
  8572. return [hook.memoizedState, dispatch];
  8573. }
  8574. function updateReducer(reducer, initialArg, init) {
  8575. var hook = updateWorkInProgressHook();
  8576. var queue = hook.queue;
  8577. if (!(queue !== null)) {
  8578. throw Error(
  8579. "Should have a queue. This is likely a bug in React. Please file an issue."
  8580. );
  8581. }
  8582. queue.lastRenderedReducer = reducer;
  8583. var current = currentHook; // The last rebase update that is NOT part of the base state.
  8584. var baseQueue = current.baseQueue; // The last pending update that hasn't been processed yet.
  8585. var pendingQueue = queue.pending;
  8586. if (pendingQueue !== null) {
  8587. // We have new updates that haven't been processed yet.
  8588. // We'll add them to the base queue.
  8589. if (baseQueue !== null) {
  8590. // Merge the pending queue and the base queue.
  8591. var baseFirst = baseQueue.next;
  8592. var pendingFirst = pendingQueue.next;
  8593. baseQueue.next = pendingFirst;
  8594. pendingQueue.next = baseFirst;
  8595. }
  8596. current.baseQueue = baseQueue = pendingQueue;
  8597. queue.pending = null;
  8598. }
  8599. if (baseQueue !== null) {
  8600. // We have a queue to process.
  8601. var first = baseQueue.next;
  8602. var newState = current.baseState;
  8603. var newBaseState = null;
  8604. var newBaseQueueFirst = null;
  8605. var newBaseQueueLast = null;
  8606. var update = first;
  8607. do {
  8608. var updateExpirationTime = update.expirationTime;
  8609. if (updateExpirationTime < renderExpirationTime) {
  8610. // Priority is insufficient. Skip this update. If this is the first
  8611. // skipped update, the previous update/state is the new base
  8612. // update/state.
  8613. var clone = {
  8614. expirationTime: update.expirationTime,
  8615. suspenseConfig: update.suspenseConfig,
  8616. action: update.action,
  8617. eagerReducer: update.eagerReducer,
  8618. eagerState: update.eagerState,
  8619. next: null
  8620. };
  8621. if (newBaseQueueLast === null) {
  8622. newBaseQueueFirst = newBaseQueueLast = clone;
  8623. newBaseState = newState;
  8624. } else {
  8625. newBaseQueueLast = newBaseQueueLast.next = clone;
  8626. } // Update the remaining priority in the queue.
  8627. if (updateExpirationTime > currentlyRenderingFiber$1.expirationTime) {
  8628. currentlyRenderingFiber$1.expirationTime = updateExpirationTime;
  8629. markUnprocessedUpdateTime(updateExpirationTime);
  8630. }
  8631. } else {
  8632. // This update does have sufficient priority.
  8633. if (newBaseQueueLast !== null) {
  8634. var _clone = {
  8635. expirationTime: Sync,
  8636. // This update is going to be committed so we never want uncommit it.
  8637. suspenseConfig: update.suspenseConfig,
  8638. action: update.action,
  8639. eagerReducer: update.eagerReducer,
  8640. eagerState: update.eagerState,
  8641. next: null
  8642. };
  8643. newBaseQueueLast = newBaseQueueLast.next = _clone;
  8644. } // Mark the event time of this update as relevant to this render pass.
  8645. // TODO: This should ideally use the true event time of this update rather than
  8646. // its priority which is a derived and not reverseable value.
  8647. // TODO: We should skip this update if it was already committed but currently
  8648. // we have no way of detecting the difference between a committed and suspended
  8649. // update here.
  8650. markRenderEventTimeAndConfig(
  8651. updateExpirationTime,
  8652. update.suspenseConfig
  8653. ); // Process this update.
  8654. if (update.eagerReducer === reducer) {
  8655. // If this update was processed eagerly, and its reducer matches the
  8656. // current reducer, we can use the eagerly computed state.
  8657. newState = update.eagerState;
  8658. } else {
  8659. var action = update.action;
  8660. newState = reducer(newState, action);
  8661. }
  8662. }
  8663. update = update.next;
  8664. } while (update !== null && update !== first);
  8665. if (newBaseQueueLast === null) {
  8666. newBaseState = newState;
  8667. } else {
  8668. newBaseQueueLast.next = newBaseQueueFirst;
  8669. } // Mark that the fiber performed work, but only if the new state is
  8670. // different from the current state.
  8671. if (!objectIs(newState, hook.memoizedState)) {
  8672. markWorkInProgressReceivedUpdate();
  8673. }
  8674. hook.memoizedState = newState;
  8675. hook.baseState = newBaseState;
  8676. hook.baseQueue = newBaseQueueLast;
  8677. queue.lastRenderedState = newState;
  8678. }
  8679. var dispatch = queue.dispatch;
  8680. return [hook.memoizedState, dispatch];
  8681. }
  8682. function rerenderReducer(reducer, initialArg, init) {
  8683. var hook = updateWorkInProgressHook();
  8684. var queue = hook.queue;
  8685. if (!(queue !== null)) {
  8686. throw Error(
  8687. "Should have a queue. This is likely a bug in React. Please file an issue."
  8688. );
  8689. }
  8690. queue.lastRenderedReducer = reducer; // This is a re-render. Apply the new render phase updates to the previous
  8691. // work-in-progress hook.
  8692. var dispatch = queue.dispatch;
  8693. var lastRenderPhaseUpdate = queue.pending;
  8694. var newState = hook.memoizedState;
  8695. if (lastRenderPhaseUpdate !== null) {
  8696. // The queue doesn't persist past this render pass.
  8697. queue.pending = null;
  8698. var firstRenderPhaseUpdate = lastRenderPhaseUpdate.next;
  8699. var update = firstRenderPhaseUpdate;
  8700. do {
  8701. // Process this render phase update. We don't have to check the
  8702. // priority because it will always be the same as the current
  8703. // render's.
  8704. var action = update.action;
  8705. newState = reducer(newState, action);
  8706. update = update.next;
  8707. } while (update !== firstRenderPhaseUpdate); // Mark that the fiber performed work, but only if the new state is
  8708. // different from the current state.
  8709. if (!objectIs(newState, hook.memoizedState)) {
  8710. markWorkInProgressReceivedUpdate();
  8711. }
  8712. hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
  8713. // the base state unless the queue is empty.
  8714. // TODO: Not sure if this is the desired semantics, but it's what we
  8715. // do for gDSFP. I can't remember why.
  8716. if (hook.baseQueue === null) {
  8717. hook.baseState = newState;
  8718. }
  8719. queue.lastRenderedState = newState;
  8720. }
  8721. return [newState, dispatch];
  8722. }
  8723. function mountState(initialState) {
  8724. var hook = mountWorkInProgressHook();
  8725. if (typeof initialState === "function") {
  8726. // $FlowFixMe: Flow doesn't like mixed types
  8727. initialState = initialState();
  8728. }
  8729. hook.memoizedState = hook.baseState = initialState;
  8730. var queue = (hook.queue = {
  8731. pending: null,
  8732. dispatch: null,
  8733. lastRenderedReducer: basicStateReducer,
  8734. lastRenderedState: initialState
  8735. });
  8736. var dispatch = (queue.dispatch = dispatchAction.bind(
  8737. null,
  8738. currentlyRenderingFiber$1,
  8739. queue
  8740. ));
  8741. return [hook.memoizedState, dispatch];
  8742. }
  8743. function updateState(initialState) {
  8744. return updateReducer(basicStateReducer);
  8745. }
  8746. function rerenderState(initialState) {
  8747. return rerenderReducer(basicStateReducer);
  8748. }
  8749. function pushEffect(tag, create, destroy, deps) {
  8750. var effect = {
  8751. tag: tag,
  8752. create: create,
  8753. destroy: destroy,
  8754. deps: deps,
  8755. // Circular
  8756. next: null
  8757. };
  8758. var componentUpdateQueue = currentlyRenderingFiber$1.updateQueue;
  8759. if (componentUpdateQueue === null) {
  8760. componentUpdateQueue = createFunctionComponentUpdateQueue();
  8761. currentlyRenderingFiber$1.updateQueue = componentUpdateQueue;
  8762. componentUpdateQueue.lastEffect = effect.next = effect;
  8763. } else {
  8764. var lastEffect = componentUpdateQueue.lastEffect;
  8765. if (lastEffect === null) {
  8766. componentUpdateQueue.lastEffect = effect.next = effect;
  8767. } else {
  8768. var firstEffect = lastEffect.next;
  8769. lastEffect.next = effect;
  8770. effect.next = firstEffect;
  8771. componentUpdateQueue.lastEffect = effect;
  8772. }
  8773. }
  8774. return effect;
  8775. }
  8776. function mountRef(initialValue) {
  8777. var hook = mountWorkInProgressHook();
  8778. var ref = {
  8779. current: initialValue
  8780. };
  8781. {
  8782. Object.seal(ref);
  8783. }
  8784. hook.memoizedState = ref;
  8785. return ref;
  8786. }
  8787. function updateRef(initialValue) {
  8788. var hook = updateWorkInProgressHook();
  8789. return hook.memoizedState;
  8790. }
  8791. function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  8792. var hook = mountWorkInProgressHook();
  8793. var nextDeps = deps === undefined ? null : deps;
  8794. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  8795. hook.memoizedState = pushEffect(
  8796. HasEffect | hookEffectTag,
  8797. create,
  8798. undefined,
  8799. nextDeps
  8800. );
  8801. }
  8802. function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps) {
  8803. var hook = updateWorkInProgressHook();
  8804. var nextDeps = deps === undefined ? null : deps;
  8805. var destroy = undefined;
  8806. if (currentHook !== null) {
  8807. var prevEffect = currentHook.memoizedState;
  8808. destroy = prevEffect.destroy;
  8809. if (nextDeps !== null) {
  8810. var prevDeps = prevEffect.deps;
  8811. if (areHookInputsEqual(nextDeps, prevDeps)) {
  8812. pushEffect(hookEffectTag, create, destroy, nextDeps);
  8813. return;
  8814. }
  8815. }
  8816. }
  8817. currentlyRenderingFiber$1.effectTag |= fiberEffectTag;
  8818. hook.memoizedState = pushEffect(
  8819. HasEffect | hookEffectTag,
  8820. create,
  8821. destroy,
  8822. nextDeps
  8823. );
  8824. }
  8825. function mountEffect(create, deps) {
  8826. return mountEffectImpl(Update | Passive, Passive$1, create, deps);
  8827. }
  8828. function updateEffect(create, deps) {
  8829. return updateEffectImpl(Update | Passive, Passive$1, create, deps);
  8830. }
  8831. function mountLayoutEffect(create, deps) {
  8832. return mountEffectImpl(Update, Layout, create, deps);
  8833. }
  8834. function updateLayoutEffect(create, deps) {
  8835. return updateEffectImpl(Update, Layout, create, deps);
  8836. }
  8837. function imperativeHandleEffect(create, ref) {
  8838. if (typeof ref === "function") {
  8839. var refCallback = ref;
  8840. var _inst = create();
  8841. refCallback(_inst);
  8842. return function() {
  8843. refCallback(null);
  8844. };
  8845. } else if (ref !== null && ref !== undefined) {
  8846. var refObject = ref;
  8847. {
  8848. if (!refObject.hasOwnProperty("current")) {
  8849. error(
  8850. "Expected useImperativeHandle() first argument to either be a " +
  8851. "ref callback or React.createRef() object. Instead received: %s.",
  8852. "an object with keys {" + Object.keys(refObject).join(", ") + "}"
  8853. );
  8854. }
  8855. }
  8856. var _inst2 = create();
  8857. refObject.current = _inst2;
  8858. return function() {
  8859. refObject.current = null;
  8860. };
  8861. }
  8862. }
  8863. function mountImperativeHandle(ref, create, deps) {
  8864. {
  8865. if (typeof create !== "function") {
  8866. error(
  8867. "Expected useImperativeHandle() second argument to be a function " +
  8868. "that creates a handle. Instead received: %s.",
  8869. create !== null ? typeof create : "null"
  8870. );
  8871. }
  8872. } // TODO: If deps are provided, should we skip comparing the ref itself?
  8873. var effectDeps =
  8874. deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  8875. return mountEffectImpl(
  8876. Update,
  8877. Layout,
  8878. imperativeHandleEffect.bind(null, create, ref),
  8879. effectDeps
  8880. );
  8881. }
  8882. function updateImperativeHandle(ref, create, deps) {
  8883. {
  8884. if (typeof create !== "function") {
  8885. error(
  8886. "Expected useImperativeHandle() second argument to be a function " +
  8887. "that creates a handle. Instead received: %s.",
  8888. create !== null ? typeof create : "null"
  8889. );
  8890. }
  8891. } // TODO: If deps are provided, should we skip comparing the ref itself?
  8892. var effectDeps =
  8893. deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  8894. return updateEffectImpl(
  8895. Update,
  8896. Layout,
  8897. imperativeHandleEffect.bind(null, create, ref),
  8898. effectDeps
  8899. );
  8900. }
  8901. function mountDebugValue(value, formatterFn) {
  8902. // This hook is normally a no-op.
  8903. // The react-debug-hooks package injects its own implementation
  8904. // so that e.g. DevTools can display custom hook values.
  8905. }
  8906. var updateDebugValue = mountDebugValue;
  8907. function mountCallback(callback, deps) {
  8908. var hook = mountWorkInProgressHook();
  8909. var nextDeps = deps === undefined ? null : deps;
  8910. hook.memoizedState = [callback, nextDeps];
  8911. return callback;
  8912. }
  8913. function updateCallback(callback, deps) {
  8914. var hook = updateWorkInProgressHook();
  8915. var nextDeps = deps === undefined ? null : deps;
  8916. var prevState = hook.memoizedState;
  8917. if (prevState !== null) {
  8918. if (nextDeps !== null) {
  8919. var prevDeps = prevState[1];
  8920. if (areHookInputsEqual(nextDeps, prevDeps)) {
  8921. return prevState[0];
  8922. }
  8923. }
  8924. }
  8925. hook.memoizedState = [callback, nextDeps];
  8926. return callback;
  8927. }
  8928. function mountMemo(nextCreate, deps) {
  8929. var hook = mountWorkInProgressHook();
  8930. var nextDeps = deps === undefined ? null : deps;
  8931. var nextValue = nextCreate();
  8932. hook.memoizedState = [nextValue, nextDeps];
  8933. return nextValue;
  8934. }
  8935. function updateMemo(nextCreate, deps) {
  8936. var hook = updateWorkInProgressHook();
  8937. var nextDeps = deps === undefined ? null : deps;
  8938. var prevState = hook.memoizedState;
  8939. if (prevState !== null) {
  8940. // Assume these are defined. If they're not, areHookInputsEqual will warn.
  8941. if (nextDeps !== null) {
  8942. var prevDeps = prevState[1];
  8943. if (areHookInputsEqual(nextDeps, prevDeps)) {
  8944. return prevState[0];
  8945. }
  8946. }
  8947. }
  8948. var nextValue = nextCreate();
  8949. hook.memoizedState = [nextValue, nextDeps];
  8950. return nextValue;
  8951. }
  8952. function mountDeferredValue(value, config) {
  8953. var _mountState = mountState(value),
  8954. prevValue = _mountState[0],
  8955. setValue = _mountState[1];
  8956. mountEffect(
  8957. function() {
  8958. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  8959. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  8960. try {
  8961. setValue(value);
  8962. } finally {
  8963. ReactCurrentBatchConfig$1.suspense = previousConfig;
  8964. }
  8965. },
  8966. [value, config]
  8967. );
  8968. return prevValue;
  8969. }
  8970. function updateDeferredValue(value, config) {
  8971. var _updateState = updateState(),
  8972. prevValue = _updateState[0],
  8973. setValue = _updateState[1];
  8974. updateEffect(
  8975. function() {
  8976. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  8977. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  8978. try {
  8979. setValue(value);
  8980. } finally {
  8981. ReactCurrentBatchConfig$1.suspense = previousConfig;
  8982. }
  8983. },
  8984. [value, config]
  8985. );
  8986. return prevValue;
  8987. }
  8988. function rerenderDeferredValue(value, config) {
  8989. var _rerenderState = rerenderState(),
  8990. prevValue = _rerenderState[0],
  8991. setValue = _rerenderState[1];
  8992. updateEffect(
  8993. function() {
  8994. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  8995. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  8996. try {
  8997. setValue(value);
  8998. } finally {
  8999. ReactCurrentBatchConfig$1.suspense = previousConfig;
  9000. }
  9001. },
  9002. [value, config]
  9003. );
  9004. return prevValue;
  9005. }
  9006. function startTransition(setPending, config, callback) {
  9007. var priorityLevel = getCurrentPriorityLevel();
  9008. runWithPriority(
  9009. priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel,
  9010. function() {
  9011. setPending(true);
  9012. }
  9013. );
  9014. runWithPriority(
  9015. priorityLevel > NormalPriority ? NormalPriority : priorityLevel,
  9016. function() {
  9017. var previousConfig = ReactCurrentBatchConfig$1.suspense;
  9018. ReactCurrentBatchConfig$1.suspense = config === undefined ? null : config;
  9019. try {
  9020. setPending(false);
  9021. callback();
  9022. } finally {
  9023. ReactCurrentBatchConfig$1.suspense = previousConfig;
  9024. }
  9025. }
  9026. );
  9027. }
  9028. function mountTransition(config) {
  9029. var _mountState2 = mountState(false),
  9030. isPending = _mountState2[0],
  9031. setPending = _mountState2[1];
  9032. var start = mountCallback(startTransition.bind(null, setPending, config), [
  9033. setPending,
  9034. config
  9035. ]);
  9036. return [start, isPending];
  9037. }
  9038. function updateTransition(config) {
  9039. var _updateState2 = updateState(),
  9040. isPending = _updateState2[0],
  9041. setPending = _updateState2[1];
  9042. var start = updateCallback(startTransition.bind(null, setPending, config), [
  9043. setPending,
  9044. config
  9045. ]);
  9046. return [start, isPending];
  9047. }
  9048. function rerenderTransition(config) {
  9049. var _rerenderState2 = rerenderState(),
  9050. isPending = _rerenderState2[0],
  9051. setPending = _rerenderState2[1];
  9052. var start = updateCallback(startTransition.bind(null, setPending, config), [
  9053. setPending,
  9054. config
  9055. ]);
  9056. return [start, isPending];
  9057. }
  9058. function dispatchAction(fiber, queue, action) {
  9059. {
  9060. if (typeof arguments[3] === "function") {
  9061. error(
  9062. "State updates from the useState() and useReducer() Hooks don't support the " +
  9063. "second callback argument. To execute a side effect after " +
  9064. "rendering, declare it in the component body with useEffect()."
  9065. );
  9066. }
  9067. }
  9068. var currentTime = requestCurrentTimeForUpdate();
  9069. var suspenseConfig = requestCurrentSuspenseConfig();
  9070. var expirationTime = computeExpirationForFiber(
  9071. currentTime,
  9072. fiber,
  9073. suspenseConfig
  9074. );
  9075. var update = {
  9076. expirationTime: expirationTime,
  9077. suspenseConfig: suspenseConfig,
  9078. action: action,
  9079. eagerReducer: null,
  9080. eagerState: null,
  9081. next: null
  9082. };
  9083. {
  9084. update.priority = getCurrentPriorityLevel();
  9085. } // Append the update to the end of the list.
  9086. var pending = queue.pending;
  9087. if (pending === null) {
  9088. // This is the first update. Create a circular list.
  9089. update.next = update;
  9090. } else {
  9091. update.next = pending.next;
  9092. pending.next = update;
  9093. }
  9094. queue.pending = update;
  9095. var alternate = fiber.alternate;
  9096. if (
  9097. fiber === currentlyRenderingFiber$1 ||
  9098. (alternate !== null && alternate === currentlyRenderingFiber$1)
  9099. ) {
  9100. // This is a render phase update. Stash it in a lazily-created map of
  9101. // queue -> linked list of updates. After this render pass, we'll restart
  9102. // and apply the stashed updates on top of the work-in-progress hook.
  9103. didScheduleRenderPhaseUpdate = true;
  9104. update.expirationTime = renderExpirationTime;
  9105. currentlyRenderingFiber$1.expirationTime = renderExpirationTime;
  9106. } else {
  9107. if (
  9108. fiber.expirationTime === NoWork &&
  9109. (alternate === null || alternate.expirationTime === NoWork)
  9110. ) {
  9111. // The queue is currently empty, which means we can eagerly compute the
  9112. // next state before entering the render phase. If the new state is the
  9113. // same as the current state, we may be able to bail out entirely.
  9114. var lastRenderedReducer = queue.lastRenderedReducer;
  9115. if (lastRenderedReducer !== null) {
  9116. var prevDispatcher;
  9117. {
  9118. prevDispatcher = ReactCurrentDispatcher.current;
  9119. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9120. }
  9121. try {
  9122. var currentState = queue.lastRenderedState;
  9123. var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
  9124. // it, on the update object. If the reducer hasn't changed by the
  9125. // time we enter the render phase, then the eager state can be used
  9126. // without calling the reducer again.
  9127. update.eagerReducer = lastRenderedReducer;
  9128. update.eagerState = eagerState;
  9129. if (objectIs(eagerState, currentState)) {
  9130. // Fast path. We can bail out without scheduling React to re-render.
  9131. // It's still possible that we'll need to rebase this update later,
  9132. // if the component re-renders for a different reason and by that
  9133. // time the reducer has changed.
  9134. return;
  9135. }
  9136. } catch (error) {
  9137. // Suppress the error. It will throw again in the render phase.
  9138. } finally {
  9139. {
  9140. ReactCurrentDispatcher.current = prevDispatcher;
  9141. }
  9142. }
  9143. }
  9144. }
  9145. scheduleWork(fiber, expirationTime);
  9146. }
  9147. }
  9148. function mountEventListener(event) {
  9149. return undefined;
  9150. }
  9151. function updateEventListener(event) {
  9152. return undefined;
  9153. }
  9154. var ContextOnlyDispatcher = {
  9155. readContext: readContext,
  9156. useCallback: throwInvalidHookError,
  9157. useContext: throwInvalidHookError,
  9158. useEffect: throwInvalidHookError,
  9159. useImperativeHandle: throwInvalidHookError,
  9160. useLayoutEffect: throwInvalidHookError,
  9161. useMemo: throwInvalidHookError,
  9162. useReducer: throwInvalidHookError,
  9163. useRef: throwInvalidHookError,
  9164. useState: throwInvalidHookError,
  9165. useDebugValue: throwInvalidHookError,
  9166. useResponder: throwInvalidHookError,
  9167. useDeferredValue: throwInvalidHookError,
  9168. useTransition: throwInvalidHookError,
  9169. useEvent: throwInvalidHookError
  9170. };
  9171. var HooksDispatcherOnMountInDEV = null;
  9172. var HooksDispatcherOnMountWithHookTypesInDEV = null;
  9173. var HooksDispatcherOnUpdateInDEV = null;
  9174. var HooksDispatcherOnRerenderInDEV = null;
  9175. var InvalidNestedHooksDispatcherOnMountInDEV = null;
  9176. var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
  9177. var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
  9178. {
  9179. var warnInvalidContextAccess = function() {
  9180. error(
  9181. "Context can only be read while React is rendering. " +
  9182. "In classes, you can read it in the render method or getDerivedStateFromProps. " +
  9183. "In function components, you can read it directly in the function body, but not " +
  9184. "inside Hooks like useReducer() or useMemo()."
  9185. );
  9186. };
  9187. var warnInvalidHookAccess = function() {
  9188. error(
  9189. "Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. " +
  9190. "You can only call Hooks at the top level of your React function. " +
  9191. "For more information, see " +
  9192. "https://fb.me/rules-of-hooks"
  9193. );
  9194. };
  9195. HooksDispatcherOnMountInDEV = {
  9196. readContext: function(context, observedBits) {
  9197. return readContext(context, observedBits);
  9198. },
  9199. useCallback: function(callback, deps) {
  9200. currentHookNameInDev = "useCallback";
  9201. mountHookTypesDev();
  9202. checkDepsAreArrayDev(deps);
  9203. return mountCallback(callback, deps);
  9204. },
  9205. useContext: function(context, observedBits) {
  9206. currentHookNameInDev = "useContext";
  9207. mountHookTypesDev();
  9208. return readContext(context, observedBits);
  9209. },
  9210. useEffect: function(create, deps) {
  9211. currentHookNameInDev = "useEffect";
  9212. mountHookTypesDev();
  9213. checkDepsAreArrayDev(deps);
  9214. return mountEffect(create, deps);
  9215. },
  9216. useImperativeHandle: function(ref, create, deps) {
  9217. currentHookNameInDev = "useImperativeHandle";
  9218. mountHookTypesDev();
  9219. checkDepsAreArrayDev(deps);
  9220. return mountImperativeHandle(ref, create, deps);
  9221. },
  9222. useLayoutEffect: function(create, deps) {
  9223. currentHookNameInDev = "useLayoutEffect";
  9224. mountHookTypesDev();
  9225. checkDepsAreArrayDev(deps);
  9226. return mountLayoutEffect(create, deps);
  9227. },
  9228. useMemo: function(create, deps) {
  9229. currentHookNameInDev = "useMemo";
  9230. mountHookTypesDev();
  9231. checkDepsAreArrayDev(deps);
  9232. var prevDispatcher = ReactCurrentDispatcher.current;
  9233. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9234. try {
  9235. return mountMemo(create, deps);
  9236. } finally {
  9237. ReactCurrentDispatcher.current = prevDispatcher;
  9238. }
  9239. },
  9240. useReducer: function(reducer, initialArg, init) {
  9241. currentHookNameInDev = "useReducer";
  9242. mountHookTypesDev();
  9243. var prevDispatcher = ReactCurrentDispatcher.current;
  9244. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9245. try {
  9246. return mountReducer(reducer, initialArg, init);
  9247. } finally {
  9248. ReactCurrentDispatcher.current = prevDispatcher;
  9249. }
  9250. },
  9251. useRef: function(initialValue) {
  9252. currentHookNameInDev = "useRef";
  9253. mountHookTypesDev();
  9254. return mountRef(initialValue);
  9255. },
  9256. useState: function(initialState) {
  9257. currentHookNameInDev = "useState";
  9258. mountHookTypesDev();
  9259. var prevDispatcher = ReactCurrentDispatcher.current;
  9260. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9261. try {
  9262. return mountState(initialState);
  9263. } finally {
  9264. ReactCurrentDispatcher.current = prevDispatcher;
  9265. }
  9266. },
  9267. useDebugValue: function(value, formatterFn) {
  9268. currentHookNameInDev = "useDebugValue";
  9269. mountHookTypesDev();
  9270. return mountDebugValue();
  9271. },
  9272. useResponder: function(responder, props) {
  9273. currentHookNameInDev = "useResponder";
  9274. mountHookTypesDev();
  9275. return createDeprecatedResponderListener(responder, props);
  9276. },
  9277. useDeferredValue: function(value, config) {
  9278. currentHookNameInDev = "useDeferredValue";
  9279. mountHookTypesDev();
  9280. return mountDeferredValue(value, config);
  9281. },
  9282. useTransition: function(config) {
  9283. currentHookNameInDev = "useTransition";
  9284. mountHookTypesDev();
  9285. return mountTransition(config);
  9286. },
  9287. useEvent: function(event) {
  9288. currentHookNameInDev = "useEvent";
  9289. mountHookTypesDev();
  9290. return mountEventListener();
  9291. }
  9292. };
  9293. HooksDispatcherOnMountWithHookTypesInDEV = {
  9294. readContext: function(context, observedBits) {
  9295. return readContext(context, observedBits);
  9296. },
  9297. useCallback: function(callback, deps) {
  9298. currentHookNameInDev = "useCallback";
  9299. updateHookTypesDev();
  9300. return mountCallback(callback, deps);
  9301. },
  9302. useContext: function(context, observedBits) {
  9303. currentHookNameInDev = "useContext";
  9304. updateHookTypesDev();
  9305. return readContext(context, observedBits);
  9306. },
  9307. useEffect: function(create, deps) {
  9308. currentHookNameInDev = "useEffect";
  9309. updateHookTypesDev();
  9310. return mountEffect(create, deps);
  9311. },
  9312. useImperativeHandle: function(ref, create, deps) {
  9313. currentHookNameInDev = "useImperativeHandle";
  9314. updateHookTypesDev();
  9315. return mountImperativeHandle(ref, create, deps);
  9316. },
  9317. useLayoutEffect: function(create, deps) {
  9318. currentHookNameInDev = "useLayoutEffect";
  9319. updateHookTypesDev();
  9320. return mountLayoutEffect(create, deps);
  9321. },
  9322. useMemo: function(create, deps) {
  9323. currentHookNameInDev = "useMemo";
  9324. updateHookTypesDev();
  9325. var prevDispatcher = ReactCurrentDispatcher.current;
  9326. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9327. try {
  9328. return mountMemo(create, deps);
  9329. } finally {
  9330. ReactCurrentDispatcher.current = prevDispatcher;
  9331. }
  9332. },
  9333. useReducer: function(reducer, initialArg, init) {
  9334. currentHookNameInDev = "useReducer";
  9335. updateHookTypesDev();
  9336. var prevDispatcher = ReactCurrentDispatcher.current;
  9337. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9338. try {
  9339. return mountReducer(reducer, initialArg, init);
  9340. } finally {
  9341. ReactCurrentDispatcher.current = prevDispatcher;
  9342. }
  9343. },
  9344. useRef: function(initialValue) {
  9345. currentHookNameInDev = "useRef";
  9346. updateHookTypesDev();
  9347. return mountRef(initialValue);
  9348. },
  9349. useState: function(initialState) {
  9350. currentHookNameInDev = "useState";
  9351. updateHookTypesDev();
  9352. var prevDispatcher = ReactCurrentDispatcher.current;
  9353. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9354. try {
  9355. return mountState(initialState);
  9356. } finally {
  9357. ReactCurrentDispatcher.current = prevDispatcher;
  9358. }
  9359. },
  9360. useDebugValue: function(value, formatterFn) {
  9361. currentHookNameInDev = "useDebugValue";
  9362. updateHookTypesDev();
  9363. return mountDebugValue();
  9364. },
  9365. useResponder: function(responder, props) {
  9366. currentHookNameInDev = "useResponder";
  9367. updateHookTypesDev();
  9368. return createDeprecatedResponderListener(responder, props);
  9369. },
  9370. useDeferredValue: function(value, config) {
  9371. currentHookNameInDev = "useDeferredValue";
  9372. updateHookTypesDev();
  9373. return mountDeferredValue(value, config);
  9374. },
  9375. useTransition: function(config) {
  9376. currentHookNameInDev = "useTransition";
  9377. updateHookTypesDev();
  9378. return mountTransition(config);
  9379. },
  9380. useEvent: function(event) {
  9381. currentHookNameInDev = "useEvent";
  9382. updateHookTypesDev();
  9383. return mountEventListener();
  9384. }
  9385. };
  9386. HooksDispatcherOnUpdateInDEV = {
  9387. readContext: function(context, observedBits) {
  9388. return readContext(context, observedBits);
  9389. },
  9390. useCallback: function(callback, deps) {
  9391. currentHookNameInDev = "useCallback";
  9392. updateHookTypesDev();
  9393. return updateCallback(callback, deps);
  9394. },
  9395. useContext: function(context, observedBits) {
  9396. currentHookNameInDev = "useContext";
  9397. updateHookTypesDev();
  9398. return readContext(context, observedBits);
  9399. },
  9400. useEffect: function(create, deps) {
  9401. currentHookNameInDev = "useEffect";
  9402. updateHookTypesDev();
  9403. return updateEffect(create, deps);
  9404. },
  9405. useImperativeHandle: function(ref, create, deps) {
  9406. currentHookNameInDev = "useImperativeHandle";
  9407. updateHookTypesDev();
  9408. return updateImperativeHandle(ref, create, deps);
  9409. },
  9410. useLayoutEffect: function(create, deps) {
  9411. currentHookNameInDev = "useLayoutEffect";
  9412. updateHookTypesDev();
  9413. return updateLayoutEffect(create, deps);
  9414. },
  9415. useMemo: function(create, deps) {
  9416. currentHookNameInDev = "useMemo";
  9417. updateHookTypesDev();
  9418. var prevDispatcher = ReactCurrentDispatcher.current;
  9419. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9420. try {
  9421. return updateMemo(create, deps);
  9422. } finally {
  9423. ReactCurrentDispatcher.current = prevDispatcher;
  9424. }
  9425. },
  9426. useReducer: function(reducer, initialArg, init) {
  9427. currentHookNameInDev = "useReducer";
  9428. updateHookTypesDev();
  9429. var prevDispatcher = ReactCurrentDispatcher.current;
  9430. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9431. try {
  9432. return updateReducer(reducer, initialArg, init);
  9433. } finally {
  9434. ReactCurrentDispatcher.current = prevDispatcher;
  9435. }
  9436. },
  9437. useRef: function(initialValue) {
  9438. currentHookNameInDev = "useRef";
  9439. updateHookTypesDev();
  9440. return updateRef();
  9441. },
  9442. useState: function(initialState) {
  9443. currentHookNameInDev = "useState";
  9444. updateHookTypesDev();
  9445. var prevDispatcher = ReactCurrentDispatcher.current;
  9446. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9447. try {
  9448. return updateState(initialState);
  9449. } finally {
  9450. ReactCurrentDispatcher.current = prevDispatcher;
  9451. }
  9452. },
  9453. useDebugValue: function(value, formatterFn) {
  9454. currentHookNameInDev = "useDebugValue";
  9455. updateHookTypesDev();
  9456. return updateDebugValue();
  9457. },
  9458. useResponder: function(responder, props) {
  9459. currentHookNameInDev = "useResponder";
  9460. updateHookTypesDev();
  9461. return createDeprecatedResponderListener(responder, props);
  9462. },
  9463. useDeferredValue: function(value, config) {
  9464. currentHookNameInDev = "useDeferredValue";
  9465. updateHookTypesDev();
  9466. return updateDeferredValue(value, config);
  9467. },
  9468. useTransition: function(config) {
  9469. currentHookNameInDev = "useTransition";
  9470. updateHookTypesDev();
  9471. return updateTransition(config);
  9472. },
  9473. useEvent: function(event) {
  9474. currentHookNameInDev = "useEvent";
  9475. updateHookTypesDev();
  9476. return updateEventListener();
  9477. }
  9478. };
  9479. HooksDispatcherOnRerenderInDEV = {
  9480. readContext: function(context, observedBits) {
  9481. return readContext(context, observedBits);
  9482. },
  9483. useCallback: function(callback, deps) {
  9484. currentHookNameInDev = "useCallback";
  9485. updateHookTypesDev();
  9486. return updateCallback(callback, deps);
  9487. },
  9488. useContext: function(context, observedBits) {
  9489. currentHookNameInDev = "useContext";
  9490. updateHookTypesDev();
  9491. return readContext(context, observedBits);
  9492. },
  9493. useEffect: function(create, deps) {
  9494. currentHookNameInDev = "useEffect";
  9495. updateHookTypesDev();
  9496. return updateEffect(create, deps);
  9497. },
  9498. useImperativeHandle: function(ref, create, deps) {
  9499. currentHookNameInDev = "useImperativeHandle";
  9500. updateHookTypesDev();
  9501. return updateImperativeHandle(ref, create, deps);
  9502. },
  9503. useLayoutEffect: function(create, deps) {
  9504. currentHookNameInDev = "useLayoutEffect";
  9505. updateHookTypesDev();
  9506. return updateLayoutEffect(create, deps);
  9507. },
  9508. useMemo: function(create, deps) {
  9509. currentHookNameInDev = "useMemo";
  9510. updateHookTypesDev();
  9511. var prevDispatcher = ReactCurrentDispatcher.current;
  9512. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  9513. try {
  9514. return updateMemo(create, deps);
  9515. } finally {
  9516. ReactCurrentDispatcher.current = prevDispatcher;
  9517. }
  9518. },
  9519. useReducer: function(reducer, initialArg, init) {
  9520. currentHookNameInDev = "useReducer";
  9521. updateHookTypesDev();
  9522. var prevDispatcher = ReactCurrentDispatcher.current;
  9523. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  9524. try {
  9525. return rerenderReducer(reducer, initialArg, init);
  9526. } finally {
  9527. ReactCurrentDispatcher.current = prevDispatcher;
  9528. }
  9529. },
  9530. useRef: function(initialValue) {
  9531. currentHookNameInDev = "useRef";
  9532. updateHookTypesDev();
  9533. return updateRef();
  9534. },
  9535. useState: function(initialState) {
  9536. currentHookNameInDev = "useState";
  9537. updateHookTypesDev();
  9538. var prevDispatcher = ReactCurrentDispatcher.current;
  9539. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  9540. try {
  9541. return rerenderState(initialState);
  9542. } finally {
  9543. ReactCurrentDispatcher.current = prevDispatcher;
  9544. }
  9545. },
  9546. useDebugValue: function(value, formatterFn) {
  9547. currentHookNameInDev = "useDebugValue";
  9548. updateHookTypesDev();
  9549. return updateDebugValue();
  9550. },
  9551. useResponder: function(responder, props) {
  9552. currentHookNameInDev = "useResponder";
  9553. updateHookTypesDev();
  9554. return createDeprecatedResponderListener(responder, props);
  9555. },
  9556. useDeferredValue: function(value, config) {
  9557. currentHookNameInDev = "useDeferredValue";
  9558. updateHookTypesDev();
  9559. return rerenderDeferredValue(value, config);
  9560. },
  9561. useTransition: function(config) {
  9562. currentHookNameInDev = "useTransition";
  9563. updateHookTypesDev();
  9564. return rerenderTransition(config);
  9565. },
  9566. useEvent: function(event) {
  9567. currentHookNameInDev = "useEvent";
  9568. updateHookTypesDev();
  9569. return updateEventListener();
  9570. }
  9571. };
  9572. InvalidNestedHooksDispatcherOnMountInDEV = {
  9573. readContext: function(context, observedBits) {
  9574. warnInvalidContextAccess();
  9575. return readContext(context, observedBits);
  9576. },
  9577. useCallback: function(callback, deps) {
  9578. currentHookNameInDev = "useCallback";
  9579. warnInvalidHookAccess();
  9580. mountHookTypesDev();
  9581. return mountCallback(callback, deps);
  9582. },
  9583. useContext: function(context, observedBits) {
  9584. currentHookNameInDev = "useContext";
  9585. warnInvalidHookAccess();
  9586. mountHookTypesDev();
  9587. return readContext(context, observedBits);
  9588. },
  9589. useEffect: function(create, deps) {
  9590. currentHookNameInDev = "useEffect";
  9591. warnInvalidHookAccess();
  9592. mountHookTypesDev();
  9593. return mountEffect(create, deps);
  9594. },
  9595. useImperativeHandle: function(ref, create, deps) {
  9596. currentHookNameInDev = "useImperativeHandle";
  9597. warnInvalidHookAccess();
  9598. mountHookTypesDev();
  9599. return mountImperativeHandle(ref, create, deps);
  9600. },
  9601. useLayoutEffect: function(create, deps) {
  9602. currentHookNameInDev = "useLayoutEffect";
  9603. warnInvalidHookAccess();
  9604. mountHookTypesDev();
  9605. return mountLayoutEffect(create, deps);
  9606. },
  9607. useMemo: function(create, deps) {
  9608. currentHookNameInDev = "useMemo";
  9609. warnInvalidHookAccess();
  9610. mountHookTypesDev();
  9611. var prevDispatcher = ReactCurrentDispatcher.current;
  9612. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9613. try {
  9614. return mountMemo(create, deps);
  9615. } finally {
  9616. ReactCurrentDispatcher.current = prevDispatcher;
  9617. }
  9618. },
  9619. useReducer: function(reducer, initialArg, init) {
  9620. currentHookNameInDev = "useReducer";
  9621. warnInvalidHookAccess();
  9622. mountHookTypesDev();
  9623. var prevDispatcher = ReactCurrentDispatcher.current;
  9624. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9625. try {
  9626. return mountReducer(reducer, initialArg, init);
  9627. } finally {
  9628. ReactCurrentDispatcher.current = prevDispatcher;
  9629. }
  9630. },
  9631. useRef: function(initialValue) {
  9632. currentHookNameInDev = "useRef";
  9633. warnInvalidHookAccess();
  9634. mountHookTypesDev();
  9635. return mountRef(initialValue);
  9636. },
  9637. useState: function(initialState) {
  9638. currentHookNameInDev = "useState";
  9639. warnInvalidHookAccess();
  9640. mountHookTypesDev();
  9641. var prevDispatcher = ReactCurrentDispatcher.current;
  9642. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
  9643. try {
  9644. return mountState(initialState);
  9645. } finally {
  9646. ReactCurrentDispatcher.current = prevDispatcher;
  9647. }
  9648. },
  9649. useDebugValue: function(value, formatterFn) {
  9650. currentHookNameInDev = "useDebugValue";
  9651. warnInvalidHookAccess();
  9652. mountHookTypesDev();
  9653. return mountDebugValue();
  9654. },
  9655. useResponder: function(responder, props) {
  9656. currentHookNameInDev = "useResponder";
  9657. warnInvalidHookAccess();
  9658. mountHookTypesDev();
  9659. return createDeprecatedResponderListener(responder, props);
  9660. },
  9661. useDeferredValue: function(value, config) {
  9662. currentHookNameInDev = "useDeferredValue";
  9663. warnInvalidHookAccess();
  9664. mountHookTypesDev();
  9665. return mountDeferredValue(value, config);
  9666. },
  9667. useTransition: function(config) {
  9668. currentHookNameInDev = "useTransition";
  9669. warnInvalidHookAccess();
  9670. mountHookTypesDev();
  9671. return mountTransition(config);
  9672. },
  9673. useEvent: function(event) {
  9674. currentHookNameInDev = "useEvent";
  9675. warnInvalidHookAccess();
  9676. mountHookTypesDev();
  9677. return mountEventListener();
  9678. }
  9679. };
  9680. InvalidNestedHooksDispatcherOnUpdateInDEV = {
  9681. readContext: function(context, observedBits) {
  9682. warnInvalidContextAccess();
  9683. return readContext(context, observedBits);
  9684. },
  9685. useCallback: function(callback, deps) {
  9686. currentHookNameInDev = "useCallback";
  9687. warnInvalidHookAccess();
  9688. updateHookTypesDev();
  9689. return updateCallback(callback, deps);
  9690. },
  9691. useContext: function(context, observedBits) {
  9692. currentHookNameInDev = "useContext";
  9693. warnInvalidHookAccess();
  9694. updateHookTypesDev();
  9695. return readContext(context, observedBits);
  9696. },
  9697. useEffect: function(create, deps) {
  9698. currentHookNameInDev = "useEffect";
  9699. warnInvalidHookAccess();
  9700. updateHookTypesDev();
  9701. return updateEffect(create, deps);
  9702. },
  9703. useImperativeHandle: function(ref, create, deps) {
  9704. currentHookNameInDev = "useImperativeHandle";
  9705. warnInvalidHookAccess();
  9706. updateHookTypesDev();
  9707. return updateImperativeHandle(ref, create, deps);
  9708. },
  9709. useLayoutEffect: function(create, deps) {
  9710. currentHookNameInDev = "useLayoutEffect";
  9711. warnInvalidHookAccess();
  9712. updateHookTypesDev();
  9713. return updateLayoutEffect(create, deps);
  9714. },
  9715. useMemo: function(create, deps) {
  9716. currentHookNameInDev = "useMemo";
  9717. warnInvalidHookAccess();
  9718. updateHookTypesDev();
  9719. var prevDispatcher = ReactCurrentDispatcher.current;
  9720. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9721. try {
  9722. return updateMemo(create, deps);
  9723. } finally {
  9724. ReactCurrentDispatcher.current = prevDispatcher;
  9725. }
  9726. },
  9727. useReducer: function(reducer, initialArg, init) {
  9728. currentHookNameInDev = "useReducer";
  9729. warnInvalidHookAccess();
  9730. updateHookTypesDev();
  9731. var prevDispatcher = ReactCurrentDispatcher.current;
  9732. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9733. try {
  9734. return updateReducer(reducer, initialArg, init);
  9735. } finally {
  9736. ReactCurrentDispatcher.current = prevDispatcher;
  9737. }
  9738. },
  9739. useRef: function(initialValue) {
  9740. currentHookNameInDev = "useRef";
  9741. warnInvalidHookAccess();
  9742. updateHookTypesDev();
  9743. return updateRef();
  9744. },
  9745. useState: function(initialState) {
  9746. currentHookNameInDev = "useState";
  9747. warnInvalidHookAccess();
  9748. updateHookTypesDev();
  9749. var prevDispatcher = ReactCurrentDispatcher.current;
  9750. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9751. try {
  9752. return updateState(initialState);
  9753. } finally {
  9754. ReactCurrentDispatcher.current = prevDispatcher;
  9755. }
  9756. },
  9757. useDebugValue: function(value, formatterFn) {
  9758. currentHookNameInDev = "useDebugValue";
  9759. warnInvalidHookAccess();
  9760. updateHookTypesDev();
  9761. return updateDebugValue();
  9762. },
  9763. useResponder: function(responder, props) {
  9764. currentHookNameInDev = "useResponder";
  9765. warnInvalidHookAccess();
  9766. updateHookTypesDev();
  9767. return createDeprecatedResponderListener(responder, props);
  9768. },
  9769. useDeferredValue: function(value, config) {
  9770. currentHookNameInDev = "useDeferredValue";
  9771. warnInvalidHookAccess();
  9772. updateHookTypesDev();
  9773. return updateDeferredValue(value, config);
  9774. },
  9775. useTransition: function(config) {
  9776. currentHookNameInDev = "useTransition";
  9777. warnInvalidHookAccess();
  9778. updateHookTypesDev();
  9779. return updateTransition(config);
  9780. },
  9781. useEvent: function(event) {
  9782. currentHookNameInDev = "useEvent";
  9783. warnInvalidHookAccess();
  9784. updateHookTypesDev();
  9785. return updateEventListener();
  9786. }
  9787. };
  9788. InvalidNestedHooksDispatcherOnRerenderInDEV = {
  9789. readContext: function(context, observedBits) {
  9790. warnInvalidContextAccess();
  9791. return readContext(context, observedBits);
  9792. },
  9793. useCallback: function(callback, deps) {
  9794. currentHookNameInDev = "useCallback";
  9795. warnInvalidHookAccess();
  9796. updateHookTypesDev();
  9797. return updateCallback(callback, deps);
  9798. },
  9799. useContext: function(context, observedBits) {
  9800. currentHookNameInDev = "useContext";
  9801. warnInvalidHookAccess();
  9802. updateHookTypesDev();
  9803. return readContext(context, observedBits);
  9804. },
  9805. useEffect: function(create, deps) {
  9806. currentHookNameInDev = "useEffect";
  9807. warnInvalidHookAccess();
  9808. updateHookTypesDev();
  9809. return updateEffect(create, deps);
  9810. },
  9811. useImperativeHandle: function(ref, create, deps) {
  9812. currentHookNameInDev = "useImperativeHandle";
  9813. warnInvalidHookAccess();
  9814. updateHookTypesDev();
  9815. return updateImperativeHandle(ref, create, deps);
  9816. },
  9817. useLayoutEffect: function(create, deps) {
  9818. currentHookNameInDev = "useLayoutEffect";
  9819. warnInvalidHookAccess();
  9820. updateHookTypesDev();
  9821. return updateLayoutEffect(create, deps);
  9822. },
  9823. useMemo: function(create, deps) {
  9824. currentHookNameInDev = "useMemo";
  9825. warnInvalidHookAccess();
  9826. updateHookTypesDev();
  9827. var prevDispatcher = ReactCurrentDispatcher.current;
  9828. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9829. try {
  9830. return updateMemo(create, deps);
  9831. } finally {
  9832. ReactCurrentDispatcher.current = prevDispatcher;
  9833. }
  9834. },
  9835. useReducer: function(reducer, initialArg, init) {
  9836. currentHookNameInDev = "useReducer";
  9837. warnInvalidHookAccess();
  9838. updateHookTypesDev();
  9839. var prevDispatcher = ReactCurrentDispatcher.current;
  9840. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9841. try {
  9842. return rerenderReducer(reducer, initialArg, init);
  9843. } finally {
  9844. ReactCurrentDispatcher.current = prevDispatcher;
  9845. }
  9846. },
  9847. useRef: function(initialValue) {
  9848. currentHookNameInDev = "useRef";
  9849. warnInvalidHookAccess();
  9850. updateHookTypesDev();
  9851. return updateRef();
  9852. },
  9853. useState: function(initialState) {
  9854. currentHookNameInDev = "useState";
  9855. warnInvalidHookAccess();
  9856. updateHookTypesDev();
  9857. var prevDispatcher = ReactCurrentDispatcher.current;
  9858. ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  9859. try {
  9860. return rerenderState(initialState);
  9861. } finally {
  9862. ReactCurrentDispatcher.current = prevDispatcher;
  9863. }
  9864. },
  9865. useDebugValue: function(value, formatterFn) {
  9866. currentHookNameInDev = "useDebugValue";
  9867. warnInvalidHookAccess();
  9868. updateHookTypesDev();
  9869. return updateDebugValue();
  9870. },
  9871. useResponder: function(responder, props) {
  9872. currentHookNameInDev = "useResponder";
  9873. warnInvalidHookAccess();
  9874. updateHookTypesDev();
  9875. return createDeprecatedResponderListener(responder, props);
  9876. },
  9877. useDeferredValue: function(value, config) {
  9878. currentHookNameInDev = "useDeferredValue";
  9879. warnInvalidHookAccess();
  9880. updateHookTypesDev();
  9881. return rerenderDeferredValue(value, config);
  9882. },
  9883. useTransition: function(config) {
  9884. currentHookNameInDev = "useTransition";
  9885. warnInvalidHookAccess();
  9886. updateHookTypesDev();
  9887. return rerenderTransition(config);
  9888. },
  9889. useEvent: function(event) {
  9890. currentHookNameInDev = "useEvent";
  9891. warnInvalidHookAccess();
  9892. updateHookTypesDev();
  9893. return updateEventListener();
  9894. }
  9895. };
  9896. }
  9897. var now$1 = Scheduler.unstable_now;
  9898. var commitTime = 0;
  9899. var profilerStartTime = -1;
  9900. function getCommitTime() {
  9901. return commitTime;
  9902. }
  9903. function recordCommitTime() {
  9904. commitTime = now$1();
  9905. }
  9906. function startProfilerTimer(fiber) {
  9907. profilerStartTime = now$1();
  9908. if (fiber.actualStartTime < 0) {
  9909. fiber.actualStartTime = now$1();
  9910. }
  9911. }
  9912. function stopProfilerTimerIfRunning(fiber) {
  9913. profilerStartTime = -1;
  9914. }
  9915. function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
  9916. if (profilerStartTime >= 0) {
  9917. var elapsedTime = now$1() - profilerStartTime;
  9918. fiber.actualDuration += elapsedTime;
  9919. if (overrideBaseTime) {
  9920. fiber.selfBaseDuration = elapsedTime;
  9921. }
  9922. profilerStartTime = -1;
  9923. }
  9924. }
  9925. function enterHydrationState(fiber) {
  9926. {
  9927. return false;
  9928. }
  9929. }
  9930. function prepareToHydrateHostInstance(
  9931. fiber,
  9932. rootContainerInstance,
  9933. hostContext
  9934. ) {
  9935. {
  9936. {
  9937. throw Error(
  9938. "Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue."
  9939. );
  9940. }
  9941. }
  9942. }
  9943. function prepareToHydrateHostTextInstance(fiber) {
  9944. {
  9945. {
  9946. throw Error(
  9947. "Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue."
  9948. );
  9949. }
  9950. }
  9951. var shouldUpdate = hydrateTextInstance();
  9952. }
  9953. function popHydrationState(fiber) {
  9954. {
  9955. return false;
  9956. }
  9957. }
  9958. var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
  9959. var didReceiveUpdate = false;
  9960. var didWarnAboutBadClass;
  9961. var didWarnAboutModulePatternComponent;
  9962. var didWarnAboutContextTypeOnFunctionComponent;
  9963. var didWarnAboutGetDerivedStateOnFunctionComponent;
  9964. var didWarnAboutFunctionRefs;
  9965. var didWarnAboutReassigningProps;
  9966. var didWarnAboutRevealOrder;
  9967. var didWarnAboutTailOptions;
  9968. {
  9969. didWarnAboutBadClass = {};
  9970. didWarnAboutModulePatternComponent = {};
  9971. didWarnAboutContextTypeOnFunctionComponent = {};
  9972. didWarnAboutGetDerivedStateOnFunctionComponent = {};
  9973. didWarnAboutFunctionRefs = {};
  9974. didWarnAboutReassigningProps = false;
  9975. didWarnAboutRevealOrder = {};
  9976. didWarnAboutTailOptions = {};
  9977. }
  9978. function reconcileChildren(
  9979. current,
  9980. workInProgress,
  9981. nextChildren,
  9982. renderExpirationTime
  9983. ) {
  9984. if (current === null) {
  9985. // If this is a fresh new component that hasn't been rendered yet, we
  9986. // won't update its child set by applying minimal side-effects. Instead,
  9987. // we will add them all to the child before it gets rendered. That means
  9988. // we can optimize this reconciliation pass by not tracking side-effects.
  9989. workInProgress.child = mountChildFibers(
  9990. workInProgress,
  9991. null,
  9992. nextChildren,
  9993. renderExpirationTime
  9994. );
  9995. } else {
  9996. // If the current child is the same as the work in progress, it means that
  9997. // we haven't yet started any work on these children. Therefore, we use
  9998. // the clone algorithm to create a copy of all the current children.
  9999. // If we had any progressed work already, that is invalid at this point so
  10000. // let's throw it out.
  10001. workInProgress.child = reconcileChildFibers(
  10002. workInProgress,
  10003. current.child,
  10004. nextChildren,
  10005. renderExpirationTime
  10006. );
  10007. }
  10008. }
  10009. function forceUnmountCurrentAndReconcile(
  10010. current,
  10011. workInProgress,
  10012. nextChildren,
  10013. renderExpirationTime
  10014. ) {
  10015. // This function is fork of reconcileChildren. It's used in cases where we
  10016. // want to reconcile without matching against the existing set. This has the
  10017. // effect of all current children being unmounted; even if the type and key
  10018. // are the same, the old child is unmounted and a new child is created.
  10019. //
  10020. // To do this, we're going to go through the reconcile algorithm twice. In
  10021. // the first pass, we schedule a deletion for all the current children by
  10022. // passing null.
  10023. workInProgress.child = reconcileChildFibers(
  10024. workInProgress,
  10025. current.child,
  10026. null,
  10027. renderExpirationTime
  10028. ); // In the second pass, we mount the new children. The trick here is that we
  10029. // pass null in place of where we usually pass the current child set. This has
  10030. // the effect of remounting all children regardless of whether their
  10031. // identities match.
  10032. workInProgress.child = reconcileChildFibers(
  10033. workInProgress,
  10034. null,
  10035. nextChildren,
  10036. renderExpirationTime
  10037. );
  10038. }
  10039. function updateForwardRef(
  10040. current,
  10041. workInProgress,
  10042. Component,
  10043. nextProps,
  10044. renderExpirationTime
  10045. ) {
  10046. // TODO: current can be non-null here even if the component
  10047. // hasn't yet mounted. This happens after the first render suspends.
  10048. // We'll need to figure out if this is fine or can cause issues.
  10049. {
  10050. if (workInProgress.type !== workInProgress.elementType) {
  10051. // Lazy component props can't be validated in createElement
  10052. // because they're only guaranteed to be resolved here.
  10053. var innerPropTypes = Component.propTypes;
  10054. if (innerPropTypes) {
  10055. checkPropTypes(
  10056. innerPropTypes,
  10057. nextProps, // Resolved props
  10058. "prop",
  10059. getComponentName(Component)
  10060. );
  10061. }
  10062. }
  10063. }
  10064. var render = Component.render;
  10065. var ref = workInProgress.ref; // The rest is a fork of updateFunctionComponent
  10066. var nextChildren;
  10067. prepareToReadContext(workInProgress, renderExpirationTime);
  10068. {
  10069. ReactCurrentOwner$1.current = workInProgress;
  10070. setIsRendering(true);
  10071. nextChildren = renderWithHooks(
  10072. current,
  10073. workInProgress,
  10074. render,
  10075. nextProps,
  10076. ref,
  10077. renderExpirationTime
  10078. );
  10079. setIsRendering(false);
  10080. }
  10081. if (current !== null && !didReceiveUpdate) {
  10082. bailoutHooks(current, workInProgress, renderExpirationTime);
  10083. return bailoutOnAlreadyFinishedWork(
  10084. current,
  10085. workInProgress,
  10086. renderExpirationTime
  10087. );
  10088. } // React DevTools reads this flag.
  10089. workInProgress.effectTag |= PerformedWork;
  10090. reconcileChildren(
  10091. current,
  10092. workInProgress,
  10093. nextChildren,
  10094. renderExpirationTime
  10095. );
  10096. return workInProgress.child;
  10097. }
  10098. function updateMemoComponent(
  10099. current,
  10100. workInProgress,
  10101. Component,
  10102. nextProps,
  10103. updateExpirationTime,
  10104. renderExpirationTime
  10105. ) {
  10106. if (current === null) {
  10107. var type = Component.type;
  10108. if (
  10109. isSimpleFunctionComponent(type) &&
  10110. Component.compare === null && // SimpleMemoComponent codepath doesn't resolve outer props either.
  10111. Component.defaultProps === undefined
  10112. ) {
  10113. var resolvedType = type;
  10114. {
  10115. resolvedType = resolveFunctionForHotReloading(type);
  10116. } // If this is a plain function component without default props,
  10117. // and with only the default shallow comparison, we upgrade it
  10118. // to a SimpleMemoComponent to allow fast path updates.
  10119. workInProgress.tag = SimpleMemoComponent;
  10120. workInProgress.type = resolvedType;
  10121. {
  10122. validateFunctionComponentInDev(workInProgress, type);
  10123. }
  10124. return updateSimpleMemoComponent(
  10125. current,
  10126. workInProgress,
  10127. resolvedType,
  10128. nextProps,
  10129. updateExpirationTime,
  10130. renderExpirationTime
  10131. );
  10132. }
  10133. {
  10134. var innerPropTypes = type.propTypes;
  10135. if (innerPropTypes) {
  10136. // Inner memo component props aren't currently validated in createElement.
  10137. // We could move it there, but we'd still need this for lazy code path.
  10138. checkPropTypes(
  10139. innerPropTypes,
  10140. nextProps, // Resolved props
  10141. "prop",
  10142. getComponentName(type)
  10143. );
  10144. }
  10145. }
  10146. var child = createFiberFromTypeAndProps(
  10147. Component.type,
  10148. null,
  10149. nextProps,
  10150. null,
  10151. workInProgress.mode,
  10152. renderExpirationTime
  10153. );
  10154. child.ref = workInProgress.ref;
  10155. child.return = workInProgress;
  10156. workInProgress.child = child;
  10157. return child;
  10158. }
  10159. {
  10160. var _type = Component.type;
  10161. var _innerPropTypes = _type.propTypes;
  10162. if (_innerPropTypes) {
  10163. // Inner memo component props aren't currently validated in createElement.
  10164. // We could move it there, but we'd still need this for lazy code path.
  10165. checkPropTypes(
  10166. _innerPropTypes,
  10167. nextProps, // Resolved props
  10168. "prop",
  10169. getComponentName(_type)
  10170. );
  10171. }
  10172. }
  10173. var currentChild = current.child; // This is always exactly one child
  10174. if (updateExpirationTime < renderExpirationTime) {
  10175. // This will be the props with resolved defaultProps,
  10176. // unlike current.memoizedProps which will be the unresolved ones.
  10177. var prevProps = currentChild.memoizedProps; // Default to shallow comparison
  10178. var compare = Component.compare;
  10179. compare = compare !== null ? compare : shallowEqual;
  10180. if (compare(prevProps, nextProps) && current.ref === workInProgress.ref) {
  10181. return bailoutOnAlreadyFinishedWork(
  10182. current,
  10183. workInProgress,
  10184. renderExpirationTime
  10185. );
  10186. }
  10187. } // React DevTools reads this flag.
  10188. workInProgress.effectTag |= PerformedWork;
  10189. var newChild = createWorkInProgress(currentChild, nextProps);
  10190. newChild.ref = workInProgress.ref;
  10191. newChild.return = workInProgress;
  10192. workInProgress.child = newChild;
  10193. return newChild;
  10194. }
  10195. function updateSimpleMemoComponent(
  10196. current,
  10197. workInProgress,
  10198. Component,
  10199. nextProps,
  10200. updateExpirationTime,
  10201. renderExpirationTime
  10202. ) {
  10203. // TODO: current can be non-null here even if the component
  10204. // hasn't yet mounted. This happens when the inner render suspends.
  10205. // We'll need to figure out if this is fine or can cause issues.
  10206. {
  10207. if (workInProgress.type !== workInProgress.elementType) {
  10208. // Lazy component props can't be validated in createElement
  10209. // because they're only guaranteed to be resolved here.
  10210. var outerMemoType = workInProgress.elementType;
  10211. if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
  10212. // We warn when you define propTypes on lazy()
  10213. // so let's just skip over it to find memo() outer wrapper.
  10214. // Inner props for memo are validated later.
  10215. outerMemoType = refineResolvedLazyComponent(outerMemoType);
  10216. }
  10217. var outerPropTypes = outerMemoType && outerMemoType.propTypes;
  10218. if (outerPropTypes) {
  10219. checkPropTypes(
  10220. outerPropTypes,
  10221. nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
  10222. "prop",
  10223. getComponentName(outerMemoType)
  10224. );
  10225. } // Inner propTypes will be validated in the function component path.
  10226. }
  10227. }
  10228. if (current !== null) {
  10229. var prevProps = current.memoizedProps;
  10230. if (
  10231. shallowEqual(prevProps, nextProps) &&
  10232. current.ref === workInProgress.ref && // Prevent bailout if the implementation changed due to hot reload.
  10233. workInProgress.type === current.type
  10234. ) {
  10235. didReceiveUpdate = false;
  10236. if (updateExpirationTime < renderExpirationTime) {
  10237. // The pending update priority was cleared at the beginning of
  10238. // beginWork. We're about to bail out, but there might be additional
  10239. // updates at a lower priority. Usually, the priority level of the
  10240. // remaining updates is accumlated during the evaluation of the
  10241. // component (i.e. when processing the update queue). But since since
  10242. // we're bailing out early *without* evaluating the component, we need
  10243. // to account for it here, too. Reset to the value of the current fiber.
  10244. // NOTE: This only applies to SimpleMemoComponent, not MemoComponent,
  10245. // because a MemoComponent fiber does not have hooks or an update queue;
  10246. // rather, it wraps around an inner component, which may or may not
  10247. // contains hooks.
  10248. // TODO: Move the reset at in beginWork out of the common path so that
  10249. // this is no longer necessary.
  10250. workInProgress.expirationTime = current.expirationTime;
  10251. return bailoutOnAlreadyFinishedWork(
  10252. current,
  10253. workInProgress,
  10254. renderExpirationTime
  10255. );
  10256. }
  10257. }
  10258. }
  10259. return updateFunctionComponent(
  10260. current,
  10261. workInProgress,
  10262. Component,
  10263. nextProps,
  10264. renderExpirationTime
  10265. );
  10266. }
  10267. function updateFragment(current, workInProgress, renderExpirationTime) {
  10268. var nextChildren = workInProgress.pendingProps;
  10269. reconcileChildren(
  10270. current,
  10271. workInProgress,
  10272. nextChildren,
  10273. renderExpirationTime
  10274. );
  10275. return workInProgress.child;
  10276. }
  10277. function updateMode(current, workInProgress, renderExpirationTime) {
  10278. var nextChildren = workInProgress.pendingProps.children;
  10279. reconcileChildren(
  10280. current,
  10281. workInProgress,
  10282. nextChildren,
  10283. renderExpirationTime
  10284. );
  10285. return workInProgress.child;
  10286. }
  10287. function updateProfiler(current, workInProgress, renderExpirationTime) {
  10288. {
  10289. workInProgress.effectTag |= Update; // Reset effect durations for the next eventual effect phase.
  10290. // These are reset during render to allow the DevTools commit hook a chance to read them,
  10291. var stateNode = workInProgress.stateNode;
  10292. stateNode.effectDuration = 0;
  10293. stateNode.passiveEffectDuration = 0;
  10294. }
  10295. var nextProps = workInProgress.pendingProps;
  10296. var nextChildren = nextProps.children;
  10297. reconcileChildren(
  10298. current,
  10299. workInProgress,
  10300. nextChildren,
  10301. renderExpirationTime
  10302. );
  10303. return workInProgress.child;
  10304. }
  10305. function markRef(current, workInProgress) {
  10306. var ref = workInProgress.ref;
  10307. if (
  10308. (current === null && ref !== null) ||
  10309. (current !== null && current.ref !== ref)
  10310. ) {
  10311. // Schedule a Ref effect
  10312. workInProgress.effectTag |= Ref;
  10313. }
  10314. }
  10315. function updateFunctionComponent(
  10316. current,
  10317. workInProgress,
  10318. Component,
  10319. nextProps,
  10320. renderExpirationTime
  10321. ) {
  10322. {
  10323. if (workInProgress.type !== workInProgress.elementType) {
  10324. // Lazy component props can't be validated in createElement
  10325. // because they're only guaranteed to be resolved here.
  10326. var innerPropTypes = Component.propTypes;
  10327. if (innerPropTypes) {
  10328. checkPropTypes(
  10329. innerPropTypes,
  10330. nextProps, // Resolved props
  10331. "prop",
  10332. getComponentName(Component)
  10333. );
  10334. }
  10335. }
  10336. }
  10337. var context;
  10338. {
  10339. var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
  10340. context = getMaskedContext(workInProgress, unmaskedContext);
  10341. }
  10342. var nextChildren;
  10343. prepareToReadContext(workInProgress, renderExpirationTime);
  10344. {
  10345. ReactCurrentOwner$1.current = workInProgress;
  10346. setIsRendering(true);
  10347. nextChildren = renderWithHooks(
  10348. current,
  10349. workInProgress,
  10350. Component,
  10351. nextProps,
  10352. context,
  10353. renderExpirationTime
  10354. );
  10355. setIsRendering(false);
  10356. }
  10357. if (current !== null && !didReceiveUpdate) {
  10358. bailoutHooks(current, workInProgress, renderExpirationTime);
  10359. return bailoutOnAlreadyFinishedWork(
  10360. current,
  10361. workInProgress,
  10362. renderExpirationTime
  10363. );
  10364. } // React DevTools reads this flag.
  10365. workInProgress.effectTag |= PerformedWork;
  10366. reconcileChildren(
  10367. current,
  10368. workInProgress,
  10369. nextChildren,
  10370. renderExpirationTime
  10371. );
  10372. return workInProgress.child;
  10373. }
  10374. function updateClassComponent(
  10375. current,
  10376. workInProgress,
  10377. Component,
  10378. nextProps,
  10379. renderExpirationTime
  10380. ) {
  10381. {
  10382. if (workInProgress.type !== workInProgress.elementType) {
  10383. // Lazy component props can't be validated in createElement
  10384. // because they're only guaranteed to be resolved here.
  10385. var innerPropTypes = Component.propTypes;
  10386. if (innerPropTypes) {
  10387. checkPropTypes(
  10388. innerPropTypes,
  10389. nextProps, // Resolved props
  10390. "prop",
  10391. getComponentName(Component)
  10392. );
  10393. }
  10394. }
  10395. } // Push context providers early to prevent context stack mismatches.
  10396. // During mounting we don't know the child context yet as the instance doesn't exist.
  10397. // We will invalidate the child context in finishClassComponent() right after rendering.
  10398. var hasContext;
  10399. if (isContextProvider(Component)) {
  10400. hasContext = true;
  10401. pushContextProvider(workInProgress);
  10402. } else {
  10403. hasContext = false;
  10404. }
  10405. prepareToReadContext(workInProgress, renderExpirationTime);
  10406. var instance = workInProgress.stateNode;
  10407. var shouldUpdate;
  10408. if (instance === null) {
  10409. if (current !== null) {
  10410. // A class component without an instance only mounts if it suspended
  10411. // inside a non-concurrent tree, in an inconsistent state. We want to
  10412. // treat it like a new mount, even though an empty version of it already
  10413. // committed. Disconnect the alternate pointers.
  10414. current.alternate = null;
  10415. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  10416. workInProgress.effectTag |= Placement;
  10417. } // In the initial pass we might need to construct the instance.
  10418. constructClassInstance(workInProgress, Component, nextProps);
  10419. mountClassInstance(
  10420. workInProgress,
  10421. Component,
  10422. nextProps,
  10423. renderExpirationTime
  10424. );
  10425. shouldUpdate = true;
  10426. } else if (current === null) {
  10427. // In a resume, we'll already have an instance we can reuse.
  10428. shouldUpdate = resumeMountClassInstance(
  10429. workInProgress,
  10430. Component,
  10431. nextProps,
  10432. renderExpirationTime
  10433. );
  10434. } else {
  10435. shouldUpdate = updateClassInstance(
  10436. current,
  10437. workInProgress,
  10438. Component,
  10439. nextProps,
  10440. renderExpirationTime
  10441. );
  10442. }
  10443. var nextUnitOfWork = finishClassComponent(
  10444. current,
  10445. workInProgress,
  10446. Component,
  10447. shouldUpdate,
  10448. hasContext,
  10449. renderExpirationTime
  10450. );
  10451. {
  10452. var inst = workInProgress.stateNode;
  10453. if (inst.props !== nextProps) {
  10454. if (!didWarnAboutReassigningProps) {
  10455. error(
  10456. "It looks like %s is reassigning its own `this.props` while rendering. " +
  10457. "This is not supported and can lead to confusing bugs.",
  10458. getComponentName(workInProgress.type) || "a component"
  10459. );
  10460. }
  10461. didWarnAboutReassigningProps = true;
  10462. }
  10463. }
  10464. return nextUnitOfWork;
  10465. }
  10466. function finishClassComponent(
  10467. current,
  10468. workInProgress,
  10469. Component,
  10470. shouldUpdate,
  10471. hasContext,
  10472. renderExpirationTime
  10473. ) {
  10474. // Refs should update even if shouldComponentUpdate returns false
  10475. markRef(current, workInProgress);
  10476. var didCaptureError = (workInProgress.effectTag & DidCapture) !== NoEffect;
  10477. if (!shouldUpdate && !didCaptureError) {
  10478. // Context providers should defer to sCU for rendering
  10479. if (hasContext) {
  10480. invalidateContextProvider(workInProgress, Component, false);
  10481. }
  10482. return bailoutOnAlreadyFinishedWork(
  10483. current,
  10484. workInProgress,
  10485. renderExpirationTime
  10486. );
  10487. }
  10488. var instance = workInProgress.stateNode; // Rerender
  10489. ReactCurrentOwner$1.current = workInProgress;
  10490. var nextChildren;
  10491. if (
  10492. didCaptureError &&
  10493. typeof Component.getDerivedStateFromError !== "function"
  10494. ) {
  10495. // If we captured an error, but getDerivedStateFromError is not defined,
  10496. // unmount all the children. componentDidCatch will schedule an update to
  10497. // re-render a fallback. This is temporary until we migrate everyone to
  10498. // the new API.
  10499. // TODO: Warn in a future release.
  10500. nextChildren = null;
  10501. {
  10502. stopProfilerTimerIfRunning();
  10503. }
  10504. } else {
  10505. {
  10506. setIsRendering(true);
  10507. nextChildren = instance.render();
  10508. setIsRendering(false);
  10509. }
  10510. } // React DevTools reads this flag.
  10511. workInProgress.effectTag |= PerformedWork;
  10512. if (current !== null && didCaptureError) {
  10513. // If we're recovering from an error, reconcile without reusing any of
  10514. // the existing children. Conceptually, the normal children and the children
  10515. // that are shown on error are two different sets, so we shouldn't reuse
  10516. // normal children even if their identities match.
  10517. forceUnmountCurrentAndReconcile(
  10518. current,
  10519. workInProgress,
  10520. nextChildren,
  10521. renderExpirationTime
  10522. );
  10523. } else {
  10524. reconcileChildren(
  10525. current,
  10526. workInProgress,
  10527. nextChildren,
  10528. renderExpirationTime
  10529. );
  10530. } // Memoize state using the values we just used to render.
  10531. // TODO: Restructure so we never read values from the instance.
  10532. workInProgress.memoizedState = instance.state; // The context might have changed so we need to recalculate it.
  10533. if (hasContext) {
  10534. invalidateContextProvider(workInProgress, Component, true);
  10535. }
  10536. return workInProgress.child;
  10537. }
  10538. function pushHostRootContext(workInProgress) {
  10539. var root = workInProgress.stateNode;
  10540. if (root.pendingContext) {
  10541. pushTopLevelContextObject(
  10542. workInProgress,
  10543. root.pendingContext,
  10544. root.pendingContext !== root.context
  10545. );
  10546. } else if (root.context) {
  10547. // Should always be set
  10548. pushTopLevelContextObject(workInProgress, root.context, false);
  10549. }
  10550. pushHostContainer(workInProgress, root.containerInfo);
  10551. }
  10552. function updateHostRoot(current, workInProgress, renderExpirationTime) {
  10553. pushHostRootContext(workInProgress);
  10554. var updateQueue = workInProgress.updateQueue;
  10555. if (!(current !== null && updateQueue !== null)) {
  10556. throw Error(
  10557. "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."
  10558. );
  10559. }
  10560. var nextProps = workInProgress.pendingProps;
  10561. var prevState = workInProgress.memoizedState;
  10562. var prevChildren = prevState !== null ? prevState.element : null;
  10563. cloneUpdateQueue(current, workInProgress);
  10564. processUpdateQueue(workInProgress, nextProps, null, renderExpirationTime);
  10565. var nextState = workInProgress.memoizedState; // Caution: React DevTools currently depends on this property
  10566. // being called "element".
  10567. var nextChildren = nextState.element;
  10568. if (nextChildren === prevChildren) {
  10569. return bailoutOnAlreadyFinishedWork(
  10570. current,
  10571. workInProgress,
  10572. renderExpirationTime
  10573. );
  10574. }
  10575. var root = workInProgress.stateNode;
  10576. if (root.hydrate && enterHydrationState()) {
  10577. // If we don't have any current children this might be the first pass.
  10578. // We always try to hydrate. If this isn't a hydration pass there won't
  10579. // be any children to hydrate which is effectively the same thing as
  10580. // not hydrating.
  10581. var child = mountChildFibers(
  10582. workInProgress,
  10583. null,
  10584. nextChildren,
  10585. renderExpirationTime
  10586. );
  10587. workInProgress.child = child;
  10588. var node = child;
  10589. while (node) {
  10590. // Mark each child as hydrating. This is a fast path to know whether this
  10591. // tree is part of a hydrating tree. This is used to determine if a child
  10592. // node has fully mounted yet, and for scheduling event replaying.
  10593. // Conceptually this is similar to Placement in that a new subtree is
  10594. // inserted into the React tree here. It just happens to not need DOM
  10595. // mutations because it already exists.
  10596. node.effectTag = (node.effectTag & ~Placement) | Hydrating;
  10597. node = node.sibling;
  10598. }
  10599. } else {
  10600. // Otherwise reset hydration state in case we aborted and resumed another
  10601. // root.
  10602. reconcileChildren(
  10603. current,
  10604. workInProgress,
  10605. nextChildren,
  10606. renderExpirationTime
  10607. );
  10608. }
  10609. return workInProgress.child;
  10610. }
  10611. function updateHostComponent(current, workInProgress, renderExpirationTime) {
  10612. pushHostContext(workInProgress);
  10613. var type = workInProgress.type;
  10614. var nextProps = workInProgress.pendingProps;
  10615. var prevProps = current !== null ? current.memoizedProps : null;
  10616. var nextChildren = nextProps.children;
  10617. if (prevProps !== null && shouldSetTextContent()) {
  10618. // If we're switching from a direct text child to a normal child, or to
  10619. // empty, we need to schedule the text content to be reset.
  10620. workInProgress.effectTag |= ContentReset;
  10621. }
  10622. markRef(current, workInProgress); // Check the host config to see if the children are offscreen/hidden.
  10623. if (
  10624. workInProgress.mode & ConcurrentMode &&
  10625. renderExpirationTime !== Never &&
  10626. shouldDeprioritizeSubtree()
  10627. ) {
  10628. {
  10629. markSpawnedWork(Never);
  10630. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  10631. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  10632. return null;
  10633. }
  10634. reconcileChildren(
  10635. current,
  10636. workInProgress,
  10637. nextChildren,
  10638. renderExpirationTime
  10639. );
  10640. return workInProgress.child;
  10641. }
  10642. function updateHostText(current, workInProgress) {
  10643. // immediately after.
  10644. return null;
  10645. }
  10646. function mountLazyComponent(
  10647. _current,
  10648. workInProgress,
  10649. elementType,
  10650. updateExpirationTime,
  10651. renderExpirationTime
  10652. ) {
  10653. if (_current !== null) {
  10654. // A lazy component only mounts if it suspended inside a non-
  10655. // concurrent tree, in an inconsistent state. We want to treat it like
  10656. // a new mount, even though an empty version of it already committed.
  10657. // Disconnect the alternate pointers.
  10658. _current.alternate = null;
  10659. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  10660. workInProgress.effectTag |= Placement;
  10661. }
  10662. var props = workInProgress.pendingProps; // We can't start a User Timing measurement with correct label yet.
  10663. // Cancel and resume right after we know the tag.
  10664. cancelWorkTimer(workInProgress);
  10665. var Component = readLazyComponentType(elementType); // Store the unwrapped component in the type.
  10666. workInProgress.type = Component;
  10667. var resolvedTag = (workInProgress.tag = resolveLazyComponentTag(Component));
  10668. startWorkTimer(workInProgress);
  10669. var resolvedProps = resolveDefaultProps(Component, props);
  10670. var child;
  10671. switch (resolvedTag) {
  10672. case FunctionComponent: {
  10673. {
  10674. validateFunctionComponentInDev(workInProgress, Component);
  10675. workInProgress.type = Component = resolveFunctionForHotReloading(
  10676. Component
  10677. );
  10678. }
  10679. child = updateFunctionComponent(
  10680. null,
  10681. workInProgress,
  10682. Component,
  10683. resolvedProps,
  10684. renderExpirationTime
  10685. );
  10686. return child;
  10687. }
  10688. case ClassComponent: {
  10689. {
  10690. workInProgress.type = Component = resolveClassForHotReloading(
  10691. Component
  10692. );
  10693. }
  10694. child = updateClassComponent(
  10695. null,
  10696. workInProgress,
  10697. Component,
  10698. resolvedProps,
  10699. renderExpirationTime
  10700. );
  10701. return child;
  10702. }
  10703. case ForwardRef: {
  10704. {
  10705. workInProgress.type = Component = resolveForwardRefForHotReloading(
  10706. Component
  10707. );
  10708. }
  10709. child = updateForwardRef(
  10710. null,
  10711. workInProgress,
  10712. Component,
  10713. resolvedProps,
  10714. renderExpirationTime
  10715. );
  10716. return child;
  10717. }
  10718. case MemoComponent: {
  10719. {
  10720. if (workInProgress.type !== workInProgress.elementType) {
  10721. var outerPropTypes = Component.propTypes;
  10722. if (outerPropTypes) {
  10723. checkPropTypes(
  10724. outerPropTypes,
  10725. resolvedProps, // Resolved for outer only
  10726. "prop",
  10727. getComponentName(Component)
  10728. );
  10729. }
  10730. }
  10731. }
  10732. child = updateMemoComponent(
  10733. null,
  10734. workInProgress,
  10735. Component,
  10736. resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
  10737. updateExpirationTime,
  10738. renderExpirationTime
  10739. );
  10740. return child;
  10741. }
  10742. }
  10743. var hint = "";
  10744. {
  10745. if (
  10746. Component !== null &&
  10747. typeof Component === "object" &&
  10748. Component.$$typeof === REACT_LAZY_TYPE
  10749. ) {
  10750. hint = " Did you wrap a component in React.lazy() more than once?";
  10751. }
  10752. } // This message intentionally doesn't mention ForwardRef or MemoComponent
  10753. // because the fact that it's a separate type of work is an
  10754. // implementation detail.
  10755. {
  10756. throw Error(
  10757. "Element type is invalid. Received a promise that resolves to: " +
  10758. Component +
  10759. ". Lazy element type must resolve to a class or function." +
  10760. hint
  10761. );
  10762. }
  10763. }
  10764. function mountIncompleteClassComponent(
  10765. _current,
  10766. workInProgress,
  10767. Component,
  10768. nextProps,
  10769. renderExpirationTime
  10770. ) {
  10771. if (_current !== null) {
  10772. // An incomplete component only mounts if it suspended inside a non-
  10773. // concurrent tree, in an inconsistent state. We want to treat it like
  10774. // a new mount, even though an empty version of it already committed.
  10775. // Disconnect the alternate pointers.
  10776. _current.alternate = null;
  10777. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  10778. workInProgress.effectTag |= Placement;
  10779. } // Promote the fiber to a class and try rendering again.
  10780. workInProgress.tag = ClassComponent; // The rest of this function is a fork of `updateClassComponent`
  10781. // Push context providers early to prevent context stack mismatches.
  10782. // During mounting we don't know the child context yet as the instance doesn't exist.
  10783. // We will invalidate the child context in finishClassComponent() right after rendering.
  10784. var hasContext;
  10785. if (isContextProvider(Component)) {
  10786. hasContext = true;
  10787. pushContextProvider(workInProgress);
  10788. } else {
  10789. hasContext = false;
  10790. }
  10791. prepareToReadContext(workInProgress, renderExpirationTime);
  10792. constructClassInstance(workInProgress, Component, nextProps);
  10793. mountClassInstance(
  10794. workInProgress,
  10795. Component,
  10796. nextProps,
  10797. renderExpirationTime
  10798. );
  10799. return finishClassComponent(
  10800. null,
  10801. workInProgress,
  10802. Component,
  10803. true,
  10804. hasContext,
  10805. renderExpirationTime
  10806. );
  10807. }
  10808. function mountIndeterminateComponent(
  10809. _current,
  10810. workInProgress,
  10811. Component,
  10812. renderExpirationTime
  10813. ) {
  10814. if (_current !== null) {
  10815. // An indeterminate component only mounts if it suspended inside a non-
  10816. // concurrent tree, in an inconsistent state. We want to treat it like
  10817. // a new mount, even though an empty version of it already committed.
  10818. // Disconnect the alternate pointers.
  10819. _current.alternate = null;
  10820. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  10821. workInProgress.effectTag |= Placement;
  10822. }
  10823. var props = workInProgress.pendingProps;
  10824. var context;
  10825. {
  10826. var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
  10827. context = getMaskedContext(workInProgress, unmaskedContext);
  10828. }
  10829. prepareToReadContext(workInProgress, renderExpirationTime);
  10830. var value;
  10831. {
  10832. if (
  10833. Component.prototype &&
  10834. typeof Component.prototype.render === "function"
  10835. ) {
  10836. var componentName = getComponentName(Component) || "Unknown";
  10837. if (!didWarnAboutBadClass[componentName]) {
  10838. error(
  10839. "The <%s /> component appears to have a render method, but doesn't extend React.Component. " +
  10840. "This is likely to cause errors. Change %s to extend React.Component instead.",
  10841. componentName,
  10842. componentName
  10843. );
  10844. didWarnAboutBadClass[componentName] = true;
  10845. }
  10846. }
  10847. if (workInProgress.mode & StrictMode) {
  10848. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
  10849. }
  10850. ReactCurrentOwner$1.current = workInProgress;
  10851. value = renderWithHooks(
  10852. null,
  10853. workInProgress,
  10854. Component,
  10855. props,
  10856. context,
  10857. renderExpirationTime
  10858. );
  10859. } // React DevTools reads this flag.
  10860. workInProgress.effectTag |= PerformedWork;
  10861. if (
  10862. typeof value === "object" &&
  10863. value !== null &&
  10864. typeof value.render === "function" &&
  10865. value.$$typeof === undefined
  10866. ) {
  10867. {
  10868. var _componentName = getComponentName(Component) || "Unknown";
  10869. if (!didWarnAboutModulePatternComponent[_componentName]) {
  10870. error(
  10871. "The <%s /> component appears to be a function component that returns a class instance. " +
  10872. "Change %s to a class that extends React.Component instead. " +
  10873. "If you can't use a class try assigning the prototype on the function as a workaround. " +
  10874. "`%s.prototype = React.Component.prototype`. Don't use an arrow function since it " +
  10875. "cannot be called with `new` by React.",
  10876. _componentName,
  10877. _componentName,
  10878. _componentName
  10879. );
  10880. didWarnAboutModulePatternComponent[_componentName] = true;
  10881. }
  10882. } // Proceed under the assumption that this is a class instance
  10883. workInProgress.tag = ClassComponent; // Throw out any hooks that were used.
  10884. workInProgress.memoizedState = null;
  10885. workInProgress.updateQueue = null; // Push context providers early to prevent context stack mismatches.
  10886. // During mounting we don't know the child context yet as the instance doesn't exist.
  10887. // We will invalidate the child context in finishClassComponent() right after rendering.
  10888. var hasContext = false;
  10889. if (isContextProvider(Component)) {
  10890. hasContext = true;
  10891. pushContextProvider(workInProgress);
  10892. } else {
  10893. hasContext = false;
  10894. }
  10895. workInProgress.memoizedState =
  10896. value.state !== null && value.state !== undefined ? value.state : null;
  10897. initializeUpdateQueue(workInProgress);
  10898. var getDerivedStateFromProps = Component.getDerivedStateFromProps;
  10899. if (typeof getDerivedStateFromProps === "function") {
  10900. applyDerivedStateFromProps(
  10901. workInProgress,
  10902. Component,
  10903. getDerivedStateFromProps,
  10904. props
  10905. );
  10906. }
  10907. adoptClassInstance(workInProgress, value);
  10908. mountClassInstance(workInProgress, Component, props, renderExpirationTime);
  10909. return finishClassComponent(
  10910. null,
  10911. workInProgress,
  10912. Component,
  10913. true,
  10914. hasContext,
  10915. renderExpirationTime
  10916. );
  10917. } else {
  10918. // Proceed under the assumption that this is a function component
  10919. workInProgress.tag = FunctionComponent;
  10920. reconcileChildren(null, workInProgress, value, renderExpirationTime);
  10921. {
  10922. validateFunctionComponentInDev(workInProgress, Component);
  10923. }
  10924. return workInProgress.child;
  10925. }
  10926. }
  10927. function validateFunctionComponentInDev(workInProgress, Component) {
  10928. {
  10929. if (Component) {
  10930. if (Component.childContextTypes) {
  10931. error(
  10932. "%s(...): childContextTypes cannot be defined on a function component.",
  10933. Component.displayName || Component.name || "Component"
  10934. );
  10935. }
  10936. }
  10937. if (workInProgress.ref !== null) {
  10938. var info = "";
  10939. var ownerName = getCurrentFiberOwnerNameInDevOrNull();
  10940. if (ownerName) {
  10941. info += "\n\nCheck the render method of `" + ownerName + "`.";
  10942. }
  10943. var warningKey = ownerName || workInProgress._debugID || "";
  10944. var debugSource = workInProgress._debugSource;
  10945. if (debugSource) {
  10946. warningKey = debugSource.fileName + ":" + debugSource.lineNumber;
  10947. }
  10948. if (!didWarnAboutFunctionRefs[warningKey]) {
  10949. didWarnAboutFunctionRefs[warningKey] = true;
  10950. error(
  10951. "Function components cannot be given refs. " +
  10952. "Attempts to access this ref will fail. " +
  10953. "Did you mean to use React.forwardRef()?%s",
  10954. info
  10955. );
  10956. }
  10957. }
  10958. if (typeof Component.getDerivedStateFromProps === "function") {
  10959. var _componentName2 = getComponentName(Component) || "Unknown";
  10960. if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2]) {
  10961. error(
  10962. "%s: Function components do not support getDerivedStateFromProps.",
  10963. _componentName2
  10964. );
  10965. didWarnAboutGetDerivedStateOnFunctionComponent[_componentName2] = true;
  10966. }
  10967. }
  10968. if (
  10969. typeof Component.contextType === "object" &&
  10970. Component.contextType !== null
  10971. ) {
  10972. var _componentName3 = getComponentName(Component) || "Unknown";
  10973. if (!didWarnAboutContextTypeOnFunctionComponent[_componentName3]) {
  10974. error(
  10975. "%s: Function components do not support contextType.",
  10976. _componentName3
  10977. );
  10978. didWarnAboutContextTypeOnFunctionComponent[_componentName3] = true;
  10979. }
  10980. }
  10981. }
  10982. }
  10983. var SUSPENDED_MARKER = {
  10984. dehydrated: null,
  10985. retryTime: NoWork
  10986. };
  10987. function shouldRemainOnFallback(suspenseContext, current, workInProgress) {
  10988. // If the context is telling us that we should show a fallback, and we're not
  10989. // already showing content, then we should show the fallback instead.
  10990. return (
  10991. hasSuspenseContext(suspenseContext, ForceSuspenseFallback) &&
  10992. (current === null || current.memoizedState !== null)
  10993. );
  10994. }
  10995. function updateSuspenseComponent(
  10996. current,
  10997. workInProgress,
  10998. renderExpirationTime
  10999. ) {
  11000. var mode = workInProgress.mode;
  11001. var nextProps = workInProgress.pendingProps; // This is used by DevTools to force a boundary to suspend.
  11002. {
  11003. if (shouldSuspend(workInProgress)) {
  11004. workInProgress.effectTag |= DidCapture;
  11005. }
  11006. }
  11007. var suspenseContext = suspenseStackCursor.current;
  11008. var nextDidTimeout = false;
  11009. var didSuspend = (workInProgress.effectTag & DidCapture) !== NoEffect;
  11010. if (didSuspend || shouldRemainOnFallback(suspenseContext, current)) {
  11011. // Something in this boundary's subtree already suspended. Switch to
  11012. // rendering the fallback children.
  11013. nextDidTimeout = true;
  11014. workInProgress.effectTag &= ~DidCapture;
  11015. } else {
  11016. // Attempting the main content
  11017. if (current === null || current.memoizedState !== null) {
  11018. // This is a new mount or this boundary is already showing a fallback state.
  11019. // Mark this subtree context as having at least one invisible parent that could
  11020. // handle the fallback state.
  11021. // Boundaries without fallbacks or should be avoided are not considered since
  11022. // they cannot handle preferred fallback states.
  11023. if (
  11024. nextProps.fallback !== undefined &&
  11025. nextProps.unstable_avoidThisFallback !== true
  11026. ) {
  11027. suspenseContext = addSubtreeSuspenseContext(
  11028. suspenseContext,
  11029. InvisibleParentSuspenseContext
  11030. );
  11031. }
  11032. }
  11033. }
  11034. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  11035. pushSuspenseContext(workInProgress, suspenseContext); // This next part is a bit confusing. If the children timeout, we switch to
  11036. // showing the fallback children in place of the "primary" children.
  11037. // However, we don't want to delete the primary children because then their
  11038. // state will be lost (both the React state and the host state, e.g.
  11039. // uncontrolled form inputs). Instead we keep them mounted and hide them.
  11040. // Both the fallback children AND the primary children are rendered at the
  11041. // same time. Once the primary children are un-suspended, we can delete
  11042. // the fallback children — don't need to preserve their state.
  11043. //
  11044. // The two sets of children are siblings in the host environment, but
  11045. // semantically, for purposes of reconciliation, they are two separate sets.
  11046. // So we store them using two fragment fibers.
  11047. //
  11048. // However, we want to avoid allocating extra fibers for every placeholder.
  11049. // They're only necessary when the children time out, because that's the
  11050. // only time when both sets are mounted.
  11051. //
  11052. // So, the extra fragment fibers are only used if the children time out.
  11053. // Otherwise, we render the primary children directly. This requires some
  11054. // custom reconciliation logic to preserve the state of the primary
  11055. // children. It's essentially a very basic form of re-parenting.
  11056. if (current === null) {
  11057. // If we're currently hydrating, try to hydrate this boundary.
  11058. // But only if this has a fallback.
  11059. if (nextProps.fallback !== undefined); // This is the initial mount. This branch is pretty simple because there's
  11060. // no previous state that needs to be preserved.
  11061. if (nextDidTimeout) {
  11062. // Mount separate fragments for primary and fallback children.
  11063. var nextFallbackChildren = nextProps.fallback;
  11064. var primaryChildFragment = createFiberFromFragment(
  11065. null,
  11066. mode,
  11067. NoWork,
  11068. null
  11069. );
  11070. primaryChildFragment.return = workInProgress;
  11071. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11072. // Outside of blocking mode, we commit the effects from the
  11073. // partially completed, timed-out tree, too.
  11074. var progressedState = workInProgress.memoizedState;
  11075. var progressedPrimaryChild =
  11076. progressedState !== null
  11077. ? workInProgress.child.child
  11078. : workInProgress.child;
  11079. primaryChildFragment.child = progressedPrimaryChild;
  11080. var progressedChild = progressedPrimaryChild;
  11081. while (progressedChild !== null) {
  11082. progressedChild.return = primaryChildFragment;
  11083. progressedChild = progressedChild.sibling;
  11084. }
  11085. }
  11086. var fallbackChildFragment = createFiberFromFragment(
  11087. nextFallbackChildren,
  11088. mode,
  11089. renderExpirationTime,
  11090. null
  11091. );
  11092. fallbackChildFragment.return = workInProgress;
  11093. primaryChildFragment.sibling = fallbackChildFragment; // Skip the primary children, and continue working on the
  11094. // fallback children.
  11095. workInProgress.memoizedState = SUSPENDED_MARKER;
  11096. workInProgress.child = primaryChildFragment;
  11097. return fallbackChildFragment;
  11098. } else {
  11099. // Mount the primary children without an intermediate fragment fiber.
  11100. var nextPrimaryChildren = nextProps.children;
  11101. workInProgress.memoizedState = null;
  11102. return (workInProgress.child = mountChildFibers(
  11103. workInProgress,
  11104. null,
  11105. nextPrimaryChildren,
  11106. renderExpirationTime
  11107. ));
  11108. }
  11109. } else {
  11110. // This is an update. This branch is more complicated because we need to
  11111. // ensure the state of the primary children is preserved.
  11112. var prevState = current.memoizedState;
  11113. if (prevState !== null) {
  11114. // wrapped in a fragment fiber.
  11115. var currentPrimaryChildFragment = current.child;
  11116. var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
  11117. if (nextDidTimeout) {
  11118. // Still timed out. Reuse the current primary children by cloning
  11119. // its fragment. We're going to skip over these entirely.
  11120. var _nextFallbackChildren2 = nextProps.fallback;
  11121. var _primaryChildFragment2 = createWorkInProgress(
  11122. currentPrimaryChildFragment,
  11123. currentPrimaryChildFragment.pendingProps
  11124. );
  11125. _primaryChildFragment2.return = workInProgress;
  11126. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11127. // Outside of blocking mode, we commit the effects from the
  11128. // partially completed, timed-out tree, too.
  11129. var _progressedState = workInProgress.memoizedState;
  11130. var _progressedPrimaryChild =
  11131. _progressedState !== null
  11132. ? workInProgress.child.child
  11133. : workInProgress.child;
  11134. if (_progressedPrimaryChild !== currentPrimaryChildFragment.child) {
  11135. _primaryChildFragment2.child = _progressedPrimaryChild;
  11136. var _progressedChild2 = _progressedPrimaryChild;
  11137. while (_progressedChild2 !== null) {
  11138. _progressedChild2.return = _primaryChildFragment2;
  11139. _progressedChild2 = _progressedChild2.sibling;
  11140. }
  11141. }
  11142. } // Because primaryChildFragment is a new fiber that we're inserting as the
  11143. // parent of a new tree, we need to set its treeBaseDuration.
  11144. if (workInProgress.mode & ProfileMode) {
  11145. // treeBaseDuration is the sum of all the child tree base durations.
  11146. var _treeBaseDuration = 0;
  11147. var _hiddenChild = _primaryChildFragment2.child;
  11148. while (_hiddenChild !== null) {
  11149. _treeBaseDuration += _hiddenChild.treeBaseDuration;
  11150. _hiddenChild = _hiddenChild.sibling;
  11151. }
  11152. _primaryChildFragment2.treeBaseDuration = _treeBaseDuration;
  11153. } // Clone the fallback child fragment, too. These we'll continue
  11154. // working on.
  11155. var _fallbackChildFragment2 = createWorkInProgress(
  11156. currentFallbackChildFragment,
  11157. _nextFallbackChildren2
  11158. );
  11159. _fallbackChildFragment2.return = workInProgress;
  11160. _primaryChildFragment2.sibling = _fallbackChildFragment2;
  11161. _primaryChildFragment2.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  11162. // fallback children.
  11163. workInProgress.memoizedState = SUSPENDED_MARKER;
  11164. workInProgress.child = _primaryChildFragment2;
  11165. return _fallbackChildFragment2;
  11166. } else {
  11167. // No longer suspended. Switch back to showing the primary children,
  11168. // and remove the intermediate fragment fiber.
  11169. var _nextPrimaryChildren = nextProps.children;
  11170. var currentPrimaryChild = currentPrimaryChildFragment.child;
  11171. var primaryChild = reconcileChildFibers(
  11172. workInProgress,
  11173. currentPrimaryChild,
  11174. _nextPrimaryChildren,
  11175. renderExpirationTime
  11176. ); // If this render doesn't suspend, we need to delete the fallback
  11177. // children. Wait until the complete phase, after we've confirmed the
  11178. // fallback is no longer needed.
  11179. // TODO: Would it be better to store the fallback fragment on
  11180. // the stateNode?
  11181. // Continue rendering the children, like we normally do.
  11182. workInProgress.memoizedState = null;
  11183. return (workInProgress.child = primaryChild);
  11184. }
  11185. } else {
  11186. // The current tree has not already timed out. That means the primary
  11187. // children are not wrapped in a fragment fiber.
  11188. var _currentPrimaryChild = current.child;
  11189. if (nextDidTimeout) {
  11190. // Timed out. Wrap the children in a fragment fiber to keep them
  11191. // separate from the fallback children.
  11192. var _nextFallbackChildren3 = nextProps.fallback;
  11193. var _primaryChildFragment3 = createFiberFromFragment(
  11194. // It shouldn't matter what the pending props are because we aren't
  11195. // going to render this fragment.
  11196. null,
  11197. mode,
  11198. NoWork,
  11199. null
  11200. );
  11201. _primaryChildFragment3.return = workInProgress;
  11202. _primaryChildFragment3.child = _currentPrimaryChild;
  11203. if (_currentPrimaryChild !== null) {
  11204. _currentPrimaryChild.return = _primaryChildFragment3;
  11205. } // Even though we're creating a new fiber, there are no new children,
  11206. // because we're reusing an already mounted tree. So we don't need to
  11207. // schedule a placement.
  11208. // primaryChildFragment.effectTag |= Placement;
  11209. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11210. // Outside of blocking mode, we commit the effects from the
  11211. // partially completed, timed-out tree, too.
  11212. var _progressedState2 = workInProgress.memoizedState;
  11213. var _progressedPrimaryChild2 =
  11214. _progressedState2 !== null
  11215. ? workInProgress.child.child
  11216. : workInProgress.child;
  11217. _primaryChildFragment3.child = _progressedPrimaryChild2;
  11218. var _progressedChild3 = _progressedPrimaryChild2;
  11219. while (_progressedChild3 !== null) {
  11220. _progressedChild3.return = _primaryChildFragment3;
  11221. _progressedChild3 = _progressedChild3.sibling;
  11222. }
  11223. } // Because primaryChildFragment is a new fiber that we're inserting as the
  11224. // parent of a new tree, we need to set its treeBaseDuration.
  11225. if (workInProgress.mode & ProfileMode) {
  11226. // treeBaseDuration is the sum of all the child tree base durations.
  11227. var _treeBaseDuration2 = 0;
  11228. var _hiddenChild2 = _primaryChildFragment3.child;
  11229. while (_hiddenChild2 !== null) {
  11230. _treeBaseDuration2 += _hiddenChild2.treeBaseDuration;
  11231. _hiddenChild2 = _hiddenChild2.sibling;
  11232. }
  11233. _primaryChildFragment3.treeBaseDuration = _treeBaseDuration2;
  11234. } // Create a fragment from the fallback children, too.
  11235. var _fallbackChildFragment3 = createFiberFromFragment(
  11236. _nextFallbackChildren3,
  11237. mode,
  11238. renderExpirationTime,
  11239. null
  11240. );
  11241. _fallbackChildFragment3.return = workInProgress;
  11242. _primaryChildFragment3.sibling = _fallbackChildFragment3;
  11243. _fallbackChildFragment3.effectTag |= Placement;
  11244. _primaryChildFragment3.childExpirationTime = NoWork; // Skip the primary children, and continue working on the
  11245. // fallback children.
  11246. workInProgress.memoizedState = SUSPENDED_MARKER;
  11247. workInProgress.child = _primaryChildFragment3;
  11248. return _fallbackChildFragment3;
  11249. } else {
  11250. // Still haven't timed out. Continue rendering the children, like we
  11251. // normally do.
  11252. workInProgress.memoizedState = null;
  11253. var _nextPrimaryChildren2 = nextProps.children;
  11254. return (workInProgress.child = reconcileChildFibers(
  11255. workInProgress,
  11256. _currentPrimaryChild,
  11257. _nextPrimaryChildren2,
  11258. renderExpirationTime
  11259. ));
  11260. }
  11261. }
  11262. }
  11263. }
  11264. function scheduleWorkOnFiber(fiber, renderExpirationTime) {
  11265. if (fiber.expirationTime < renderExpirationTime) {
  11266. fiber.expirationTime = renderExpirationTime;
  11267. }
  11268. var alternate = fiber.alternate;
  11269. if (alternate !== null && alternate.expirationTime < renderExpirationTime) {
  11270. alternate.expirationTime = renderExpirationTime;
  11271. }
  11272. scheduleWorkOnParentPath(fiber.return, renderExpirationTime);
  11273. }
  11274. function propagateSuspenseContextChange(
  11275. workInProgress,
  11276. firstChild,
  11277. renderExpirationTime
  11278. ) {
  11279. // Mark any Suspense boundaries with fallbacks as having work to do.
  11280. // If they were previously forced into fallbacks, they may now be able
  11281. // to unblock.
  11282. var node = firstChild;
  11283. while (node !== null) {
  11284. if (node.tag === SuspenseComponent) {
  11285. var state = node.memoizedState;
  11286. if (state !== null) {
  11287. scheduleWorkOnFiber(node, renderExpirationTime);
  11288. }
  11289. } else if (node.tag === SuspenseListComponent) {
  11290. // If the tail is hidden there might not be an Suspense boundaries
  11291. // to schedule work on. In this case we have to schedule it on the
  11292. // list itself.
  11293. // We don't have to traverse to the children of the list since
  11294. // the list will propagate the change when it rerenders.
  11295. scheduleWorkOnFiber(node, renderExpirationTime);
  11296. } else if (node.child !== null) {
  11297. node.child.return = node;
  11298. node = node.child;
  11299. continue;
  11300. }
  11301. if (node === workInProgress) {
  11302. return;
  11303. }
  11304. while (node.sibling === null) {
  11305. if (node.return === null || node.return === workInProgress) {
  11306. return;
  11307. }
  11308. node = node.return;
  11309. }
  11310. node.sibling.return = node.return;
  11311. node = node.sibling;
  11312. }
  11313. }
  11314. function findLastContentRow(firstChild) {
  11315. // This is going to find the last row among these children that is already
  11316. // showing content on the screen, as opposed to being in fallback state or
  11317. // new. If a row has multiple Suspense boundaries, any of them being in the
  11318. // fallback state, counts as the whole row being in a fallback state.
  11319. // Note that the "rows" will be workInProgress, but any nested children
  11320. // will still be current since we haven't rendered them yet. The mounted
  11321. // order may not be the same as the new order. We use the new order.
  11322. var row = firstChild;
  11323. var lastContentRow = null;
  11324. while (row !== null) {
  11325. var currentRow = row.alternate; // New rows can't be content rows.
  11326. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  11327. lastContentRow = row;
  11328. }
  11329. row = row.sibling;
  11330. }
  11331. return lastContentRow;
  11332. }
  11333. function validateRevealOrder(revealOrder) {
  11334. {
  11335. if (
  11336. revealOrder !== undefined &&
  11337. revealOrder !== "forwards" &&
  11338. revealOrder !== "backwards" &&
  11339. revealOrder !== "together" &&
  11340. !didWarnAboutRevealOrder[revealOrder]
  11341. ) {
  11342. didWarnAboutRevealOrder[revealOrder] = true;
  11343. if (typeof revealOrder === "string") {
  11344. switch (revealOrder.toLowerCase()) {
  11345. case "together":
  11346. case "forwards":
  11347. case "backwards": {
  11348. error(
  11349. '"%s" is not a valid value for revealOrder on <SuspenseList />. ' +
  11350. 'Use lowercase "%s" instead.',
  11351. revealOrder,
  11352. revealOrder.toLowerCase()
  11353. );
  11354. break;
  11355. }
  11356. case "forward":
  11357. case "backward": {
  11358. error(
  11359. '"%s" is not a valid value for revealOrder on <SuspenseList />. ' +
  11360. 'React uses the -s suffix in the spelling. Use "%ss" instead.',
  11361. revealOrder,
  11362. revealOrder.toLowerCase()
  11363. );
  11364. break;
  11365. }
  11366. default:
  11367. error(
  11368. '"%s" is not a supported revealOrder on <SuspenseList />. ' +
  11369. 'Did you mean "together", "forwards" or "backwards"?',
  11370. revealOrder
  11371. );
  11372. break;
  11373. }
  11374. } else {
  11375. error(
  11376. "%s is not a supported value for revealOrder on <SuspenseList />. " +
  11377. 'Did you mean "together", "forwards" or "backwards"?',
  11378. revealOrder
  11379. );
  11380. }
  11381. }
  11382. }
  11383. }
  11384. function validateTailOptions(tailMode, revealOrder) {
  11385. {
  11386. if (tailMode !== undefined && !didWarnAboutTailOptions[tailMode]) {
  11387. if (tailMode !== "collapsed" && tailMode !== "hidden") {
  11388. didWarnAboutTailOptions[tailMode] = true;
  11389. error(
  11390. '"%s" is not a supported value for tail on <SuspenseList />. ' +
  11391. 'Did you mean "collapsed" or "hidden"?',
  11392. tailMode
  11393. );
  11394. } else if (revealOrder !== "forwards" && revealOrder !== "backwards") {
  11395. didWarnAboutTailOptions[tailMode] = true;
  11396. error(
  11397. '<SuspenseList tail="%s" /> is only valid if revealOrder is ' +
  11398. '"forwards" or "backwards". ' +
  11399. 'Did you mean to specify revealOrder="forwards"?',
  11400. tailMode
  11401. );
  11402. }
  11403. }
  11404. }
  11405. }
  11406. function validateSuspenseListNestedChild(childSlot, index) {
  11407. {
  11408. var isArray = Array.isArray(childSlot);
  11409. var isIterable = !isArray && typeof getIteratorFn(childSlot) === "function";
  11410. if (isArray || isIterable) {
  11411. var type = isArray ? "array" : "iterable";
  11412. error(
  11413. "A nested %s was passed to row #%s in <SuspenseList />. Wrap it in " +
  11414. "an additional SuspenseList to configure its revealOrder: " +
  11415. "<SuspenseList revealOrder=...> ... " +
  11416. "<SuspenseList revealOrder=...>{%s}</SuspenseList> ... " +
  11417. "</SuspenseList>",
  11418. type,
  11419. index,
  11420. type
  11421. );
  11422. return false;
  11423. }
  11424. }
  11425. return true;
  11426. }
  11427. function validateSuspenseListChildren(children, revealOrder) {
  11428. {
  11429. if (
  11430. (revealOrder === "forwards" || revealOrder === "backwards") &&
  11431. children !== undefined &&
  11432. children !== null &&
  11433. children !== false
  11434. ) {
  11435. if (Array.isArray(children)) {
  11436. for (var i = 0; i < children.length; i++) {
  11437. if (!validateSuspenseListNestedChild(children[i], i)) {
  11438. return;
  11439. }
  11440. }
  11441. } else {
  11442. var iteratorFn = getIteratorFn(children);
  11443. if (typeof iteratorFn === "function") {
  11444. var childrenIterator = iteratorFn.call(children);
  11445. if (childrenIterator) {
  11446. var step = childrenIterator.next();
  11447. var _i = 0;
  11448. for (; !step.done; step = childrenIterator.next()) {
  11449. if (!validateSuspenseListNestedChild(step.value, _i)) {
  11450. return;
  11451. }
  11452. _i++;
  11453. }
  11454. }
  11455. } else {
  11456. error(
  11457. 'A single row was passed to a <SuspenseList revealOrder="%s" />. ' +
  11458. "This is not useful since it needs multiple rows. " +
  11459. "Did you mean to pass multiple children or an array?",
  11460. revealOrder
  11461. );
  11462. }
  11463. }
  11464. }
  11465. }
  11466. }
  11467. function initSuspenseListRenderState(
  11468. workInProgress,
  11469. isBackwards,
  11470. tail,
  11471. lastContentRow,
  11472. tailMode,
  11473. lastEffectBeforeRendering
  11474. ) {
  11475. var renderState = workInProgress.memoizedState;
  11476. if (renderState === null) {
  11477. workInProgress.memoizedState = {
  11478. isBackwards: isBackwards,
  11479. rendering: null,
  11480. renderingStartTime: 0,
  11481. last: lastContentRow,
  11482. tail: tail,
  11483. tailExpiration: 0,
  11484. tailMode: tailMode,
  11485. lastEffect: lastEffectBeforeRendering
  11486. };
  11487. } else {
  11488. // We can reuse the existing object from previous renders.
  11489. renderState.isBackwards = isBackwards;
  11490. renderState.rendering = null;
  11491. renderState.renderingStartTime = 0;
  11492. renderState.last = lastContentRow;
  11493. renderState.tail = tail;
  11494. renderState.tailExpiration = 0;
  11495. renderState.tailMode = tailMode;
  11496. renderState.lastEffect = lastEffectBeforeRendering;
  11497. }
  11498. } // This can end up rendering this component multiple passes.
  11499. // The first pass splits the children fibers into two sets. A head and tail.
  11500. // We first render the head. If anything is in fallback state, we do another
  11501. // pass through beginWork to rerender all children (including the tail) with
  11502. // the force suspend context. If the first render didn't have anything in
  11503. // in fallback state. Then we render each row in the tail one-by-one.
  11504. // That happens in the completeWork phase without going back to beginWork.
  11505. function updateSuspenseListComponent(
  11506. current,
  11507. workInProgress,
  11508. renderExpirationTime
  11509. ) {
  11510. var nextProps = workInProgress.pendingProps;
  11511. var revealOrder = nextProps.revealOrder;
  11512. var tailMode = nextProps.tail;
  11513. var newChildren = nextProps.children;
  11514. validateRevealOrder(revealOrder);
  11515. validateTailOptions(tailMode, revealOrder);
  11516. validateSuspenseListChildren(newChildren, revealOrder);
  11517. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  11518. var suspenseContext = suspenseStackCursor.current;
  11519. var shouldForceFallback = hasSuspenseContext(
  11520. suspenseContext,
  11521. ForceSuspenseFallback
  11522. );
  11523. if (shouldForceFallback) {
  11524. suspenseContext = setShallowSuspenseContext(
  11525. suspenseContext,
  11526. ForceSuspenseFallback
  11527. );
  11528. workInProgress.effectTag |= DidCapture;
  11529. } else {
  11530. var didSuspendBefore =
  11531. current !== null && (current.effectTag & DidCapture) !== NoEffect;
  11532. if (didSuspendBefore) {
  11533. // If we previously forced a fallback, we need to schedule work
  11534. // on any nested boundaries to let them know to try to render
  11535. // again. This is the same as context updating.
  11536. propagateSuspenseContextChange(
  11537. workInProgress,
  11538. workInProgress.child,
  11539. renderExpirationTime
  11540. );
  11541. }
  11542. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  11543. }
  11544. pushSuspenseContext(workInProgress, suspenseContext);
  11545. if ((workInProgress.mode & BlockingMode) === NoMode) {
  11546. // Outside of blocking mode, SuspenseList doesn't work so we just
  11547. // use make it a noop by treating it as the default revealOrder.
  11548. workInProgress.memoizedState = null;
  11549. } else {
  11550. switch (revealOrder) {
  11551. case "forwards": {
  11552. var lastContentRow = findLastContentRow(workInProgress.child);
  11553. var tail;
  11554. if (lastContentRow === null) {
  11555. // The whole list is part of the tail.
  11556. // TODO: We could fast path by just rendering the tail now.
  11557. tail = workInProgress.child;
  11558. workInProgress.child = null;
  11559. } else {
  11560. // Disconnect the tail rows after the content row.
  11561. // We're going to render them separately later.
  11562. tail = lastContentRow.sibling;
  11563. lastContentRow.sibling = null;
  11564. }
  11565. initSuspenseListRenderState(
  11566. workInProgress,
  11567. false, // isBackwards
  11568. tail,
  11569. lastContentRow,
  11570. tailMode,
  11571. workInProgress.lastEffect
  11572. );
  11573. break;
  11574. }
  11575. case "backwards": {
  11576. // We're going to find the first row that has existing content.
  11577. // At the same time we're going to reverse the list of everything
  11578. // we pass in the meantime. That's going to be our tail in reverse
  11579. // order.
  11580. var _tail = null;
  11581. var row = workInProgress.child;
  11582. workInProgress.child = null;
  11583. while (row !== null) {
  11584. var currentRow = row.alternate; // New rows can't be content rows.
  11585. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  11586. // This is the beginning of the main content.
  11587. workInProgress.child = row;
  11588. break;
  11589. }
  11590. var nextRow = row.sibling;
  11591. row.sibling = _tail;
  11592. _tail = row;
  11593. row = nextRow;
  11594. } // TODO: If workInProgress.child is null, we can continue on the tail immediately.
  11595. initSuspenseListRenderState(
  11596. workInProgress,
  11597. true, // isBackwards
  11598. _tail,
  11599. null, // last
  11600. tailMode,
  11601. workInProgress.lastEffect
  11602. );
  11603. break;
  11604. }
  11605. case "together": {
  11606. initSuspenseListRenderState(
  11607. workInProgress,
  11608. false, // isBackwards
  11609. null, // tail
  11610. null, // last
  11611. undefined,
  11612. workInProgress.lastEffect
  11613. );
  11614. break;
  11615. }
  11616. default: {
  11617. // The default reveal order is the same as not having
  11618. // a boundary.
  11619. workInProgress.memoizedState = null;
  11620. }
  11621. }
  11622. }
  11623. return workInProgress.child;
  11624. }
  11625. function updatePortalComponent(current, workInProgress, renderExpirationTime) {
  11626. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  11627. var nextChildren = workInProgress.pendingProps;
  11628. if (current === null) {
  11629. // Portals are special because we don't append the children during mount
  11630. // but at commit. Therefore we need to track insertions which the normal
  11631. // flow doesn't do during mount. This doesn't happen at the root because
  11632. // the root always starts with a "current" with a null child.
  11633. // TODO: Consider unifying this with how the root works.
  11634. workInProgress.child = reconcileChildFibers(
  11635. workInProgress,
  11636. null,
  11637. nextChildren,
  11638. renderExpirationTime
  11639. );
  11640. } else {
  11641. reconcileChildren(
  11642. current,
  11643. workInProgress,
  11644. nextChildren,
  11645. renderExpirationTime
  11646. );
  11647. }
  11648. return workInProgress.child;
  11649. }
  11650. function updateContextProvider(current, workInProgress, renderExpirationTime) {
  11651. var providerType = workInProgress.type;
  11652. var context = providerType._context;
  11653. var newProps = workInProgress.pendingProps;
  11654. var oldProps = workInProgress.memoizedProps;
  11655. var newValue = newProps.value;
  11656. {
  11657. var providerPropTypes = workInProgress.type.propTypes;
  11658. if (providerPropTypes) {
  11659. checkPropTypes(providerPropTypes, newProps, "prop", "Context.Provider");
  11660. }
  11661. }
  11662. pushProvider(workInProgress, newValue);
  11663. if (oldProps !== null) {
  11664. var oldValue = oldProps.value;
  11665. var changedBits = calculateChangedBits(context, newValue, oldValue);
  11666. if (changedBits === 0) {
  11667. // No change. Bailout early if children are the same.
  11668. if (oldProps.children === newProps.children && !hasContextChanged()) {
  11669. return bailoutOnAlreadyFinishedWork(
  11670. current,
  11671. workInProgress,
  11672. renderExpirationTime
  11673. );
  11674. }
  11675. } else {
  11676. // The context value changed. Search for matching consumers and schedule
  11677. // them to update.
  11678. propagateContextChange(
  11679. workInProgress,
  11680. context,
  11681. changedBits,
  11682. renderExpirationTime
  11683. );
  11684. }
  11685. }
  11686. var newChildren = newProps.children;
  11687. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  11688. return workInProgress.child;
  11689. }
  11690. var hasWarnedAboutUsingContextAsConsumer = false;
  11691. function updateContextConsumer(current, workInProgress, renderExpirationTime) {
  11692. var context = workInProgress.type; // The logic below for Context differs depending on PROD or DEV mode. In
  11693. // DEV mode, we create a separate object for Context.Consumer that acts
  11694. // like a proxy to Context. This proxy object adds unnecessary code in PROD
  11695. // so we use the old behaviour (Context.Consumer references Context) to
  11696. // reduce size and overhead. The separate object references context via
  11697. // a property called "_context", which also gives us the ability to check
  11698. // in DEV mode if this property exists or not and warn if it does not.
  11699. {
  11700. if (context._context === undefined) {
  11701. // This may be because it's a Context (rather than a Consumer).
  11702. // Or it may be because it's older React where they're the same thing.
  11703. // We only want to warn if we're sure it's a new React.
  11704. if (context !== context.Consumer) {
  11705. if (!hasWarnedAboutUsingContextAsConsumer) {
  11706. hasWarnedAboutUsingContextAsConsumer = true;
  11707. error(
  11708. "Rendering <Context> directly is not supported and will be removed in " +
  11709. "a future major release. Did you mean to render <Context.Consumer> instead?"
  11710. );
  11711. }
  11712. }
  11713. } else {
  11714. context = context._context;
  11715. }
  11716. }
  11717. var newProps = workInProgress.pendingProps;
  11718. var render = newProps.children;
  11719. {
  11720. if (typeof render !== "function") {
  11721. error(
  11722. "A context consumer was rendered with multiple children, or a child " +
  11723. "that isn't a function. A context consumer expects a single child " +
  11724. "that is a function. If you did pass a function, make sure there " +
  11725. "is no trailing or leading whitespace around it."
  11726. );
  11727. }
  11728. }
  11729. prepareToReadContext(workInProgress, renderExpirationTime);
  11730. var newValue = readContext(context, newProps.unstable_observedBits);
  11731. var newChildren;
  11732. {
  11733. ReactCurrentOwner$1.current = workInProgress;
  11734. setIsRendering(true);
  11735. newChildren = render(newValue);
  11736. setIsRendering(false);
  11737. } // React DevTools reads this flag.
  11738. workInProgress.effectTag |= PerformedWork;
  11739. reconcileChildren(current, workInProgress, newChildren, renderExpirationTime);
  11740. return workInProgress.child;
  11741. }
  11742. function markWorkInProgressReceivedUpdate() {
  11743. didReceiveUpdate = true;
  11744. }
  11745. function bailoutOnAlreadyFinishedWork(
  11746. current,
  11747. workInProgress,
  11748. renderExpirationTime
  11749. ) {
  11750. cancelWorkTimer(workInProgress);
  11751. if (current !== null) {
  11752. // Reuse previous dependencies
  11753. workInProgress.dependencies = current.dependencies;
  11754. }
  11755. {
  11756. // Don't update "base" render times for bailouts.
  11757. stopProfilerTimerIfRunning();
  11758. }
  11759. var updateExpirationTime = workInProgress.expirationTime;
  11760. if (updateExpirationTime !== NoWork) {
  11761. markUnprocessedUpdateTime(updateExpirationTime);
  11762. } // Check if the children have any pending work.
  11763. var childExpirationTime = workInProgress.childExpirationTime;
  11764. if (childExpirationTime < renderExpirationTime) {
  11765. // The children don't have any work either. We can skip them.
  11766. // TODO: Once we add back resuming, we should check if the children are
  11767. // a work-in-progress set. If so, we need to transfer their effects.
  11768. return null;
  11769. } else {
  11770. // This fiber doesn't have work, but its subtree does. Clone the child
  11771. // fibers and continue.
  11772. cloneChildFibers(current, workInProgress);
  11773. return workInProgress.child;
  11774. }
  11775. }
  11776. function remountFiber(current, oldWorkInProgress, newWorkInProgress) {
  11777. {
  11778. var returnFiber = oldWorkInProgress.return;
  11779. if (returnFiber === null) {
  11780. throw new Error("Cannot swap the root fiber.");
  11781. } // Disconnect from the old current.
  11782. // It will get deleted.
  11783. current.alternate = null;
  11784. oldWorkInProgress.alternate = null; // Connect to the new tree.
  11785. newWorkInProgress.index = oldWorkInProgress.index;
  11786. newWorkInProgress.sibling = oldWorkInProgress.sibling;
  11787. newWorkInProgress.return = oldWorkInProgress.return;
  11788. newWorkInProgress.ref = oldWorkInProgress.ref; // Replace the child/sibling pointers above it.
  11789. if (oldWorkInProgress === returnFiber.child) {
  11790. returnFiber.child = newWorkInProgress;
  11791. } else {
  11792. var prevSibling = returnFiber.child;
  11793. if (prevSibling === null) {
  11794. throw new Error("Expected parent to have a child.");
  11795. }
  11796. while (prevSibling.sibling !== oldWorkInProgress) {
  11797. prevSibling = prevSibling.sibling;
  11798. if (prevSibling === null) {
  11799. throw new Error("Expected to find the previous sibling.");
  11800. }
  11801. }
  11802. prevSibling.sibling = newWorkInProgress;
  11803. } // Delete the old fiber and place the new one.
  11804. // Since the old fiber is disconnected, we have to schedule it manually.
  11805. var last = returnFiber.lastEffect;
  11806. if (last !== null) {
  11807. last.nextEffect = current;
  11808. returnFiber.lastEffect = current;
  11809. } else {
  11810. returnFiber.firstEffect = returnFiber.lastEffect = current;
  11811. }
  11812. current.nextEffect = null;
  11813. current.effectTag = Deletion;
  11814. newWorkInProgress.effectTag |= Placement; // Restart work from the new fiber.
  11815. return newWorkInProgress;
  11816. }
  11817. }
  11818. function beginWork(current, workInProgress, renderExpirationTime) {
  11819. var updateExpirationTime = workInProgress.expirationTime;
  11820. {
  11821. if (workInProgress._debugNeedsRemount && current !== null) {
  11822. // This will restart the begin phase with a new fiber.
  11823. return remountFiber(
  11824. current,
  11825. workInProgress,
  11826. createFiberFromTypeAndProps(
  11827. workInProgress.type,
  11828. workInProgress.key,
  11829. workInProgress.pendingProps,
  11830. workInProgress._debugOwner || null,
  11831. workInProgress.mode,
  11832. workInProgress.expirationTime
  11833. )
  11834. );
  11835. }
  11836. }
  11837. if (current !== null) {
  11838. var oldProps = current.memoizedProps;
  11839. var newProps = workInProgress.pendingProps;
  11840. if (
  11841. oldProps !== newProps ||
  11842. hasContextChanged() || // Force a re-render if the implementation changed due to hot reload:
  11843. workInProgress.type !== current.type
  11844. ) {
  11845. // If props or context changed, mark the fiber as having performed work.
  11846. // This may be unset if the props are determined to be equal later (memo).
  11847. didReceiveUpdate = true;
  11848. } else if (updateExpirationTime < renderExpirationTime) {
  11849. didReceiveUpdate = false; // This fiber does not have any pending work. Bailout without entering
  11850. // the begin phase. There's still some bookkeeping we that needs to be done
  11851. // in this optimized path, mostly pushing stuff onto the stack.
  11852. switch (workInProgress.tag) {
  11853. case HostRoot:
  11854. pushHostRootContext(workInProgress);
  11855. break;
  11856. case HostComponent:
  11857. pushHostContext(workInProgress);
  11858. if (
  11859. workInProgress.mode & ConcurrentMode &&
  11860. renderExpirationTime !== Never &&
  11861. shouldDeprioritizeSubtree(workInProgress.type)
  11862. ) {
  11863. {
  11864. markSpawnedWork(Never);
  11865. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  11866. workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
  11867. return null;
  11868. }
  11869. break;
  11870. case ClassComponent: {
  11871. var Component = workInProgress.type;
  11872. if (isContextProvider(Component)) {
  11873. pushContextProvider(workInProgress);
  11874. }
  11875. break;
  11876. }
  11877. case HostPortal:
  11878. pushHostContainer(
  11879. workInProgress,
  11880. workInProgress.stateNode.containerInfo
  11881. );
  11882. break;
  11883. case ContextProvider: {
  11884. var newValue = workInProgress.memoizedProps.value;
  11885. pushProvider(workInProgress, newValue);
  11886. break;
  11887. }
  11888. case Profiler:
  11889. {
  11890. // Profiler should only call onRender when one of its descendants actually rendered.
  11891. var hasChildWork =
  11892. workInProgress.childExpirationTime >= renderExpirationTime;
  11893. if (hasChildWork) {
  11894. workInProgress.effectTag |= Update;
  11895. } // Reset effect durations for the next eventual effect phase.
  11896. // These are reset during render to allow the DevTools commit hook a chance to read them,
  11897. var stateNode = workInProgress.stateNode;
  11898. stateNode.effectDuration = 0;
  11899. stateNode.passiveEffectDuration = 0;
  11900. }
  11901. break;
  11902. case SuspenseComponent: {
  11903. var state = workInProgress.memoizedState;
  11904. if (state !== null) {
  11905. // whether to retry the primary children, or to skip over it and
  11906. // go straight to the fallback. Check the priority of the primary
  11907. // child fragment.
  11908. var primaryChildFragment = workInProgress.child;
  11909. var primaryChildExpirationTime =
  11910. primaryChildFragment.childExpirationTime;
  11911. if (
  11912. primaryChildExpirationTime !== NoWork &&
  11913. primaryChildExpirationTime >= renderExpirationTime
  11914. ) {
  11915. // The primary children have pending work. Use the normal path
  11916. // to attempt to render the primary children again.
  11917. return updateSuspenseComponent(
  11918. current,
  11919. workInProgress,
  11920. renderExpirationTime
  11921. );
  11922. } else {
  11923. pushSuspenseContext(
  11924. workInProgress,
  11925. setDefaultShallowSuspenseContext(suspenseStackCursor.current)
  11926. ); // The primary children do not have pending work with sufficient
  11927. // priority. Bailout.
  11928. var child = bailoutOnAlreadyFinishedWork(
  11929. current,
  11930. workInProgress,
  11931. renderExpirationTime
  11932. );
  11933. if (child !== null) {
  11934. // The fallback children have pending work. Skip over the
  11935. // primary children and work on the fallback.
  11936. return child.sibling;
  11937. } else {
  11938. return null;
  11939. }
  11940. }
  11941. } else {
  11942. pushSuspenseContext(
  11943. workInProgress,
  11944. setDefaultShallowSuspenseContext(suspenseStackCursor.current)
  11945. );
  11946. }
  11947. break;
  11948. }
  11949. case SuspenseListComponent: {
  11950. var didSuspendBefore = (current.effectTag & DidCapture) !== NoEffect;
  11951. var _hasChildWork =
  11952. workInProgress.childExpirationTime >= renderExpirationTime;
  11953. if (didSuspendBefore) {
  11954. if (_hasChildWork) {
  11955. // If something was in fallback state last time, and we have all the
  11956. // same children then we're still in progressive loading state.
  11957. // Something might get unblocked by state updates or retries in the
  11958. // tree which will affect the tail. So we need to use the normal
  11959. // path to compute the correct tail.
  11960. return updateSuspenseListComponent(
  11961. current,
  11962. workInProgress,
  11963. renderExpirationTime
  11964. );
  11965. } // If none of the children had any work, that means that none of
  11966. // them got retried so they'll still be blocked in the same way
  11967. // as before. We can fast bail out.
  11968. workInProgress.effectTag |= DidCapture;
  11969. } // If nothing suspended before and we're rendering the same children,
  11970. // then the tail doesn't matter. Anything new that suspends will work
  11971. // in the "together" mode, so we can continue from the state we had.
  11972. var renderState = workInProgress.memoizedState;
  11973. if (renderState !== null) {
  11974. // Reset to the "together" mode in case we've started a different
  11975. // update in the past but didn't complete it.
  11976. renderState.rendering = null;
  11977. renderState.tail = null;
  11978. }
  11979. pushSuspenseContext(workInProgress, suspenseStackCursor.current);
  11980. if (_hasChildWork) {
  11981. break;
  11982. } else {
  11983. // If none of the children had any work, that means that none of
  11984. // them got retried so they'll still be blocked in the same way
  11985. // as before. We can fast bail out.
  11986. return null;
  11987. }
  11988. }
  11989. }
  11990. return bailoutOnAlreadyFinishedWork(
  11991. current,
  11992. workInProgress,
  11993. renderExpirationTime
  11994. );
  11995. } else {
  11996. // An update was scheduled on this fiber, but there are no new props
  11997. // nor legacy context. Set this to false. If an update queue or context
  11998. // consumer produces a changed value, it will set this to true. Otherwise,
  11999. // the component will assume the children have not changed and bail out.
  12000. didReceiveUpdate = false;
  12001. }
  12002. } else {
  12003. didReceiveUpdate = false;
  12004. } // Before entering the begin phase, clear pending update priority.
  12005. // TODO: This assumes that we're about to evaluate the component and process
  12006. // the update queue. However, there's an exception: SimpleMemoComponent
  12007. // sometimes bails out later in the begin phase. This indicates that we should
  12008. // move this assignment out of the common path and into each branch.
  12009. workInProgress.expirationTime = NoWork;
  12010. switch (workInProgress.tag) {
  12011. case IndeterminateComponent: {
  12012. return mountIndeterminateComponent(
  12013. current,
  12014. workInProgress,
  12015. workInProgress.type,
  12016. renderExpirationTime
  12017. );
  12018. }
  12019. case LazyComponent: {
  12020. var elementType = workInProgress.elementType;
  12021. return mountLazyComponent(
  12022. current,
  12023. workInProgress,
  12024. elementType,
  12025. updateExpirationTime,
  12026. renderExpirationTime
  12027. );
  12028. }
  12029. case FunctionComponent: {
  12030. var _Component = workInProgress.type;
  12031. var unresolvedProps = workInProgress.pendingProps;
  12032. var resolvedProps =
  12033. workInProgress.elementType === _Component
  12034. ? unresolvedProps
  12035. : resolveDefaultProps(_Component, unresolvedProps);
  12036. return updateFunctionComponent(
  12037. current,
  12038. workInProgress,
  12039. _Component,
  12040. resolvedProps,
  12041. renderExpirationTime
  12042. );
  12043. }
  12044. case ClassComponent: {
  12045. var _Component2 = workInProgress.type;
  12046. var _unresolvedProps = workInProgress.pendingProps;
  12047. var _resolvedProps =
  12048. workInProgress.elementType === _Component2
  12049. ? _unresolvedProps
  12050. : resolveDefaultProps(_Component2, _unresolvedProps);
  12051. return updateClassComponent(
  12052. current,
  12053. workInProgress,
  12054. _Component2,
  12055. _resolvedProps,
  12056. renderExpirationTime
  12057. );
  12058. }
  12059. case HostRoot:
  12060. return updateHostRoot(current, workInProgress, renderExpirationTime);
  12061. case HostComponent:
  12062. return updateHostComponent(current, workInProgress, renderExpirationTime);
  12063. case HostText:
  12064. return updateHostText();
  12065. case SuspenseComponent:
  12066. return updateSuspenseComponent(
  12067. current,
  12068. workInProgress,
  12069. renderExpirationTime
  12070. );
  12071. case HostPortal:
  12072. return updatePortalComponent(
  12073. current,
  12074. workInProgress,
  12075. renderExpirationTime
  12076. );
  12077. case ForwardRef: {
  12078. var type = workInProgress.type;
  12079. var _unresolvedProps2 = workInProgress.pendingProps;
  12080. var _resolvedProps2 =
  12081. workInProgress.elementType === type
  12082. ? _unresolvedProps2
  12083. : resolveDefaultProps(type, _unresolvedProps2);
  12084. return updateForwardRef(
  12085. current,
  12086. workInProgress,
  12087. type,
  12088. _resolvedProps2,
  12089. renderExpirationTime
  12090. );
  12091. }
  12092. case Fragment:
  12093. return updateFragment(current, workInProgress, renderExpirationTime);
  12094. case Mode:
  12095. return updateMode(current, workInProgress, renderExpirationTime);
  12096. case Profiler:
  12097. return updateProfiler(current, workInProgress, renderExpirationTime);
  12098. case ContextProvider:
  12099. return updateContextProvider(
  12100. current,
  12101. workInProgress,
  12102. renderExpirationTime
  12103. );
  12104. case ContextConsumer:
  12105. return updateContextConsumer(
  12106. current,
  12107. workInProgress,
  12108. renderExpirationTime
  12109. );
  12110. case MemoComponent: {
  12111. var _type2 = workInProgress.type;
  12112. var _unresolvedProps3 = workInProgress.pendingProps; // Resolve outer props first, then resolve inner props.
  12113. var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
  12114. {
  12115. if (workInProgress.type !== workInProgress.elementType) {
  12116. var outerPropTypes = _type2.propTypes;
  12117. if (outerPropTypes) {
  12118. checkPropTypes(
  12119. outerPropTypes,
  12120. _resolvedProps3, // Resolved for outer only
  12121. "prop",
  12122. getComponentName(_type2)
  12123. );
  12124. }
  12125. }
  12126. }
  12127. _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
  12128. return updateMemoComponent(
  12129. current,
  12130. workInProgress,
  12131. _type2,
  12132. _resolvedProps3,
  12133. updateExpirationTime,
  12134. renderExpirationTime
  12135. );
  12136. }
  12137. case SimpleMemoComponent: {
  12138. return updateSimpleMemoComponent(
  12139. current,
  12140. workInProgress,
  12141. workInProgress.type,
  12142. workInProgress.pendingProps,
  12143. updateExpirationTime,
  12144. renderExpirationTime
  12145. );
  12146. }
  12147. case IncompleteClassComponent: {
  12148. var _Component3 = workInProgress.type;
  12149. var _unresolvedProps4 = workInProgress.pendingProps;
  12150. var _resolvedProps4 =
  12151. workInProgress.elementType === _Component3
  12152. ? _unresolvedProps4
  12153. : resolveDefaultProps(_Component3, _unresolvedProps4);
  12154. return mountIncompleteClassComponent(
  12155. current,
  12156. workInProgress,
  12157. _Component3,
  12158. _resolvedProps4,
  12159. renderExpirationTime
  12160. );
  12161. }
  12162. case SuspenseListComponent: {
  12163. return updateSuspenseListComponent(
  12164. current,
  12165. workInProgress,
  12166. renderExpirationTime
  12167. );
  12168. }
  12169. }
  12170. {
  12171. throw Error(
  12172. "Unknown unit of work tag (" +
  12173. workInProgress.tag +
  12174. "). This error is likely caused by a bug in React. Please file an issue."
  12175. );
  12176. }
  12177. }
  12178. function markUpdate(workInProgress) {
  12179. // Tag the fiber with an update effect. This turns a Placement into
  12180. // a PlacementAndUpdate.
  12181. workInProgress.effectTag |= Update;
  12182. }
  12183. function markRef$1(workInProgress) {
  12184. workInProgress.effectTag |= Ref;
  12185. }
  12186. var appendAllChildren;
  12187. var updateHostContainer;
  12188. var updateHostComponent$1;
  12189. var updateHostText$1;
  12190. {
  12191. // Persistent host tree mode
  12192. appendAllChildren = function(
  12193. parent,
  12194. workInProgress,
  12195. needsVisibilityToggle,
  12196. isHidden
  12197. ) {
  12198. // We only have the top Fiber that was created but we need recurse down its
  12199. // children to find all the terminal nodes.
  12200. var node = workInProgress.child;
  12201. while (node !== null) {
  12202. // eslint-disable-next-line no-labels
  12203. if (node.tag === HostComponent) {
  12204. var instance = node.stateNode;
  12205. if (needsVisibilityToggle && isHidden) {
  12206. // This child is inside a timed out tree. Hide it.
  12207. var props = node.memoizedProps;
  12208. var type = node.type;
  12209. instance = cloneHiddenInstance(instance);
  12210. }
  12211. appendInitialChild(parent, instance);
  12212. } else if (node.tag === HostText) {
  12213. var _instance = node.stateNode;
  12214. if (needsVisibilityToggle && isHidden) {
  12215. // This child is inside a timed out tree. Hide it.
  12216. var text = node.memoizedProps;
  12217. _instance = cloneHiddenTextInstance();
  12218. }
  12219. appendInitialChild(parent, _instance);
  12220. } else if (node.tag === HostPortal);
  12221. else if (node.tag === SuspenseComponent) {
  12222. if ((node.effectTag & Update) !== NoEffect) {
  12223. // Need to toggle the visibility of the primary children.
  12224. var newIsHidden = node.memoizedState !== null;
  12225. if (newIsHidden) {
  12226. var primaryChildParent = node.child;
  12227. if (primaryChildParent !== null) {
  12228. if (primaryChildParent.child !== null) {
  12229. primaryChildParent.child.return = primaryChildParent;
  12230. appendAllChildren(
  12231. parent,
  12232. primaryChildParent,
  12233. true,
  12234. newIsHidden
  12235. );
  12236. }
  12237. var fallbackChildParent = primaryChildParent.sibling;
  12238. if (fallbackChildParent !== null) {
  12239. fallbackChildParent.return = node;
  12240. node = fallbackChildParent;
  12241. continue;
  12242. }
  12243. }
  12244. }
  12245. }
  12246. if (node.child !== null) {
  12247. // Continue traversing like normal
  12248. node.child.return = node;
  12249. node = node.child;
  12250. continue;
  12251. }
  12252. } else if (node.child !== null) {
  12253. node.child.return = node;
  12254. node = node.child;
  12255. continue;
  12256. } // $FlowFixMe This is correct but Flow is confused by the labeled break.
  12257. node = node;
  12258. if (node === workInProgress) {
  12259. return;
  12260. }
  12261. while (node.sibling === null) {
  12262. if (node.return === null || node.return === workInProgress) {
  12263. return;
  12264. }
  12265. node = node.return;
  12266. }
  12267. node.sibling.return = node.return;
  12268. node = node.sibling;
  12269. }
  12270. }; // An unfortunate fork of appendAllChildren because we have two different parent types.
  12271. var appendAllChildrenToContainer = function(
  12272. containerChildSet,
  12273. workInProgress,
  12274. needsVisibilityToggle,
  12275. isHidden
  12276. ) {
  12277. // We only have the top Fiber that was created but we need recurse down its
  12278. // children to find all the terminal nodes.
  12279. var node = workInProgress.child;
  12280. while (node !== null) {
  12281. // eslint-disable-next-line no-labels
  12282. if (node.tag === HostComponent) {
  12283. var instance = node.stateNode;
  12284. if (needsVisibilityToggle && isHidden) {
  12285. // This child is inside a timed out tree. Hide it.
  12286. var props = node.memoizedProps;
  12287. var type = node.type;
  12288. instance = cloneHiddenInstance(instance);
  12289. }
  12290. appendChildToContainerChildSet(containerChildSet, instance);
  12291. } else if (node.tag === HostText) {
  12292. var _instance3 = node.stateNode;
  12293. if (needsVisibilityToggle && isHidden) {
  12294. // This child is inside a timed out tree. Hide it.
  12295. var text = node.memoizedProps;
  12296. _instance3 = cloneHiddenTextInstance();
  12297. }
  12298. appendChildToContainerChildSet(containerChildSet, _instance3);
  12299. } else if (node.tag === HostPortal);
  12300. else if (node.tag === SuspenseComponent) {
  12301. if ((node.effectTag & Update) !== NoEffect) {
  12302. // Need to toggle the visibility of the primary children.
  12303. var newIsHidden = node.memoizedState !== null;
  12304. if (newIsHidden) {
  12305. var primaryChildParent = node.child;
  12306. if (primaryChildParent !== null) {
  12307. if (primaryChildParent.child !== null) {
  12308. primaryChildParent.child.return = primaryChildParent;
  12309. appendAllChildrenToContainer(
  12310. containerChildSet,
  12311. primaryChildParent,
  12312. true,
  12313. newIsHidden
  12314. );
  12315. }
  12316. var fallbackChildParent = primaryChildParent.sibling;
  12317. if (fallbackChildParent !== null) {
  12318. fallbackChildParent.return = node;
  12319. node = fallbackChildParent;
  12320. continue;
  12321. }
  12322. }
  12323. }
  12324. }
  12325. if (node.child !== null) {
  12326. // Continue traversing like normal
  12327. node.child.return = node;
  12328. node = node.child;
  12329. continue;
  12330. }
  12331. } else if (node.child !== null) {
  12332. node.child.return = node;
  12333. node = node.child;
  12334. continue;
  12335. } // $FlowFixMe This is correct but Flow is confused by the labeled break.
  12336. node = node;
  12337. if (node === workInProgress) {
  12338. return;
  12339. }
  12340. while (node.sibling === null) {
  12341. if (node.return === null || node.return === workInProgress) {
  12342. return;
  12343. }
  12344. node = node.return;
  12345. }
  12346. node.sibling.return = node.return;
  12347. node = node.sibling;
  12348. }
  12349. };
  12350. updateHostContainer = function(workInProgress) {
  12351. var portalOrRoot = workInProgress.stateNode;
  12352. var childrenUnchanged = workInProgress.firstEffect === null;
  12353. if (childrenUnchanged);
  12354. else {
  12355. var container = portalOrRoot.containerInfo;
  12356. var newChildSet = createContainerChildSet(container); // If children might have changed, we have to add them all to the set.
  12357. appendAllChildrenToContainer(newChildSet, workInProgress, false, false);
  12358. portalOrRoot.pendingChildren = newChildSet; // Schedule an update on the container to swap out the container.
  12359. markUpdate(workInProgress);
  12360. finalizeContainerChildren(container, newChildSet);
  12361. }
  12362. };
  12363. updateHostComponent$1 = function(
  12364. current,
  12365. workInProgress,
  12366. type,
  12367. newProps,
  12368. rootContainerInstance
  12369. ) {
  12370. var currentInstance = current.stateNode;
  12371. var oldProps = current.memoizedProps; // If there are no effects associated with this node, then none of our children had any updates.
  12372. // This guarantees that we can reuse all of them.
  12373. var childrenUnchanged = workInProgress.firstEffect === null;
  12374. if (childrenUnchanged && oldProps === newProps) {
  12375. // No changes, just reuse the existing instance.
  12376. // Note that this might release a previous clone.
  12377. workInProgress.stateNode = currentInstance;
  12378. return;
  12379. }
  12380. var recyclableInstance = workInProgress.stateNode;
  12381. var currentHostContext = getHostContext();
  12382. var updatePayload = null;
  12383. if (oldProps !== newProps) {
  12384. updatePayload = prepareUpdate(
  12385. recyclableInstance,
  12386. type,
  12387. oldProps,
  12388. newProps
  12389. );
  12390. }
  12391. if (childrenUnchanged && updatePayload === null) {
  12392. // No changes, just reuse the existing instance.
  12393. // Note that this might release a previous clone.
  12394. workInProgress.stateNode = currentInstance;
  12395. return;
  12396. }
  12397. var newInstance = cloneInstance(
  12398. currentInstance,
  12399. updatePayload,
  12400. type,
  12401. oldProps,
  12402. newProps,
  12403. workInProgress,
  12404. childrenUnchanged
  12405. );
  12406. workInProgress.stateNode = newInstance;
  12407. if (childrenUnchanged) {
  12408. // If there are no other effects in this tree, we need to flag this node as having one.
  12409. // Even though we're not going to use it for anything.
  12410. // Otherwise parents won't know that there are new children to propagate upwards.
  12411. markUpdate(workInProgress);
  12412. } else {
  12413. // If children might have changed, we have to add them all to the set.
  12414. appendAllChildren(newInstance, workInProgress, false, false);
  12415. }
  12416. };
  12417. updateHostText$1 = function(current, workInProgress, oldText, newText) {
  12418. if (oldText !== newText) {
  12419. // If the text content differs, we'll create a new text instance for it.
  12420. var rootContainerInstance = getRootHostContainer();
  12421. var currentHostContext = getHostContext();
  12422. workInProgress.stateNode = createTextInstance(
  12423. newText,
  12424. rootContainerInstance,
  12425. currentHostContext,
  12426. workInProgress
  12427. ); // We'll have to mark it as having an effect, even though we won't use the effect for anything.
  12428. // This lets the parents know that at least one of their children has changed.
  12429. markUpdate(workInProgress);
  12430. } else {
  12431. workInProgress.stateNode = current.stateNode;
  12432. }
  12433. };
  12434. }
  12435. function cutOffTailIfNeeded(renderState, hasRenderedATailFallback) {
  12436. switch (renderState.tailMode) {
  12437. case "hidden": {
  12438. // Any insertions at the end of the tail list after this point
  12439. // should be invisible. If there are already mounted boundaries
  12440. // anything before them are not considered for collapsing.
  12441. // Therefore we need to go through the whole tail to find if
  12442. // there are any.
  12443. var tailNode = renderState.tail;
  12444. var lastTailNode = null;
  12445. while (tailNode !== null) {
  12446. if (tailNode.alternate !== null) {
  12447. lastTailNode = tailNode;
  12448. }
  12449. tailNode = tailNode.sibling;
  12450. } // Next we're simply going to delete all insertions after the
  12451. // last rendered item.
  12452. if (lastTailNode === null) {
  12453. // All remaining items in the tail are insertions.
  12454. renderState.tail = null;
  12455. } else {
  12456. // Detach the insertion after the last node that was already
  12457. // inserted.
  12458. lastTailNode.sibling = null;
  12459. }
  12460. break;
  12461. }
  12462. case "collapsed": {
  12463. // Any insertions at the end of the tail list after this point
  12464. // should be invisible. If there are already mounted boundaries
  12465. // anything before them are not considered for collapsing.
  12466. // Therefore we need to go through the whole tail to find if
  12467. // there are any.
  12468. var _tailNode = renderState.tail;
  12469. var _lastTailNode = null;
  12470. while (_tailNode !== null) {
  12471. if (_tailNode.alternate !== null) {
  12472. _lastTailNode = _tailNode;
  12473. }
  12474. _tailNode = _tailNode.sibling;
  12475. } // Next we're simply going to delete all insertions after the
  12476. // last rendered item.
  12477. if (_lastTailNode === null) {
  12478. // All remaining items in the tail are insertions.
  12479. if (!hasRenderedATailFallback && renderState.tail !== null) {
  12480. // We suspended during the head. We want to show at least one
  12481. // row at the tail. So we'll keep on and cut off the rest.
  12482. renderState.tail.sibling = null;
  12483. } else {
  12484. renderState.tail = null;
  12485. }
  12486. } else {
  12487. // Detach the insertion after the last node that was already
  12488. // inserted.
  12489. _lastTailNode.sibling = null;
  12490. }
  12491. break;
  12492. }
  12493. }
  12494. }
  12495. function completeWork(current, workInProgress, renderExpirationTime) {
  12496. var newProps = workInProgress.pendingProps;
  12497. switch (workInProgress.tag) {
  12498. case IndeterminateComponent:
  12499. case LazyComponent:
  12500. case SimpleMemoComponent:
  12501. case FunctionComponent:
  12502. case ForwardRef:
  12503. case Fragment:
  12504. case Mode:
  12505. case Profiler:
  12506. case ContextConsumer:
  12507. case MemoComponent:
  12508. return null;
  12509. case ClassComponent: {
  12510. var Component = workInProgress.type;
  12511. if (isContextProvider(Component)) {
  12512. popContext(workInProgress);
  12513. }
  12514. return null;
  12515. }
  12516. case HostRoot: {
  12517. popHostContainer(workInProgress);
  12518. popTopLevelContextObject(workInProgress);
  12519. var fiberRoot = workInProgress.stateNode;
  12520. if (fiberRoot.pendingContext) {
  12521. fiberRoot.context = fiberRoot.pendingContext;
  12522. fiberRoot.pendingContext = null;
  12523. }
  12524. if (current === null || current.child === null) {
  12525. // If we hydrated, pop so that we can delete any remaining children
  12526. // that weren't hydrated.
  12527. var wasHydrated = popHydrationState();
  12528. if (wasHydrated) {
  12529. // If we hydrated, then we'll need to schedule an update for
  12530. // the commit side-effects on the root.
  12531. markUpdate(workInProgress);
  12532. }
  12533. }
  12534. updateHostContainer(workInProgress);
  12535. return null;
  12536. }
  12537. case HostComponent: {
  12538. popHostContext(workInProgress);
  12539. var rootContainerInstance = getRootHostContainer();
  12540. var type = workInProgress.type;
  12541. if (current !== null && workInProgress.stateNode != null) {
  12542. updateHostComponent$1(
  12543. current,
  12544. workInProgress,
  12545. type,
  12546. newProps,
  12547. rootContainerInstance
  12548. );
  12549. if (current.ref !== workInProgress.ref) {
  12550. markRef$1(workInProgress);
  12551. }
  12552. } else {
  12553. if (!newProps) {
  12554. if (!(workInProgress.stateNode !== null)) {
  12555. throw Error(
  12556. "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue."
  12557. );
  12558. } // This can happen when we abort work.
  12559. return null;
  12560. }
  12561. var currentHostContext = getHostContext(); // TODO: Move createInstance to beginWork and keep it on a context
  12562. // "stack" as the parent. Then append children as we go in beginWork
  12563. // or completeWork depending on whether we want to add them top->down or
  12564. // bottom->up. Top->down is faster in IE11.
  12565. var _wasHydrated = popHydrationState();
  12566. if (_wasHydrated) {
  12567. // TODO: Move this and createInstance step into the beginPhase
  12568. // to consolidate.
  12569. if (prepareToHydrateHostInstance()) {
  12570. // If changes to the hydrated node need to be applied at the
  12571. // commit-phase we mark this as such.
  12572. markUpdate(workInProgress);
  12573. }
  12574. } else {
  12575. var instance = createInstance(
  12576. type,
  12577. newProps,
  12578. rootContainerInstance,
  12579. currentHostContext,
  12580. workInProgress
  12581. );
  12582. appendAllChildren(instance, workInProgress, false, false); // This needs to be set before we mount Flare event listeners
  12583. workInProgress.stateNode = instance;
  12584. }
  12585. if (workInProgress.ref !== null) {
  12586. // If there is a ref on a host node we need to schedule a callback
  12587. markRef$1(workInProgress);
  12588. }
  12589. }
  12590. return null;
  12591. }
  12592. case HostText: {
  12593. var newText = newProps;
  12594. if (current && workInProgress.stateNode != null) {
  12595. var oldText = current.memoizedProps; // If we have an alternate, that means this is an update and we need
  12596. // to schedule a side-effect to do the updates.
  12597. updateHostText$1(current, workInProgress, oldText, newText);
  12598. } else {
  12599. if (typeof newText !== "string") {
  12600. if (!(workInProgress.stateNode !== null)) {
  12601. throw Error(
  12602. "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue."
  12603. );
  12604. } // This can happen when we abort work.
  12605. }
  12606. var _rootContainerInstance = getRootHostContainer();
  12607. var _currentHostContext = getHostContext();
  12608. var _wasHydrated2 = popHydrationState();
  12609. if (_wasHydrated2) {
  12610. if (prepareToHydrateHostTextInstance()) {
  12611. markUpdate(workInProgress);
  12612. }
  12613. } else {
  12614. workInProgress.stateNode = createTextInstance(
  12615. newText,
  12616. _rootContainerInstance,
  12617. _currentHostContext,
  12618. workInProgress
  12619. );
  12620. }
  12621. }
  12622. return null;
  12623. }
  12624. case SuspenseComponent: {
  12625. popSuspenseContext(workInProgress);
  12626. var nextState = workInProgress.memoizedState;
  12627. if ((workInProgress.effectTag & DidCapture) !== NoEffect) {
  12628. // Something suspended. Re-render with the fallback children.
  12629. workInProgress.expirationTime = renderExpirationTime; // Do not reset the effect list.
  12630. return workInProgress;
  12631. }
  12632. var nextDidTimeout = nextState !== null;
  12633. var prevDidTimeout = false;
  12634. if (current === null) {
  12635. if (workInProgress.memoizedProps.fallback !== undefined);
  12636. } else {
  12637. var prevState = current.memoizedState;
  12638. prevDidTimeout = prevState !== null;
  12639. if (!nextDidTimeout && prevState !== null) {
  12640. // We just switched from the fallback to the normal children.
  12641. // Delete the fallback.
  12642. // TODO: Would it be better to store the fallback fragment on
  12643. // the stateNode during the begin phase?
  12644. var currentFallbackChild = current.child.sibling;
  12645. if (currentFallbackChild !== null) {
  12646. // Deletions go at the beginning of the return fiber's effect list
  12647. var first = workInProgress.firstEffect;
  12648. if (first !== null) {
  12649. workInProgress.firstEffect = currentFallbackChild;
  12650. currentFallbackChild.nextEffect = first;
  12651. } else {
  12652. workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChild;
  12653. currentFallbackChild.nextEffect = null;
  12654. }
  12655. currentFallbackChild.effectTag = Deletion;
  12656. }
  12657. }
  12658. }
  12659. if (nextDidTimeout && !prevDidTimeout) {
  12660. // If this subtreee is running in blocking mode we can suspend,
  12661. // otherwise we won't suspend.
  12662. // TODO: This will still suspend a synchronous tree if anything
  12663. // in the concurrent tree already suspended during this render.
  12664. // This is a known bug.
  12665. if ((workInProgress.mode & BlockingMode) !== NoMode) {
  12666. // TODO: Move this back to throwException because this is too late
  12667. // if this is a large tree which is common for initial loads. We
  12668. // don't know if we should restart a render or not until we get
  12669. // this marker, and this is too late.
  12670. // If this render already had a ping or lower pri updates,
  12671. // and this is the first time we know we're going to suspend we
  12672. // should be able to immediately restart from within throwException.
  12673. var hasInvisibleChildContext =
  12674. current === null &&
  12675. workInProgress.memoizedProps.unstable_avoidThisFallback !== true;
  12676. if (
  12677. hasInvisibleChildContext ||
  12678. hasSuspenseContext(
  12679. suspenseStackCursor.current,
  12680. InvisibleParentSuspenseContext
  12681. )
  12682. ) {
  12683. // If this was in an invisible tree or a new render, then showing
  12684. // this boundary is ok.
  12685. renderDidSuspend();
  12686. } else {
  12687. // Otherwise, we're going to have to hide content so we should
  12688. // suspend for longer if possible.
  12689. renderDidSuspendDelayIfPossible();
  12690. }
  12691. }
  12692. }
  12693. {
  12694. // TODO: Only schedule updates if not prevDidTimeout.
  12695. if (nextDidTimeout) {
  12696. // If this boundary just timed out, schedule an effect to attach a
  12697. // retry listener to the promise. This flag is also used to hide the
  12698. // primary children.
  12699. workInProgress.effectTag |= Update;
  12700. }
  12701. }
  12702. return null;
  12703. }
  12704. case HostPortal:
  12705. popHostContainer(workInProgress);
  12706. updateHostContainer(workInProgress);
  12707. return null;
  12708. case ContextProvider:
  12709. // Pop provider fiber
  12710. popProvider(workInProgress);
  12711. return null;
  12712. case IncompleteClassComponent: {
  12713. // Same as class component case. I put it down here so that the tags are
  12714. // sequential to ensure this switch is compiled to a jump table.
  12715. var _Component = workInProgress.type;
  12716. if (isContextProvider(_Component)) {
  12717. popContext(workInProgress);
  12718. }
  12719. return null;
  12720. }
  12721. case SuspenseListComponent: {
  12722. popSuspenseContext(workInProgress);
  12723. var renderState = workInProgress.memoizedState;
  12724. if (renderState === null) {
  12725. // We're running in the default, "independent" mode.
  12726. // We don't do anything in this mode.
  12727. return null;
  12728. }
  12729. var didSuspendAlready =
  12730. (workInProgress.effectTag & DidCapture) !== NoEffect;
  12731. var renderedTail = renderState.rendering;
  12732. if (renderedTail === null) {
  12733. // We just rendered the head.
  12734. if (!didSuspendAlready) {
  12735. // This is the first pass. We need to figure out if anything is still
  12736. // suspended in the rendered set.
  12737. // If new content unsuspended, but there's still some content that
  12738. // didn't. Then we need to do a second pass that forces everything
  12739. // to keep showing their fallbacks.
  12740. // We might be suspended if something in this render pass suspended, or
  12741. // something in the previous committed pass suspended. Otherwise,
  12742. // there's no chance so we can skip the expensive call to
  12743. // findFirstSuspended.
  12744. var cannotBeSuspended =
  12745. renderHasNotSuspendedYet() &&
  12746. (current === null || (current.effectTag & DidCapture) === NoEffect);
  12747. if (!cannotBeSuspended) {
  12748. var row = workInProgress.child;
  12749. while (row !== null) {
  12750. var suspended = findFirstSuspended(row);
  12751. if (suspended !== null) {
  12752. didSuspendAlready = true;
  12753. workInProgress.effectTag |= DidCapture;
  12754. cutOffTailIfNeeded(renderState, false); // If this is a newly suspended tree, it might not get committed as
  12755. // part of the second pass. In that case nothing will subscribe to
  12756. // its thennables. Instead, we'll transfer its thennables to the
  12757. // SuspenseList so that it can retry if they resolve.
  12758. // There might be multiple of these in the list but since we're
  12759. // going to wait for all of them anyway, it doesn't really matter
  12760. // which ones gets to ping. In theory we could get clever and keep
  12761. // track of how many dependencies remain but it gets tricky because
  12762. // in the meantime, we can add/remove/change items and dependencies.
  12763. // We might bail out of the loop before finding any but that
  12764. // doesn't matter since that means that the other boundaries that
  12765. // we did find already has their listeners attached.
  12766. var newThennables = suspended.updateQueue;
  12767. if (newThennables !== null) {
  12768. workInProgress.updateQueue = newThennables;
  12769. workInProgress.effectTag |= Update;
  12770. } // Rerender the whole list, but this time, we'll force fallbacks
  12771. // to stay in place.
  12772. // Reset the effect list before doing the second pass since that's now invalid.
  12773. if (renderState.lastEffect === null) {
  12774. workInProgress.firstEffect = null;
  12775. }
  12776. workInProgress.lastEffect = renderState.lastEffect; // Reset the child fibers to their original state.
  12777. resetChildFibers(workInProgress, renderExpirationTime); // Set up the Suspense Context to force suspense and immediately
  12778. // rerender the children.
  12779. pushSuspenseContext(
  12780. workInProgress,
  12781. setShallowSuspenseContext(
  12782. suspenseStackCursor.current,
  12783. ForceSuspenseFallback
  12784. )
  12785. );
  12786. return workInProgress.child;
  12787. }
  12788. row = row.sibling;
  12789. }
  12790. }
  12791. } else {
  12792. cutOffTailIfNeeded(renderState, false);
  12793. } // Next we're going to render the tail.
  12794. } else {
  12795. // Append the rendered row to the child list.
  12796. if (!didSuspendAlready) {
  12797. var _suspended = findFirstSuspended(renderedTail);
  12798. if (_suspended !== null) {
  12799. workInProgress.effectTag |= DidCapture;
  12800. didSuspendAlready = true; // Ensure we transfer the update queue to the parent so that it doesn't
  12801. // get lost if this row ends up dropped during a second pass.
  12802. var _newThennables = _suspended.updateQueue;
  12803. if (_newThennables !== null) {
  12804. workInProgress.updateQueue = _newThennables;
  12805. workInProgress.effectTag |= Update;
  12806. }
  12807. cutOffTailIfNeeded(renderState, true); // This might have been modified.
  12808. if (
  12809. renderState.tail === null &&
  12810. renderState.tailMode === "hidden" &&
  12811. !renderedTail.alternate
  12812. ) {
  12813. // We need to delete the row we just rendered.
  12814. // Reset the effect list to what it was before we rendered this
  12815. // child. The nested children have already appended themselves.
  12816. var lastEffect = (workInProgress.lastEffect =
  12817. renderState.lastEffect); // Remove any effects that were appended after this point.
  12818. if (lastEffect !== null) {
  12819. lastEffect.nextEffect = null;
  12820. } // We're done.
  12821. return null;
  12822. }
  12823. } else if (
  12824. // The time it took to render last row is greater than time until
  12825. // the expiration.
  12826. now() * 2 - renderState.renderingStartTime >
  12827. renderState.tailExpiration &&
  12828. renderExpirationTime > Never
  12829. ) {
  12830. // We have now passed our CPU deadline and we'll just give up further
  12831. // attempts to render the main content and only render fallbacks.
  12832. // The assumption is that this is usually faster.
  12833. workInProgress.effectTag |= DidCapture;
  12834. didSuspendAlready = true;
  12835. cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
  12836. // to get it started back up to attempt the next item. If we can show
  12837. // them, then they really have the same priority as this render.
  12838. // So we'll pick it back up the very next render pass once we've had
  12839. // an opportunity to yield for paint.
  12840. var nextPriority = renderExpirationTime - 1;
  12841. workInProgress.expirationTime = workInProgress.childExpirationTime = nextPriority;
  12842. {
  12843. markSpawnedWork(nextPriority);
  12844. }
  12845. }
  12846. }
  12847. if (renderState.isBackwards) {
  12848. // The effect list of the backwards tail will have been added
  12849. // to the end. This breaks the guarantee that life-cycles fire in
  12850. // sibling order but that isn't a strong guarantee promised by React.
  12851. // Especially since these might also just pop in during future commits.
  12852. // Append to the beginning of the list.
  12853. renderedTail.sibling = workInProgress.child;
  12854. workInProgress.child = renderedTail;
  12855. } else {
  12856. var previousSibling = renderState.last;
  12857. if (previousSibling !== null) {
  12858. previousSibling.sibling = renderedTail;
  12859. } else {
  12860. workInProgress.child = renderedTail;
  12861. }
  12862. renderState.last = renderedTail;
  12863. }
  12864. }
  12865. if (renderState.tail !== null) {
  12866. // We still have tail rows to render.
  12867. if (renderState.tailExpiration === 0) {
  12868. // Heuristic for how long we're willing to spend rendering rows
  12869. // until we just give up and show what we have so far.
  12870. var TAIL_EXPIRATION_TIMEOUT_MS = 500;
  12871. renderState.tailExpiration = now() + TAIL_EXPIRATION_TIMEOUT_MS; // TODO: This is meant to mimic the train model or JND but this
  12872. // is a per component value. It should really be since the start
  12873. // of the total render or last commit. Consider using something like
  12874. // globalMostRecentFallbackTime. That doesn't account for being
  12875. // suspended for part of the time or when it's a new render.
  12876. // It should probably use a global start time value instead.
  12877. } // Pop a row.
  12878. var next = renderState.tail;
  12879. renderState.rendering = next;
  12880. renderState.tail = next.sibling;
  12881. renderState.lastEffect = workInProgress.lastEffect;
  12882. renderState.renderingStartTime = now();
  12883. next.sibling = null; // Restore the context.
  12884. // TODO: We can probably just avoid popping it instead and only
  12885. // setting it the first time we go from not suspended to suspended.
  12886. var suspenseContext = suspenseStackCursor.current;
  12887. if (didSuspendAlready) {
  12888. suspenseContext = setShallowSuspenseContext(
  12889. suspenseContext,
  12890. ForceSuspenseFallback
  12891. );
  12892. } else {
  12893. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  12894. }
  12895. pushSuspenseContext(workInProgress, suspenseContext); // Do a pass over the next row.
  12896. return next;
  12897. }
  12898. return null;
  12899. }
  12900. }
  12901. {
  12902. throw Error(
  12903. "Unknown unit of work tag (" +
  12904. workInProgress.tag +
  12905. "). This error is likely caused by a bug in React. Please file an issue."
  12906. );
  12907. }
  12908. }
  12909. function unwindWork(workInProgress, renderExpirationTime) {
  12910. switch (workInProgress.tag) {
  12911. case ClassComponent: {
  12912. var Component = workInProgress.type;
  12913. if (isContextProvider(Component)) {
  12914. popContext(workInProgress);
  12915. }
  12916. var effectTag = workInProgress.effectTag;
  12917. if (effectTag & ShouldCapture) {
  12918. workInProgress.effectTag = (effectTag & ~ShouldCapture) | DidCapture;
  12919. return workInProgress;
  12920. }
  12921. return null;
  12922. }
  12923. case HostRoot: {
  12924. popHostContainer(workInProgress);
  12925. popTopLevelContextObject(workInProgress);
  12926. var _effectTag = workInProgress.effectTag;
  12927. if (!((_effectTag & DidCapture) === NoEffect)) {
  12928. throw Error(
  12929. "The root failed to unmount after an error. This is likely a bug in React. Please file an issue."
  12930. );
  12931. }
  12932. workInProgress.effectTag = (_effectTag & ~ShouldCapture) | DidCapture;
  12933. return workInProgress;
  12934. }
  12935. case HostComponent: {
  12936. // TODO: popHydrationState
  12937. popHostContext(workInProgress);
  12938. return null;
  12939. }
  12940. case SuspenseComponent: {
  12941. popSuspenseContext(workInProgress);
  12942. var _effectTag2 = workInProgress.effectTag;
  12943. if (_effectTag2 & ShouldCapture) {
  12944. workInProgress.effectTag = (_effectTag2 & ~ShouldCapture) | DidCapture; // Captured a suspense effect. Re-render the boundary.
  12945. return workInProgress;
  12946. }
  12947. return null;
  12948. }
  12949. case SuspenseListComponent: {
  12950. popSuspenseContext(workInProgress); // SuspenseList doesn't actually catch anything. It should've been
  12951. // caught by a nested boundary. If not, it should bubble through.
  12952. return null;
  12953. }
  12954. case HostPortal:
  12955. popHostContainer(workInProgress);
  12956. return null;
  12957. case ContextProvider:
  12958. popProvider(workInProgress);
  12959. return null;
  12960. default:
  12961. return null;
  12962. }
  12963. }
  12964. function unwindInterruptedWork(interruptedWork) {
  12965. switch (interruptedWork.tag) {
  12966. case ClassComponent: {
  12967. var childContextTypes = interruptedWork.type.childContextTypes;
  12968. if (childContextTypes !== null && childContextTypes !== undefined) {
  12969. popContext(interruptedWork);
  12970. }
  12971. break;
  12972. }
  12973. case HostRoot: {
  12974. popHostContainer(interruptedWork);
  12975. popTopLevelContextObject(interruptedWork);
  12976. break;
  12977. }
  12978. case HostComponent: {
  12979. popHostContext(interruptedWork);
  12980. break;
  12981. }
  12982. case HostPortal:
  12983. popHostContainer(interruptedWork);
  12984. break;
  12985. case SuspenseComponent:
  12986. popSuspenseContext(interruptedWork);
  12987. break;
  12988. case SuspenseListComponent:
  12989. popSuspenseContext(interruptedWork);
  12990. break;
  12991. case ContextProvider:
  12992. popProvider(interruptedWork);
  12993. break;
  12994. }
  12995. }
  12996. function createCapturedValue(value, source) {
  12997. // If the value is an error, call this function immediately after it is thrown
  12998. // so the stack is accurate.
  12999. return {
  13000. value: value,
  13001. source: source,
  13002. stack: getStackByFiberInDevAndProd(source)
  13003. };
  13004. }
  13005. // Module provided by RN:
  13006. if (
  13007. !(
  13008. typeof ReactNativePrivateInterface.ReactFiberErrorDialog.showErrorDialog ===
  13009. "function"
  13010. )
  13011. ) {
  13012. throw Error(
  13013. "Expected ReactFiberErrorDialog.showErrorDialog to be a function."
  13014. );
  13015. }
  13016. function showErrorDialog(capturedError) {
  13017. return ReactNativePrivateInterface.ReactFiberErrorDialog.showErrorDialog(
  13018. capturedError
  13019. );
  13020. }
  13021. function logCapturedError(capturedError) {
  13022. var logError = showErrorDialog(capturedError); // Allow injected showErrorDialog() to prevent default console.error logging.
  13023. // This enables renderers like ReactNative to better manage redbox behavior.
  13024. if (logError === false) {
  13025. return;
  13026. }
  13027. var error = capturedError.error;
  13028. {
  13029. var componentName = capturedError.componentName,
  13030. componentStack = capturedError.componentStack,
  13031. errorBoundaryName = capturedError.errorBoundaryName,
  13032. errorBoundaryFound = capturedError.errorBoundaryFound,
  13033. willRetry = capturedError.willRetry; // Browsers support silencing uncaught errors by calling
  13034. // `preventDefault()` in window `error` handler.
  13035. // We record this information as an expando on the error.
  13036. if (error != null && error._suppressLogging) {
  13037. if (errorBoundaryFound && willRetry) {
  13038. // The error is recoverable and was silenced.
  13039. // Ignore it and don't print the stack addendum.
  13040. // This is handy for testing error boundaries without noise.
  13041. return;
  13042. } // The error is fatal. Since the silencing might have
  13043. // been accidental, we'll surface it anyway.
  13044. // However, the browser would have silenced the original error
  13045. // so we'll print it first, and then print the stack addendum.
  13046. console["error"](error); // Don't transform to our wrapper
  13047. // For a more detailed description of this block, see:
  13048. // https://github.com/facebook/react/pull/13384
  13049. }
  13050. var componentNameMessage = componentName
  13051. ? "The above error occurred in the <" + componentName + "> component:"
  13052. : "The above error occurred in one of your React components:";
  13053. var errorBoundaryMessage; // errorBoundaryFound check is sufficient; errorBoundaryName check is to satisfy Flow.
  13054. if (errorBoundaryFound && errorBoundaryName) {
  13055. if (willRetry) {
  13056. errorBoundaryMessage =
  13057. "React will try to recreate this component tree from scratch " +
  13058. ("using the error boundary you provided, " + errorBoundaryName + ".");
  13059. } else {
  13060. errorBoundaryMessage =
  13061. "This error was initially handled by the error boundary " +
  13062. errorBoundaryName +
  13063. ".\n" +
  13064. "Recreating the tree from scratch failed so React will unmount the tree.";
  13065. }
  13066. } else {
  13067. errorBoundaryMessage =
  13068. "Consider adding an error boundary to your tree to customize error handling behavior.\n" +
  13069. "Visit https://fb.me/react-error-boundaries to learn more about error boundaries.";
  13070. }
  13071. var combinedMessage =
  13072. "" +
  13073. componentNameMessage +
  13074. componentStack +
  13075. "\n\n" +
  13076. ("" + errorBoundaryMessage); // In development, we provide our own message with just the component stack.
  13077. // We don't include the original error message and JS stack because the browser
  13078. // has already printed it. Even if the application swallows the error, it is still
  13079. // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
  13080. console["error"](combinedMessage); // Don't transform to our wrapper
  13081. }
  13082. }
  13083. var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
  13084. {
  13085. didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
  13086. }
  13087. var PossiblyWeakSet = typeof WeakSet === "function" ? WeakSet : Set;
  13088. function logError(boundary, errorInfo) {
  13089. var source = errorInfo.source;
  13090. var stack = errorInfo.stack;
  13091. if (stack === null && source !== null) {
  13092. stack = getStackByFiberInDevAndProd(source);
  13093. }
  13094. var capturedError = {
  13095. componentName: source !== null ? getComponentName(source.type) : null,
  13096. componentStack: stack !== null ? stack : "",
  13097. error: errorInfo.value,
  13098. errorBoundary: null,
  13099. errorBoundaryName: null,
  13100. errorBoundaryFound: false,
  13101. willRetry: false
  13102. };
  13103. if (boundary !== null && boundary.tag === ClassComponent) {
  13104. capturedError.errorBoundary = boundary.stateNode;
  13105. capturedError.errorBoundaryName = getComponentName(boundary.type);
  13106. capturedError.errorBoundaryFound = true;
  13107. capturedError.willRetry = true;
  13108. }
  13109. try {
  13110. logCapturedError(capturedError);
  13111. } catch (e) {
  13112. // This method must not throw, or React internal state will get messed up.
  13113. // If console.error is overridden, or logCapturedError() shows a dialog that throws,
  13114. // we want to report this error outside of the normal stack as a last resort.
  13115. // https://github.com/facebook/react/issues/13188
  13116. setTimeout(function() {
  13117. throw e;
  13118. });
  13119. }
  13120. }
  13121. var callComponentWillUnmountWithTimer = function(current, instance) {
  13122. startPhaseTimer(current, "componentWillUnmount");
  13123. instance.props = current.memoizedProps;
  13124. instance.state = current.memoizedState;
  13125. {
  13126. instance.componentWillUnmount();
  13127. }
  13128. stopPhaseTimer();
  13129. }; // Capture errors so they don't interrupt unmounting.
  13130. function safelyCallComponentWillUnmount(current, instance) {
  13131. {
  13132. invokeGuardedCallback(
  13133. null,
  13134. callComponentWillUnmountWithTimer,
  13135. null,
  13136. current,
  13137. instance
  13138. );
  13139. if (hasCaughtError()) {
  13140. var unmountError = clearCaughtError();
  13141. captureCommitPhaseError(current, unmountError);
  13142. }
  13143. }
  13144. }
  13145. function safelyDetachRef(current) {
  13146. var ref = current.ref;
  13147. if (ref !== null) {
  13148. if (typeof ref === "function") {
  13149. {
  13150. invokeGuardedCallback(null, ref, null, null);
  13151. if (hasCaughtError()) {
  13152. var refError = clearCaughtError();
  13153. captureCommitPhaseError(current, refError);
  13154. }
  13155. }
  13156. } else {
  13157. ref.current = null;
  13158. }
  13159. }
  13160. }
  13161. function safelyCallDestroy(current, destroy) {
  13162. {
  13163. invokeGuardedCallback(null, destroy, null);
  13164. if (hasCaughtError()) {
  13165. var error = clearCaughtError();
  13166. captureCommitPhaseError(current, error);
  13167. }
  13168. }
  13169. }
  13170. function commitBeforeMutationLifeCycles(current, finishedWork) {
  13171. switch (finishedWork.tag) {
  13172. case FunctionComponent:
  13173. case ForwardRef:
  13174. case SimpleMemoComponent:
  13175. case Block: {
  13176. return;
  13177. }
  13178. case ClassComponent: {
  13179. if (finishedWork.effectTag & Snapshot) {
  13180. if (current !== null) {
  13181. var prevProps = current.memoizedProps;
  13182. var prevState = current.memoizedState;
  13183. startPhaseTimer(finishedWork, "getSnapshotBeforeUpdate");
  13184. var instance = finishedWork.stateNode; // We could update instance props and state here,
  13185. // but instead we rely on them being set during last render.
  13186. // TODO: revisit this when we implement resuming.
  13187. {
  13188. if (
  13189. finishedWork.type === finishedWork.elementType &&
  13190. !didWarnAboutReassigningProps
  13191. ) {
  13192. if (instance.props !== finishedWork.memoizedProps) {
  13193. error(
  13194. "Expected %s props to match memoized props before " +
  13195. "getSnapshotBeforeUpdate. " +
  13196. "This might either be because of a bug in React, or because " +
  13197. "a component reassigns its own `this.props`. " +
  13198. "Please file an issue.",
  13199. getComponentName(finishedWork.type) || "instance"
  13200. );
  13201. }
  13202. if (instance.state !== finishedWork.memoizedState) {
  13203. error(
  13204. "Expected %s state to match memoized state before " +
  13205. "getSnapshotBeforeUpdate. " +
  13206. "This might either be because of a bug in React, or because " +
  13207. "a component reassigns its own `this.state`. " +
  13208. "Please file an issue.",
  13209. getComponentName(finishedWork.type) || "instance"
  13210. );
  13211. }
  13212. }
  13213. }
  13214. var snapshot = instance.getSnapshotBeforeUpdate(
  13215. finishedWork.elementType === finishedWork.type
  13216. ? prevProps
  13217. : resolveDefaultProps(finishedWork.type, prevProps),
  13218. prevState
  13219. );
  13220. {
  13221. var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
  13222. if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
  13223. didWarnSet.add(finishedWork.type);
  13224. error(
  13225. "%s.getSnapshotBeforeUpdate(): A snapshot value (or null) " +
  13226. "must be returned. You have returned undefined.",
  13227. getComponentName(finishedWork.type)
  13228. );
  13229. }
  13230. }
  13231. instance.__reactInternalSnapshotBeforeUpdate = snapshot;
  13232. stopPhaseTimer();
  13233. }
  13234. }
  13235. return;
  13236. }
  13237. case HostRoot:
  13238. case HostComponent:
  13239. case HostText:
  13240. case HostPortal:
  13241. case IncompleteClassComponent:
  13242. // Nothing to do for these component types
  13243. return;
  13244. }
  13245. {
  13246. throw Error(
  13247. "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."
  13248. );
  13249. }
  13250. }
  13251. function commitHookEffectListUnmount(tag, finishedWork) {
  13252. var updateQueue = finishedWork.updateQueue;
  13253. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  13254. if (lastEffect !== null) {
  13255. var firstEffect = lastEffect.next;
  13256. var effect = firstEffect;
  13257. do {
  13258. if ((effect.tag & tag) === tag) {
  13259. // Unmount
  13260. var destroy = effect.destroy;
  13261. effect.destroy = undefined;
  13262. if (destroy !== undefined) {
  13263. destroy();
  13264. }
  13265. }
  13266. effect = effect.next;
  13267. } while (effect !== firstEffect);
  13268. }
  13269. }
  13270. function commitHookEffectListMount(tag, finishedWork) {
  13271. var updateQueue = finishedWork.updateQueue;
  13272. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  13273. if (lastEffect !== null) {
  13274. var firstEffect = lastEffect.next;
  13275. var effect = firstEffect;
  13276. do {
  13277. if ((effect.tag & tag) === tag) {
  13278. // Mount
  13279. var create = effect.create;
  13280. effect.destroy = create();
  13281. {
  13282. var destroy = effect.destroy;
  13283. if (destroy !== undefined && typeof destroy !== "function") {
  13284. var addendum = void 0;
  13285. if (destroy === null) {
  13286. addendum =
  13287. " You returned null. If your effect does not require clean " +
  13288. "up, return undefined (or nothing).";
  13289. } else if (typeof destroy.then === "function") {
  13290. addendum =
  13291. "\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. " +
  13292. "Instead, write the async function inside your effect " +
  13293. "and call it immediately:\n\n" +
  13294. "useEffect(() => {\n" +
  13295. " async function fetchData() {\n" +
  13296. " // You can await here\n" +
  13297. " const response = await MyAPI.getData(someId);\n" +
  13298. " // ...\n" +
  13299. " }\n" +
  13300. " fetchData();\n" +
  13301. "}, [someId]); // Or [] if effect doesn't need props or state\n\n" +
  13302. "Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching";
  13303. } else {
  13304. addendum = " You returned: " + destroy;
  13305. }
  13306. error(
  13307. "An effect function must not return anything besides a function, " +
  13308. "which is used for clean-up.%s%s",
  13309. addendum,
  13310. getStackByFiberInDevAndProd(finishedWork)
  13311. );
  13312. }
  13313. }
  13314. }
  13315. effect = effect.next;
  13316. } while (effect !== firstEffect);
  13317. }
  13318. }
  13319. function commitPassiveHookEffects(finishedWork) {
  13320. if ((finishedWork.effectTag & Passive) !== NoEffect) {
  13321. switch (finishedWork.tag) {
  13322. case FunctionComponent:
  13323. case ForwardRef:
  13324. case SimpleMemoComponent:
  13325. case Block: {
  13326. // TODO (#17945) We should call all passive destroy functions (for all fibers)
  13327. // before calling any create functions. The current approach only serializes
  13328. // these for a single fiber.
  13329. {
  13330. commitHookEffectListUnmount(Passive$1 | HasEffect, finishedWork);
  13331. commitHookEffectListMount(Passive$1 | HasEffect, finishedWork);
  13332. }
  13333. break;
  13334. }
  13335. }
  13336. }
  13337. }
  13338. function commitLifeCycles(
  13339. finishedRoot,
  13340. current,
  13341. finishedWork,
  13342. committedExpirationTime
  13343. ) {
  13344. switch (finishedWork.tag) {
  13345. case FunctionComponent:
  13346. case ForwardRef:
  13347. case SimpleMemoComponent:
  13348. case Block: {
  13349. // At this point layout effects have already been destroyed (during mutation phase).
  13350. // This is done to prevent sibling component effects from interfering with each other,
  13351. // e.g. a destroy function in one component should never override a ref set
  13352. // by a create function in another component during the same commit.
  13353. {
  13354. commitHookEffectListMount(Layout | HasEffect, finishedWork);
  13355. }
  13356. return;
  13357. }
  13358. case ClassComponent: {
  13359. var instance = finishedWork.stateNode;
  13360. if (finishedWork.effectTag & Update) {
  13361. if (current === null) {
  13362. startPhaseTimer(finishedWork, "componentDidMount"); // We could update instance props and state here,
  13363. // but instead we rely on them being set during last render.
  13364. // TODO: revisit this when we implement resuming.
  13365. {
  13366. if (
  13367. finishedWork.type === finishedWork.elementType &&
  13368. !didWarnAboutReassigningProps
  13369. ) {
  13370. if (instance.props !== finishedWork.memoizedProps) {
  13371. error(
  13372. "Expected %s props to match memoized props before " +
  13373. "componentDidMount. " +
  13374. "This might either be because of a bug in React, or because " +
  13375. "a component reassigns its own `this.props`. " +
  13376. "Please file an issue.",
  13377. getComponentName(finishedWork.type) || "instance"
  13378. );
  13379. }
  13380. if (instance.state !== finishedWork.memoizedState) {
  13381. error(
  13382. "Expected %s state to match memoized state before " +
  13383. "componentDidMount. " +
  13384. "This might either be because of a bug in React, or because " +
  13385. "a component reassigns its own `this.state`. " +
  13386. "Please file an issue.",
  13387. getComponentName(finishedWork.type) || "instance"
  13388. );
  13389. }
  13390. }
  13391. }
  13392. {
  13393. instance.componentDidMount();
  13394. }
  13395. stopPhaseTimer();
  13396. } else {
  13397. var prevProps =
  13398. finishedWork.elementType === finishedWork.type
  13399. ? current.memoizedProps
  13400. : resolveDefaultProps(finishedWork.type, current.memoizedProps);
  13401. var prevState = current.memoizedState;
  13402. startPhaseTimer(finishedWork, "componentDidUpdate"); // We could update instance props and state here,
  13403. // but instead we rely on them being set during last render.
  13404. // TODO: revisit this when we implement resuming.
  13405. {
  13406. if (
  13407. finishedWork.type === finishedWork.elementType &&
  13408. !didWarnAboutReassigningProps
  13409. ) {
  13410. if (instance.props !== finishedWork.memoizedProps) {
  13411. error(
  13412. "Expected %s props to match memoized props before " +
  13413. "componentDidUpdate. " +
  13414. "This might either be because of a bug in React, or because " +
  13415. "a component reassigns its own `this.props`. " +
  13416. "Please file an issue.",
  13417. getComponentName(finishedWork.type) || "instance"
  13418. );
  13419. }
  13420. if (instance.state !== finishedWork.memoizedState) {
  13421. error(
  13422. "Expected %s state to match memoized state before " +
  13423. "componentDidUpdate. " +
  13424. "This might either be because of a bug in React, or because " +
  13425. "a component reassigns its own `this.state`. " +
  13426. "Please file an issue.",
  13427. getComponentName(finishedWork.type) || "instance"
  13428. );
  13429. }
  13430. }
  13431. }
  13432. {
  13433. instance.componentDidUpdate(
  13434. prevProps,
  13435. prevState,
  13436. instance.__reactInternalSnapshotBeforeUpdate
  13437. );
  13438. }
  13439. stopPhaseTimer();
  13440. }
  13441. }
  13442. var updateQueue = finishedWork.updateQueue;
  13443. if (updateQueue !== null) {
  13444. {
  13445. if (
  13446. finishedWork.type === finishedWork.elementType &&
  13447. !didWarnAboutReassigningProps
  13448. ) {
  13449. if (instance.props !== finishedWork.memoizedProps) {
  13450. error(
  13451. "Expected %s props to match memoized props before " +
  13452. "processing the update queue. " +
  13453. "This might either be because of a bug in React, or because " +
  13454. "a component reassigns its own `this.props`. " +
  13455. "Please file an issue.",
  13456. getComponentName(finishedWork.type) || "instance"
  13457. );
  13458. }
  13459. if (instance.state !== finishedWork.memoizedState) {
  13460. error(
  13461. "Expected %s state to match memoized state before " +
  13462. "processing the update queue. " +
  13463. "This might either be because of a bug in React, or because " +
  13464. "a component reassigns its own `this.state`. " +
  13465. "Please file an issue.",
  13466. getComponentName(finishedWork.type) || "instance"
  13467. );
  13468. }
  13469. }
  13470. } // We could update instance props and state here,
  13471. // but instead we rely on them being set during last render.
  13472. // TODO: revisit this when we implement resuming.
  13473. commitUpdateQueue(finishedWork, updateQueue, instance);
  13474. }
  13475. return;
  13476. }
  13477. case HostRoot: {
  13478. var _updateQueue = finishedWork.updateQueue;
  13479. if (_updateQueue !== null) {
  13480. var _instance = null;
  13481. if (finishedWork.child !== null) {
  13482. switch (finishedWork.child.tag) {
  13483. case HostComponent:
  13484. _instance = getPublicInstance(finishedWork.child.stateNode);
  13485. break;
  13486. case ClassComponent:
  13487. _instance = finishedWork.child.stateNode;
  13488. break;
  13489. }
  13490. }
  13491. commitUpdateQueue(finishedWork, _updateQueue, _instance);
  13492. }
  13493. return;
  13494. }
  13495. case HostComponent: {
  13496. var _instance2 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted
  13497. // (eg DOM renderer may schedule auto-focus for inputs and form controls).
  13498. // These effects should only be committed when components are first mounted,
  13499. // aka when there is no current/alternate.
  13500. if (current === null && finishedWork.effectTag & Update) {
  13501. var type = finishedWork.type;
  13502. var props = finishedWork.memoizedProps;
  13503. commitMount();
  13504. }
  13505. return;
  13506. }
  13507. case HostText: {
  13508. // We have no life-cycles associated with text.
  13509. return;
  13510. }
  13511. case HostPortal: {
  13512. // We have no life-cycles associated with portals.
  13513. return;
  13514. }
  13515. case Profiler: {
  13516. {
  13517. var _finishedWork$memoize2 = finishedWork.memoizedProps,
  13518. onCommit = _finishedWork$memoize2.onCommit,
  13519. onRender = _finishedWork$memoize2.onRender;
  13520. var effectDuration = finishedWork.stateNode.effectDuration;
  13521. var commitTime = getCommitTime();
  13522. if (typeof onRender === "function") {
  13523. {
  13524. onRender(
  13525. finishedWork.memoizedProps.id,
  13526. current === null ? "mount" : "update",
  13527. finishedWork.actualDuration,
  13528. finishedWork.treeBaseDuration,
  13529. finishedWork.actualStartTime,
  13530. commitTime,
  13531. finishedRoot.memoizedInteractions
  13532. );
  13533. }
  13534. }
  13535. }
  13536. return;
  13537. }
  13538. case SuspenseComponent: {
  13539. return;
  13540. }
  13541. case SuspenseListComponent:
  13542. case IncompleteClassComponent:
  13543. case FundamentalComponent:
  13544. case ScopeComponent:
  13545. return;
  13546. }
  13547. {
  13548. throw Error(
  13549. "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."
  13550. );
  13551. }
  13552. }
  13553. function commitAttachRef(finishedWork) {
  13554. var ref = finishedWork.ref;
  13555. if (ref !== null) {
  13556. var instance = finishedWork.stateNode;
  13557. var instanceToUse;
  13558. switch (finishedWork.tag) {
  13559. case HostComponent:
  13560. instanceToUse = getPublicInstance(instance);
  13561. break;
  13562. default:
  13563. instanceToUse = instance;
  13564. } // Moved outside to ensure DCE works with this flag
  13565. if (typeof ref === "function") {
  13566. ref(instanceToUse);
  13567. } else {
  13568. {
  13569. if (!ref.hasOwnProperty("current")) {
  13570. error(
  13571. "Unexpected ref object provided for %s. " +
  13572. "Use either a ref-setter function or React.createRef().%s",
  13573. getComponentName(finishedWork.type),
  13574. getStackByFiberInDevAndProd(finishedWork)
  13575. );
  13576. }
  13577. }
  13578. ref.current = instanceToUse;
  13579. }
  13580. }
  13581. }
  13582. function commitDetachRef(current) {
  13583. var currentRef = current.ref;
  13584. if (currentRef !== null) {
  13585. if (typeof currentRef === "function") {
  13586. currentRef(null);
  13587. } else {
  13588. currentRef.current = null;
  13589. }
  13590. }
  13591. } // User-originating errors (lifecycles and refs) should not interrupt
  13592. // deletion, so don't let them throw. Host-originating errors should
  13593. // interrupt deletion, so it's okay
  13594. function commitUnmount(finishedRoot, current, renderPriorityLevel) {
  13595. onCommitUnmount(current);
  13596. switch (current.tag) {
  13597. case FunctionComponent:
  13598. case ForwardRef:
  13599. case MemoComponent:
  13600. case SimpleMemoComponent:
  13601. case Block: {
  13602. var updateQueue = current.updateQueue;
  13603. if (updateQueue !== null) {
  13604. var lastEffect = updateQueue.lastEffect;
  13605. if (lastEffect !== null) {
  13606. var firstEffect = lastEffect.next;
  13607. {
  13608. // When the owner fiber is deleted, the destroy function of a passive
  13609. // effect hook is called during the synchronous commit phase. This is
  13610. // a concession to implementation complexity. Calling it in the
  13611. // passive effect phase (like they usually are, when dependencies
  13612. // change during an update) would require either traversing the
  13613. // children of the deleted fiber again, or including unmount effects
  13614. // as part of the fiber effect list.
  13615. //
  13616. // Because this is during the sync commit phase, we need to change
  13617. // the priority.
  13618. //
  13619. // TODO: Reconsider this implementation trade off.
  13620. var priorityLevel =
  13621. renderPriorityLevel > NormalPriority
  13622. ? NormalPriority
  13623. : renderPriorityLevel;
  13624. runWithPriority(priorityLevel, function() {
  13625. var effect = firstEffect;
  13626. do {
  13627. var _effect3 = effect,
  13628. _destroy = _effect3.destroy,
  13629. _tag = _effect3.tag;
  13630. if (_destroy !== undefined) {
  13631. {
  13632. safelyCallDestroy(current, _destroy);
  13633. }
  13634. }
  13635. effect = effect.next;
  13636. } while (effect !== firstEffect);
  13637. });
  13638. }
  13639. }
  13640. }
  13641. return;
  13642. }
  13643. case ClassComponent: {
  13644. safelyDetachRef(current);
  13645. var instance = current.stateNode;
  13646. if (typeof instance.componentWillUnmount === "function") {
  13647. safelyCallComponentWillUnmount(current, instance);
  13648. }
  13649. return;
  13650. }
  13651. case HostComponent: {
  13652. safelyDetachRef(current);
  13653. return;
  13654. }
  13655. case HostPortal: {
  13656. // TODO: this is recursive.
  13657. // We are also not using this parent because
  13658. // the portal will get pushed immediately.
  13659. {
  13660. emptyPortalContainer(current);
  13661. }
  13662. return;
  13663. }
  13664. case FundamentalComponent: {
  13665. return;
  13666. }
  13667. case DehydratedFragment: {
  13668. return;
  13669. }
  13670. case ScopeComponent: {
  13671. return;
  13672. }
  13673. }
  13674. }
  13675. function commitNestedUnmounts(finishedRoot, root, renderPriorityLevel) {
  13676. // While we're inside a removed host node we don't want to call
  13677. // removeChild on the inner nodes because they're removed by the top
  13678. // call anyway. We also want to call componentWillUnmount on all
  13679. // composites before this host node is removed from the tree. Therefore
  13680. // we do an inner loop while we're still inside the host node.
  13681. var node = root;
  13682. while (true) {
  13683. commitUnmount(finishedRoot, node, renderPriorityLevel); // Visit children because they may contain more composite or host nodes.
  13684. // Skip portals because commitUnmount() currently visits them recursively.
  13685. if (
  13686. node.child !== null && // If we use mutation we drill down into portals using commitUnmount above.
  13687. // If we don't use mutation we drill down into portals here instead.
  13688. !supportsMutation
  13689. ) {
  13690. node.child.return = node;
  13691. node = node.child;
  13692. continue;
  13693. }
  13694. if (node === root) {
  13695. return;
  13696. }
  13697. while (node.sibling === null) {
  13698. if (node.return === null || node.return === root) {
  13699. return;
  13700. }
  13701. node = node.return;
  13702. }
  13703. node.sibling.return = node.return;
  13704. node = node.sibling;
  13705. }
  13706. }
  13707. function detachFiber(current) {
  13708. var alternate = current.alternate; // Cut off the return pointers to disconnect it from the tree. Ideally, we
  13709. // should clear the child pointer of the parent alternate to let this
  13710. // get GC:ed but we don't know which for sure which parent is the current
  13711. // one so we'll settle for GC:ing the subtree of this child. This child
  13712. // itself will be GC:ed when the parent updates the next time.
  13713. current.return = null;
  13714. current.child = null;
  13715. current.memoizedState = null;
  13716. current.updateQueue = null;
  13717. current.dependencies = null;
  13718. current.alternate = null;
  13719. current.firstEffect = null;
  13720. current.lastEffect = null;
  13721. current.pendingProps = null;
  13722. current.memoizedProps = null;
  13723. current.stateNode = null;
  13724. if (alternate !== null) {
  13725. detachFiber(alternate);
  13726. }
  13727. }
  13728. function emptyPortalContainer(current) {
  13729. var portal = current.stateNode;
  13730. var containerInfo = portal.containerInfo;
  13731. var emptyChildSet = createContainerChildSet(containerInfo);
  13732. }
  13733. function commitContainer(finishedWork) {
  13734. switch (finishedWork.tag) {
  13735. case ClassComponent:
  13736. case HostComponent:
  13737. case HostText:
  13738. case FundamentalComponent: {
  13739. return;
  13740. }
  13741. case HostRoot:
  13742. case HostPortal: {
  13743. var portalOrRoot = finishedWork.stateNode;
  13744. var containerInfo = portalOrRoot.containerInfo,
  13745. pendingChildren = portalOrRoot.pendingChildren;
  13746. return;
  13747. }
  13748. }
  13749. {
  13750. throw Error(
  13751. "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue."
  13752. );
  13753. }
  13754. }
  13755. function commitDeletion(finishedRoot, current, renderPriorityLevel) {
  13756. {
  13757. // Detach refs and call componentWillUnmount() on the whole subtree.
  13758. commitNestedUnmounts(finishedRoot, current, renderPriorityLevel);
  13759. }
  13760. detachFiber(current);
  13761. }
  13762. function commitWork(current, finishedWork) {
  13763. {
  13764. switch (finishedWork.tag) {
  13765. case FunctionComponent:
  13766. case ForwardRef:
  13767. case MemoComponent:
  13768. case SimpleMemoComponent:
  13769. case Block: {
  13770. // Layout effects are destroyed during the mutation phase so that all
  13771. // destroy functions for all fibers are called before any create functions.
  13772. // This prevents sibling component effects from interfering with each other,
  13773. // e.g. a destroy function in one component should never override a ref set
  13774. // by a create function in another component during the same commit.
  13775. {
  13776. commitHookEffectListUnmount(Layout | HasEffect, finishedWork);
  13777. }
  13778. return;
  13779. }
  13780. case Profiler: {
  13781. return;
  13782. }
  13783. case SuspenseComponent: {
  13784. commitSuspenseComponent(finishedWork);
  13785. attachSuspenseRetryListeners(finishedWork);
  13786. return;
  13787. }
  13788. case SuspenseListComponent: {
  13789. attachSuspenseRetryListeners(finishedWork);
  13790. return;
  13791. }
  13792. }
  13793. commitContainer(finishedWork);
  13794. return;
  13795. }
  13796. }
  13797. function commitSuspenseComponent(finishedWork) {
  13798. var newState = finishedWork.memoizedState;
  13799. var primaryChildParent = finishedWork;
  13800. if (newState === null);
  13801. else {
  13802. primaryChildParent = finishedWork.child;
  13803. markCommitTimeOfFallback();
  13804. }
  13805. }
  13806. function attachSuspenseRetryListeners(finishedWork) {
  13807. // If this boundary just timed out, then it will have a set of thenables.
  13808. // For each thenable, attach a listener so that when it resolves, React
  13809. // attempts to re-render the boundary in the primary (pre-timeout) state.
  13810. var thenables = finishedWork.updateQueue;
  13811. if (thenables !== null) {
  13812. finishedWork.updateQueue = null;
  13813. var retryCache = finishedWork.stateNode;
  13814. if (retryCache === null) {
  13815. retryCache = finishedWork.stateNode = new PossiblyWeakSet();
  13816. }
  13817. thenables.forEach(function(thenable) {
  13818. // Memoize using the boundary fiber to prevent redundant listeners.
  13819. var retry = resolveRetryThenable.bind(null, finishedWork, thenable);
  13820. if (!retryCache.has(thenable)) {
  13821. {
  13822. if (thenable.__reactDoNotTraceInteractions !== true) {
  13823. retry = tracing.unstable_wrap(retry);
  13824. }
  13825. }
  13826. retryCache.add(thenable);
  13827. thenable.then(retry, retry);
  13828. }
  13829. });
  13830. }
  13831. }
  13832. var PossiblyWeakMap = typeof WeakMap === "function" ? WeakMap : Map;
  13833. function createRootErrorUpdate(fiber, errorInfo, expirationTime) {
  13834. var update = createUpdate(expirationTime, null); // Unmount the root by rendering null.
  13835. update.tag = CaptureUpdate; // Caution: React DevTools currently depends on this property
  13836. // being called "element".
  13837. update.payload = {
  13838. element: null
  13839. };
  13840. var error = errorInfo.value;
  13841. update.callback = function() {
  13842. onUncaughtError(error);
  13843. logError(fiber, errorInfo);
  13844. };
  13845. return update;
  13846. }
  13847. function createClassErrorUpdate(fiber, errorInfo, expirationTime) {
  13848. var update = createUpdate(expirationTime, null);
  13849. update.tag = CaptureUpdate;
  13850. var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
  13851. if (typeof getDerivedStateFromError === "function") {
  13852. var error$1 = errorInfo.value;
  13853. update.payload = function() {
  13854. logError(fiber, errorInfo);
  13855. return getDerivedStateFromError(error$1);
  13856. };
  13857. }
  13858. var inst = fiber.stateNode;
  13859. if (inst !== null && typeof inst.componentDidCatch === "function") {
  13860. update.callback = function callback() {
  13861. {
  13862. markFailedErrorBoundaryForHotReloading(fiber);
  13863. }
  13864. if (typeof getDerivedStateFromError !== "function") {
  13865. // To preserve the preexisting retry behavior of error boundaries,
  13866. // we keep track of which ones already failed during this batch.
  13867. // This gets reset before we yield back to the browser.
  13868. // TODO: Warn in strict mode if getDerivedStateFromError is
  13869. // not defined.
  13870. markLegacyErrorBoundaryAsFailed(this); // Only log here if componentDidCatch is the only error boundary method defined
  13871. logError(fiber, errorInfo);
  13872. }
  13873. var error$1 = errorInfo.value;
  13874. var stack = errorInfo.stack;
  13875. this.componentDidCatch(error$1, {
  13876. componentStack: stack !== null ? stack : ""
  13877. });
  13878. {
  13879. if (typeof getDerivedStateFromError !== "function") {
  13880. // If componentDidCatch is the only error boundary method defined,
  13881. // then it needs to call setState to recover from errors.
  13882. // If no state update is scheduled then the boundary will swallow the error.
  13883. if (fiber.expirationTime !== Sync) {
  13884. error(
  13885. "%s: Error boundaries should implement getDerivedStateFromError(). " +
  13886. "In that method, return a state update to display an error message or fallback UI.",
  13887. getComponentName(fiber.type) || "Unknown"
  13888. );
  13889. }
  13890. }
  13891. }
  13892. };
  13893. } else {
  13894. update.callback = function() {
  13895. markFailedErrorBoundaryForHotReloading(fiber);
  13896. };
  13897. }
  13898. return update;
  13899. }
  13900. function attachPingListener(root, renderExpirationTime, thenable) {
  13901. // Attach a listener to the promise to "ping" the root and retry. But
  13902. // only if one does not already exist for the current render expiration
  13903. // time (which acts like a "thread ID" here).
  13904. var pingCache = root.pingCache;
  13905. var threadIDs;
  13906. if (pingCache === null) {
  13907. pingCache = root.pingCache = new PossiblyWeakMap();
  13908. threadIDs = new Set();
  13909. pingCache.set(thenable, threadIDs);
  13910. } else {
  13911. threadIDs = pingCache.get(thenable);
  13912. if (threadIDs === undefined) {
  13913. threadIDs = new Set();
  13914. pingCache.set(thenable, threadIDs);
  13915. }
  13916. }
  13917. if (!threadIDs.has(renderExpirationTime)) {
  13918. // Memoize using the thread ID to prevent redundant listeners.
  13919. threadIDs.add(renderExpirationTime);
  13920. var ping = pingSuspendedRoot.bind(
  13921. null,
  13922. root,
  13923. thenable,
  13924. renderExpirationTime
  13925. );
  13926. thenable.then(ping, ping);
  13927. }
  13928. }
  13929. function throwException(
  13930. root,
  13931. returnFiber,
  13932. sourceFiber,
  13933. value,
  13934. renderExpirationTime
  13935. ) {
  13936. // The source fiber did not complete.
  13937. sourceFiber.effectTag |= Incomplete; // Its effect list is no longer valid.
  13938. sourceFiber.firstEffect = sourceFiber.lastEffect = null;
  13939. if (
  13940. value !== null &&
  13941. typeof value === "object" &&
  13942. typeof value.then === "function"
  13943. ) {
  13944. // This is a thenable.
  13945. var thenable = value;
  13946. if ((sourceFiber.mode & BlockingMode) === NoMode) {
  13947. // Reset the memoizedState to what it was before we attempted
  13948. // to render it.
  13949. var currentSource = sourceFiber.alternate;
  13950. if (currentSource) {
  13951. sourceFiber.updateQueue = currentSource.updateQueue;
  13952. sourceFiber.memoizedState = currentSource.memoizedState;
  13953. sourceFiber.expirationTime = currentSource.expirationTime;
  13954. } else {
  13955. sourceFiber.updateQueue = null;
  13956. sourceFiber.memoizedState = null;
  13957. }
  13958. }
  13959. var hasInvisibleParentBoundary = hasSuspenseContext(
  13960. suspenseStackCursor.current,
  13961. InvisibleParentSuspenseContext
  13962. ); // Schedule the nearest Suspense to re-render the timed out view.
  13963. var _workInProgress = returnFiber;
  13964. do {
  13965. if (
  13966. _workInProgress.tag === SuspenseComponent &&
  13967. shouldCaptureSuspense(_workInProgress, hasInvisibleParentBoundary)
  13968. ) {
  13969. // Found the nearest boundary.
  13970. // Stash the promise on the boundary fiber. If the boundary times out, we'll
  13971. // attach another listener to flip the boundary back to its normal state.
  13972. var thenables = _workInProgress.updateQueue;
  13973. if (thenables === null) {
  13974. var updateQueue = new Set();
  13975. updateQueue.add(thenable);
  13976. _workInProgress.updateQueue = updateQueue;
  13977. } else {
  13978. thenables.add(thenable);
  13979. } // If the boundary is outside of blocking mode, we should *not*
  13980. // suspend the commit. Pretend as if the suspended component rendered
  13981. // null and keep rendering. In the commit phase, we'll schedule a
  13982. // subsequent synchronous update to re-render the Suspense.
  13983. //
  13984. // Note: It doesn't matter whether the component that suspended was
  13985. // inside a blocking mode tree. If the Suspense is outside of it, we
  13986. // should *not* suspend the commit.
  13987. if ((_workInProgress.mode & BlockingMode) === NoMode) {
  13988. _workInProgress.effectTag |= DidCapture; // We're going to commit this fiber even though it didn't complete.
  13989. // But we shouldn't call any lifecycle methods or callbacks. Remove
  13990. // all lifecycle effect tags.
  13991. sourceFiber.effectTag &= ~(LifecycleEffectMask | Incomplete);
  13992. if (sourceFiber.tag === ClassComponent) {
  13993. var currentSourceFiber = sourceFiber.alternate;
  13994. if (currentSourceFiber === null) {
  13995. // This is a new mount. Change the tag so it's not mistaken for a
  13996. // completed class component. For example, we should not call
  13997. // componentWillUnmount if it is deleted.
  13998. sourceFiber.tag = IncompleteClassComponent;
  13999. } else {
  14000. // When we try rendering again, we should not reuse the current fiber,
  14001. // since it's known to be in an inconsistent state. Use a force update to
  14002. // prevent a bail out.
  14003. var update = createUpdate(Sync, null);
  14004. update.tag = ForceUpdate;
  14005. enqueueUpdate(sourceFiber, update);
  14006. }
  14007. } // The source fiber did not complete. Mark it with Sync priority to
  14008. // indicate that it still has pending work.
  14009. sourceFiber.expirationTime = Sync; // Exit without suspending.
  14010. return;
  14011. } // Confirmed that the boundary is in a concurrent mode tree. Continue
  14012. // with the normal suspend path.
  14013. //
  14014. // After this we'll use a set of heuristics to determine whether this
  14015. // render pass will run to completion or restart or "suspend" the commit.
  14016. // The actual logic for this is spread out in different places.
  14017. //
  14018. // This first principle is that if we're going to suspend when we complete
  14019. // a root, then we should also restart if we get an update or ping that
  14020. // might unsuspend it, and vice versa. The only reason to suspend is
  14021. // because you think you might want to restart before committing. However,
  14022. // it doesn't make sense to restart only while in the period we're suspended.
  14023. //
  14024. // Restarting too aggressively is also not good because it starves out any
  14025. // intermediate loading state. So we use heuristics to determine when.
  14026. // Suspense Heuristics
  14027. //
  14028. // If nothing threw a Promise or all the same fallbacks are already showing,
  14029. // then don't suspend/restart.
  14030. //
  14031. // If this is an initial render of a new tree of Suspense boundaries and
  14032. // those trigger a fallback, then don't suspend/restart. We want to ensure
  14033. // that we can show the initial loading state as quickly as possible.
  14034. //
  14035. // If we hit a "Delayed" case, such as when we'd switch from content back into
  14036. // a fallback, then we should always suspend/restart. SuspenseConfig applies to
  14037. // this case. If none is defined, JND is used instead.
  14038. //
  14039. // If we're already showing a fallback and it gets "retried", allowing us to show
  14040. // another level, but there's still an inner boundary that would show a fallback,
  14041. // then we suspend/restart for 500ms since the last time we showed a fallback
  14042. // anywhere in the tree. This effectively throttles progressive loading into a
  14043. // consistent train of commits. This also gives us an opportunity to restart to
  14044. // get to the completed state slightly earlier.
  14045. //
  14046. // If there's ambiguity due to batching it's resolved in preference of:
  14047. // 1) "delayed", 2) "initial render", 3) "retry".
  14048. //
  14049. // We want to ensure that a "busy" state doesn't get force committed. We want to
  14050. // ensure that new initial loading states can commit as soon as possible.
  14051. attachPingListener(root, renderExpirationTime, thenable);
  14052. _workInProgress.effectTag |= ShouldCapture;
  14053. _workInProgress.expirationTime = renderExpirationTime;
  14054. return;
  14055. } // This boundary already captured during this render. Continue to the next
  14056. // boundary.
  14057. _workInProgress = _workInProgress.return;
  14058. } while (_workInProgress !== null); // No boundary was found. Fallthrough to error mode.
  14059. // TODO: Use invariant so the message is stripped in prod?
  14060. value = new Error(
  14061. (getComponentName(sourceFiber.type) || "A React component") +
  14062. " suspended while rendering, but no fallback UI was specified.\n" +
  14063. "\n" +
  14064. "Add a <Suspense fallback=...> component higher in the tree to " +
  14065. "provide a loading indicator or placeholder to display." +
  14066. getStackByFiberInDevAndProd(sourceFiber)
  14067. );
  14068. } // We didn't find a boundary that could handle this type of exception. Start
  14069. // over and traverse parent path again, this time treating the exception
  14070. // as an error.
  14071. renderDidError();
  14072. value = createCapturedValue(value, sourceFiber);
  14073. var workInProgress = returnFiber;
  14074. do {
  14075. switch (workInProgress.tag) {
  14076. case HostRoot: {
  14077. var _errorInfo = value;
  14078. workInProgress.effectTag |= ShouldCapture;
  14079. workInProgress.expirationTime = renderExpirationTime;
  14080. var _update = createRootErrorUpdate(
  14081. workInProgress,
  14082. _errorInfo,
  14083. renderExpirationTime
  14084. );
  14085. enqueueCapturedUpdate(workInProgress, _update);
  14086. return;
  14087. }
  14088. case ClassComponent:
  14089. // Capture and retry
  14090. var errorInfo = value;
  14091. var ctor = workInProgress.type;
  14092. var instance = workInProgress.stateNode;
  14093. if (
  14094. (workInProgress.effectTag & DidCapture) === NoEffect &&
  14095. (typeof ctor.getDerivedStateFromError === "function" ||
  14096. (instance !== null &&
  14097. typeof instance.componentDidCatch === "function" &&
  14098. !isAlreadyFailedLegacyErrorBoundary(instance)))
  14099. ) {
  14100. workInProgress.effectTag |= ShouldCapture;
  14101. workInProgress.expirationTime = renderExpirationTime; // Schedule the error boundary to re-render using updated state
  14102. var _update2 = createClassErrorUpdate(
  14103. workInProgress,
  14104. errorInfo,
  14105. renderExpirationTime
  14106. );
  14107. enqueueCapturedUpdate(workInProgress, _update2);
  14108. return;
  14109. }
  14110. break;
  14111. }
  14112. workInProgress = workInProgress.return;
  14113. } while (workInProgress !== null);
  14114. }
  14115. var ceil = Math.ceil;
  14116. var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher,
  14117. ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner,
  14118. IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing;
  14119. var NoContext =
  14120. /* */
  14121. 0;
  14122. var BatchedContext =
  14123. /* */
  14124. 1;
  14125. var DiscreteEventContext =
  14126. /* */
  14127. 4;
  14128. var LegacyUnbatchedContext =
  14129. /* */
  14130. 8;
  14131. var RenderContext =
  14132. /* */
  14133. 16;
  14134. var CommitContext =
  14135. /* */
  14136. 32;
  14137. var RootIncomplete = 0;
  14138. var RootFatalErrored = 1;
  14139. var RootErrored = 2;
  14140. var RootSuspended = 3;
  14141. var RootSuspendedWithDelay = 4;
  14142. var RootCompleted = 5;
  14143. // Describes where we are in the React execution stack
  14144. var executionContext = NoContext; // The root we're working on
  14145. var workInProgressRoot = null; // The fiber we're working on
  14146. var workInProgress = null; // The expiration time we're rendering
  14147. var renderExpirationTime$1 = NoWork; // Whether to root completed, errored, suspended, etc.
  14148. var workInProgressRootExitStatus = RootIncomplete; // A fatal error, if one is thrown
  14149. var workInProgressRootFatalError = null; // Most recent event time among processed updates during this render.
  14150. // This is conceptually a time stamp but expressed in terms of an ExpirationTime
  14151. // because we deal mostly with expiration times in the hot path, so this avoids
  14152. // the conversion happening in the hot path.
  14153. var workInProgressRootLatestProcessedExpirationTime = Sync;
  14154. var workInProgressRootLatestSuspenseTimeout = Sync;
  14155. var workInProgressRootCanSuspendUsingConfig = null; // The work left over by components that were visited during this render. Only
  14156. // includes unprocessed updates, not work in bailed out children.
  14157. var workInProgressRootNextUnprocessedUpdateTime = NoWork; // If we're pinged while rendering we don't always restart immediately.
  14158. // This flag determines if it might be worthwhile to restart if an opportunity
  14159. // happens latere.
  14160. var workInProgressRootHasPendingPing = false; // The most recent time we committed a fallback. This lets us ensure a train
  14161. // model where we don't commit new loading states in too quick succession.
  14162. var globalMostRecentFallbackTime = 0;
  14163. var FALLBACK_THROTTLE_MS = 500;
  14164. var nextEffect = null;
  14165. var hasUncaughtError = false;
  14166. var firstUncaughtError = null;
  14167. var legacyErrorBoundariesThatAlreadyFailed = null;
  14168. var rootDoesHavePassiveEffects = false;
  14169. var rootWithPendingPassiveEffects = null;
  14170. var pendingPassiveEffectsRenderPriority = NoPriority;
  14171. var pendingPassiveEffectsExpirationTime = NoWork;
  14172. var rootsWithPendingDiscreteUpdates = null; // Use these to prevent an infinite loop of nested updates
  14173. var NESTED_UPDATE_LIMIT = 50;
  14174. var nestedUpdateCount = 0;
  14175. var rootWithNestedUpdates = null;
  14176. var NESTED_PASSIVE_UPDATE_LIMIT = 50;
  14177. var nestedPassiveUpdateCount = 0;
  14178. var interruptedBy = null; // Marks the need to reschedule pending interactions at these expiration times
  14179. // during the commit phase. This enables them to be traced across components
  14180. // that spawn new work during render. E.g. hidden boundaries, suspended SSR
  14181. // hydration or SuspenseList.
  14182. var spawnedWorkDuringRender = null; // Expiration times are computed by adding to the current time (the start
  14183. // time). However, if two updates are scheduled within the same event, we
  14184. // should treat their start times as simultaneous, even if the actual clock
  14185. // time has advanced between the first and second call.
  14186. // In other words, because expiration times determine how updates are batched,
  14187. // we want all updates of like priority that occur within the same event to
  14188. // receive the same expiration time. Otherwise we get tearing.
  14189. var currentEventTime = NoWork;
  14190. function requestCurrentTimeForUpdate() {
  14191. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  14192. // We're inside React, so it's fine to read the actual time.
  14193. return msToExpirationTime(now());
  14194. } // We're not inside React, so we may be in the middle of a browser event.
  14195. if (currentEventTime !== NoWork) {
  14196. // Use the same start time for all updates until we enter React again.
  14197. return currentEventTime;
  14198. } // This is the first update since React yielded. Compute a new start time.
  14199. currentEventTime = msToExpirationTime(now());
  14200. return currentEventTime;
  14201. }
  14202. function getCurrentTime() {
  14203. return msToExpirationTime(now());
  14204. }
  14205. function computeExpirationForFiber(currentTime, fiber, suspenseConfig) {
  14206. var mode = fiber.mode;
  14207. if ((mode & BlockingMode) === NoMode) {
  14208. return Sync;
  14209. }
  14210. var priorityLevel = getCurrentPriorityLevel();
  14211. if ((mode & ConcurrentMode) === NoMode) {
  14212. return priorityLevel === ImmediatePriority ? Sync : Batched;
  14213. }
  14214. if ((executionContext & RenderContext) !== NoContext) {
  14215. // Use whatever time we're already rendering
  14216. // TODO: Should there be a way to opt out, like with `runWithPriority`?
  14217. return renderExpirationTime$1;
  14218. }
  14219. var expirationTime;
  14220. if (suspenseConfig !== null) {
  14221. // Compute an expiration time based on the Suspense timeout.
  14222. expirationTime = computeSuspenseExpiration(
  14223. currentTime,
  14224. suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION
  14225. );
  14226. } else {
  14227. // Compute an expiration time based on the Scheduler priority.
  14228. switch (priorityLevel) {
  14229. case ImmediatePriority:
  14230. expirationTime = Sync;
  14231. break;
  14232. case UserBlockingPriority:
  14233. // TODO: Rename this to computeUserBlockingExpiration
  14234. expirationTime = computeInteractiveExpiration(currentTime);
  14235. break;
  14236. case NormalPriority:
  14237. case LowPriority:
  14238. // TODO: Handle LowPriority
  14239. // TODO: Rename this to... something better.
  14240. expirationTime = computeAsyncExpiration(currentTime);
  14241. break;
  14242. case IdlePriority:
  14243. expirationTime = Idle;
  14244. break;
  14245. default: {
  14246. throw Error("Expected a valid priority level");
  14247. }
  14248. }
  14249. } // If we're in the middle of rendering a tree, do not update at the same
  14250. // expiration time that is already rendering.
  14251. // TODO: We shouldn't have to do this if the update is on a different root.
  14252. // Refactor computeExpirationForFiber + scheduleUpdate so we have access to
  14253. // the root when we check for this condition.
  14254. if (
  14255. workInProgressRoot !== null &&
  14256. expirationTime === renderExpirationTime$1
  14257. ) {
  14258. // This is a trick to move this update into a separate batch
  14259. expirationTime -= 1;
  14260. }
  14261. return expirationTime;
  14262. }
  14263. function scheduleUpdateOnFiber(fiber, expirationTime) {
  14264. checkForNestedUpdates();
  14265. warnAboutRenderPhaseUpdatesInDEV(fiber);
  14266. var root = markUpdateTimeFromFiberToRoot(fiber, expirationTime);
  14267. if (root === null) {
  14268. warnAboutUpdateOnUnmountedFiberInDEV(fiber);
  14269. return;
  14270. }
  14271. checkForInterruption(fiber, expirationTime);
  14272. recordScheduleUpdate(); // TODO: computeExpirationForFiber also reads the priority. Pass the
  14273. // priority as an argument to that function and this one.
  14274. var priorityLevel = getCurrentPriorityLevel();
  14275. if (expirationTime === Sync) {
  14276. if (
  14277. // Check if we're inside unbatchedUpdates
  14278. (executionContext & LegacyUnbatchedContext) !== NoContext && // Check if we're not already rendering
  14279. (executionContext & (RenderContext | CommitContext)) === NoContext
  14280. ) {
  14281. // Register pending interactions on the root to avoid losing traced interaction data.
  14282. schedulePendingInteractions(root, expirationTime); // This is a legacy edge case. The initial mount of a ReactDOM.render-ed
  14283. // root inside of batchedUpdates should be synchronous, but layout updates
  14284. // should be deferred until the end of the batch.
  14285. performSyncWorkOnRoot(root);
  14286. } else {
  14287. ensureRootIsScheduled(root);
  14288. schedulePendingInteractions(root, expirationTime);
  14289. if (executionContext === NoContext) {
  14290. // Flush the synchronous work now, unless we're already working or inside
  14291. // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
  14292. // scheduleCallbackForFiber to preserve the ability to schedule a callback
  14293. // without immediately flushing it. We only do this for user-initiated
  14294. // updates, to preserve historical behavior of legacy mode.
  14295. flushSyncCallbackQueue();
  14296. }
  14297. }
  14298. } else {
  14299. ensureRootIsScheduled(root);
  14300. schedulePendingInteractions(root, expirationTime);
  14301. }
  14302. if (
  14303. (executionContext & DiscreteEventContext) !== NoContext && // Only updates at user-blocking priority or greater are considered
  14304. // discrete, even inside a discrete event.
  14305. (priorityLevel === UserBlockingPriority ||
  14306. priorityLevel === ImmediatePriority)
  14307. ) {
  14308. // This is the result of a discrete event. Track the lowest priority
  14309. // discrete update per root so we can flush them early, if needed.
  14310. if (rootsWithPendingDiscreteUpdates === null) {
  14311. rootsWithPendingDiscreteUpdates = new Map([[root, expirationTime]]);
  14312. } else {
  14313. var lastDiscreteTime = rootsWithPendingDiscreteUpdates.get(root);
  14314. if (lastDiscreteTime === undefined || lastDiscreteTime > expirationTime) {
  14315. rootsWithPendingDiscreteUpdates.set(root, expirationTime);
  14316. }
  14317. }
  14318. }
  14319. }
  14320. var scheduleWork = scheduleUpdateOnFiber; // This is split into a separate function so we can mark a fiber with pending
  14321. // work without treating it as a typical update that originates from an event;
  14322. // e.g. retrying a Suspense boundary isn't an update, but it does schedule work
  14323. // on a fiber.
  14324. function markUpdateTimeFromFiberToRoot(fiber, expirationTime) {
  14325. // Update the source fiber's expiration time
  14326. if (fiber.expirationTime < expirationTime) {
  14327. fiber.expirationTime = expirationTime;
  14328. }
  14329. var alternate = fiber.alternate;
  14330. if (alternate !== null && alternate.expirationTime < expirationTime) {
  14331. alternate.expirationTime = expirationTime;
  14332. } // Walk the parent path to the root and update the child expiration time.
  14333. var node = fiber.return;
  14334. var root = null;
  14335. if (node === null && fiber.tag === HostRoot) {
  14336. root = fiber.stateNode;
  14337. } else {
  14338. while (node !== null) {
  14339. alternate = node.alternate;
  14340. if (node.childExpirationTime < expirationTime) {
  14341. node.childExpirationTime = expirationTime;
  14342. if (
  14343. alternate !== null &&
  14344. alternate.childExpirationTime < expirationTime
  14345. ) {
  14346. alternate.childExpirationTime = expirationTime;
  14347. }
  14348. } else if (
  14349. alternate !== null &&
  14350. alternate.childExpirationTime < expirationTime
  14351. ) {
  14352. alternate.childExpirationTime = expirationTime;
  14353. }
  14354. if (node.return === null && node.tag === HostRoot) {
  14355. root = node.stateNode;
  14356. break;
  14357. }
  14358. node = node.return;
  14359. }
  14360. }
  14361. if (root !== null) {
  14362. if (workInProgressRoot === root) {
  14363. // Received an update to a tree that's in the middle of rendering. Mark
  14364. // that's unprocessed work on this root.
  14365. markUnprocessedUpdateTime(expirationTime);
  14366. if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
  14367. // The root already suspended with a delay, which means this render
  14368. // definitely won't finish. Since we have a new update, let's mark it as
  14369. // suspended now, right before marking the incoming update. This has the
  14370. // effect of interrupting the current render and switching to the update.
  14371. // TODO: This happens to work when receiving an update during the render
  14372. // phase, because of the trick inside computeExpirationForFiber to
  14373. // subtract 1 from `renderExpirationTime` to move it into a
  14374. // separate bucket. But we should probably model it with an exception,
  14375. // using the same mechanism we use to force hydration of a subtree.
  14376. // TODO: This does not account for low pri updates that were already
  14377. // scheduled before the root started rendering. Need to track the next
  14378. // pending expiration time (perhaps by backtracking the return path) and
  14379. // then trigger a restart in the `renderDidSuspendDelayIfPossible` path.
  14380. markRootSuspendedAtTime(root, renderExpirationTime$1);
  14381. }
  14382. } // Mark that the root has a pending update.
  14383. markRootUpdatedAtTime(root, expirationTime);
  14384. }
  14385. return root;
  14386. }
  14387. function getNextRootExpirationTimeToWorkOn(root) {
  14388. // Determines the next expiration time that the root should render, taking
  14389. // into account levels that may be suspended, or levels that may have
  14390. // received a ping.
  14391. var lastExpiredTime = root.lastExpiredTime;
  14392. if (lastExpiredTime !== NoWork) {
  14393. return lastExpiredTime;
  14394. } // "Pending" refers to any update that hasn't committed yet, including if it
  14395. // suspended. The "suspended" range is therefore a subset.
  14396. var firstPendingTime = root.firstPendingTime;
  14397. if (!isRootSuspendedAtTime(root, firstPendingTime)) {
  14398. // The highest priority pending time is not suspended. Let's work on that.
  14399. return firstPendingTime;
  14400. } // If the first pending time is suspended, check if there's a lower priority
  14401. // pending level that we know about. Or check if we received a ping. Work
  14402. // on whichever is higher priority.
  14403. var lastPingedTime = root.lastPingedTime;
  14404. var nextKnownPendingLevel = root.nextKnownPendingLevel;
  14405. var nextLevel =
  14406. lastPingedTime > nextKnownPendingLevel
  14407. ? lastPingedTime
  14408. : nextKnownPendingLevel;
  14409. if (nextLevel <= Idle && firstPendingTime !== nextLevel) {
  14410. // Don't work on Idle/Never priority unless everything else is committed.
  14411. return NoWork;
  14412. }
  14413. return nextLevel;
  14414. } // Use this function to schedule a task for a root. There's only one task per
  14415. // root; if a task was already scheduled, we'll check to make sure the
  14416. // expiration time of the existing task is the same as the expiration time of
  14417. // the next level that the root has work on. This function is called on every
  14418. // update, and right before exiting a task.
  14419. function ensureRootIsScheduled(root) {
  14420. var lastExpiredTime = root.lastExpiredTime;
  14421. if (lastExpiredTime !== NoWork) {
  14422. // Special case: Expired work should flush synchronously.
  14423. root.callbackExpirationTime = Sync;
  14424. root.callbackPriority = ImmediatePriority;
  14425. root.callbackNode = scheduleSyncCallback(
  14426. performSyncWorkOnRoot.bind(null, root)
  14427. );
  14428. return;
  14429. }
  14430. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  14431. var existingCallbackNode = root.callbackNode;
  14432. if (expirationTime === NoWork) {
  14433. // There's nothing to work on.
  14434. if (existingCallbackNode !== null) {
  14435. root.callbackNode = null;
  14436. root.callbackExpirationTime = NoWork;
  14437. root.callbackPriority = NoPriority;
  14438. }
  14439. return;
  14440. } // TODO: If this is an update, we already read the current time. Pass the
  14441. // time as an argument.
  14442. var currentTime = requestCurrentTimeForUpdate();
  14443. var priorityLevel = inferPriorityFromExpirationTime(
  14444. currentTime,
  14445. expirationTime
  14446. ); // If there's an existing render task, confirm it has the correct priority and
  14447. // expiration time. Otherwise, we'll cancel it and schedule a new one.
  14448. if (existingCallbackNode !== null) {
  14449. var existingCallbackPriority = root.callbackPriority;
  14450. var existingCallbackExpirationTime = root.callbackExpirationTime;
  14451. if (
  14452. // Callback must have the exact same expiration time.
  14453. existingCallbackExpirationTime === expirationTime && // Callback must have greater or equal priority.
  14454. existingCallbackPriority >= priorityLevel
  14455. ) {
  14456. // Existing callback is sufficient.
  14457. return;
  14458. } // Need to schedule a new task.
  14459. // TODO: Instead of scheduling a new task, we should be able to change the
  14460. // priority of the existing one.
  14461. cancelCallback(existingCallbackNode);
  14462. }
  14463. root.callbackExpirationTime = expirationTime;
  14464. root.callbackPriority = priorityLevel;
  14465. var callbackNode;
  14466. if (expirationTime === Sync) {
  14467. // Sync React callbacks are scheduled on a special internal queue
  14468. callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
  14469. } else {
  14470. callbackNode = scheduleCallback(
  14471. priorityLevel,
  14472. performConcurrentWorkOnRoot.bind(null, root), // Compute a task timeout based on the expiration time. This also affects
  14473. // ordering because tasks are processed in timeout order.
  14474. {
  14475. timeout: expirationTimeToMs(expirationTime) - now()
  14476. }
  14477. );
  14478. }
  14479. root.callbackNode = callbackNode;
  14480. } // This is the entry point for every concurrent task, i.e. anything that
  14481. // goes through Scheduler.
  14482. function performConcurrentWorkOnRoot(root, didTimeout) {
  14483. // Since we know we're in a React event, we can clear the current
  14484. // event time. The next update will compute a new event time.
  14485. currentEventTime = NoWork; // Check if the render expired.
  14486. if (didTimeout) {
  14487. // The render task took too long to complete. Mark the current time as
  14488. // expired to synchronously render all expired work in a single batch.
  14489. var currentTime = requestCurrentTimeForUpdate();
  14490. markRootExpiredAtTime(root, currentTime); // This will schedule a synchronous callback.
  14491. ensureRootIsScheduled(root);
  14492. return null;
  14493. } // Determine the next expiration time to work on, using the fields stored
  14494. // on the root.
  14495. var expirationTime = getNextRootExpirationTimeToWorkOn(root);
  14496. if (expirationTime === NoWork) {
  14497. return null;
  14498. }
  14499. var originalCallbackNode = root.callbackNode;
  14500. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  14501. throw Error("Should not already be working.");
  14502. }
  14503. flushPassiveEffects();
  14504. var exitStatus = renderRootConcurrent(root, expirationTime);
  14505. if (exitStatus !== RootIncomplete) {
  14506. if (exitStatus === RootErrored) {
  14507. // If something threw an error, try rendering one more time. We'll
  14508. // render synchronously to block concurrent data mutations, and we'll
  14509. // render at Idle (or lower) so that all pending updates are included.
  14510. // If it still fails after the second attempt, we'll give up and commit
  14511. // the resulting tree.
  14512. expirationTime = expirationTime > Idle ? Idle : expirationTime;
  14513. exitStatus = renderRootSync(root, expirationTime);
  14514. }
  14515. if (exitStatus === RootFatalErrored) {
  14516. var fatalError = workInProgressRootFatalError;
  14517. prepareFreshStack(root, expirationTime);
  14518. markRootSuspendedAtTime(root, expirationTime);
  14519. ensureRootIsScheduled(root);
  14520. throw fatalError;
  14521. } // We now have a consistent tree. The next step is either to commit it,
  14522. // or, if something suspended, wait to commit it after a timeout.
  14523. var finishedWork = (root.finishedWork = root.current.alternate);
  14524. root.finishedExpirationTime = expirationTime;
  14525. finishConcurrentRender(root, finishedWork, exitStatus, expirationTime);
  14526. }
  14527. ensureRootIsScheduled(root);
  14528. if (root.callbackNode === originalCallbackNode) {
  14529. // The task node scheduled for this root is the same one that's
  14530. // currently executed. Need to return a continuation.
  14531. return performConcurrentWorkOnRoot.bind(null, root);
  14532. }
  14533. return null;
  14534. }
  14535. function finishConcurrentRender(
  14536. root,
  14537. finishedWork,
  14538. exitStatus,
  14539. expirationTime
  14540. ) {
  14541. switch (exitStatus) {
  14542. case RootIncomplete:
  14543. case RootFatalErrored: {
  14544. {
  14545. throw Error("Root did not complete. This is a bug in React.");
  14546. }
  14547. }
  14548. // Flow knows about invariant, so it complains if I add a break
  14549. // statement, but eslint doesn't know about invariant, so it complains
  14550. // if I do. eslint-disable-next-line no-fallthrough
  14551. case RootErrored: {
  14552. // We should have already attempted to retry this tree. If we reached
  14553. // this point, it errored again. Commit it.
  14554. commitRoot(root);
  14555. break;
  14556. }
  14557. case RootSuspended: {
  14558. markRootSuspendedAtTime(root, expirationTime);
  14559. var lastSuspendedTime = root.lastSuspendedTime;
  14560. if (expirationTime === lastSuspendedTime) {
  14561. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  14562. } // We have an acceptable loading state. We need to figure out if we
  14563. // should immediately commit it or wait a bit.
  14564. // If we have processed new updates during this render, we may now
  14565. // have a new loading state ready. We want to ensure that we commit
  14566. // that as soon as possible.
  14567. var hasNotProcessedNewUpdates =
  14568. workInProgressRootLatestProcessedExpirationTime === Sync;
  14569. if (
  14570. hasNotProcessedNewUpdates && // do not delay if we're inside an act() scope
  14571. !IsThisRendererActing.current
  14572. ) {
  14573. // If we have not processed any new updates during this pass, then
  14574. // this is either a retry of an existing fallback state or a
  14575. // hidden tree. Hidden trees shouldn't be batched with other work
  14576. // and after that's fixed it can only be a retry. We're going to
  14577. // throttle committing retries so that we don't show too many
  14578. // loading states too quickly.
  14579. var msUntilTimeout =
  14580. globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now(); // Don't bother with a very short suspense time.
  14581. if (msUntilTimeout > 10) {
  14582. if (workInProgressRootHasPendingPing) {
  14583. var lastPingedTime = root.lastPingedTime;
  14584. if (lastPingedTime === NoWork || lastPingedTime >= expirationTime) {
  14585. // This render was pinged but we didn't get to restart
  14586. // earlier so try restarting now instead.
  14587. root.lastPingedTime = expirationTime;
  14588. prepareFreshStack(root, expirationTime);
  14589. break;
  14590. }
  14591. }
  14592. var nextTime = getNextRootExpirationTimeToWorkOn(root);
  14593. if (nextTime !== NoWork && nextTime !== expirationTime) {
  14594. // There's additional work on this root.
  14595. break;
  14596. }
  14597. if (
  14598. lastSuspendedTime !== NoWork &&
  14599. lastSuspendedTime !== expirationTime
  14600. ) {
  14601. // We should prefer to render the fallback of at the last
  14602. // suspended level. Ping the last suspended level to try
  14603. // rendering it again.
  14604. root.lastPingedTime = lastSuspendedTime;
  14605. break;
  14606. } // The render is suspended, it hasn't timed out, and there's no
  14607. // lower priority work to do. Instead of committing the fallback
  14608. // immediately, wait for more data to arrive.
  14609. root.timeoutHandle = scheduleTimeout(
  14610. commitRoot.bind(null, root),
  14611. msUntilTimeout
  14612. );
  14613. break;
  14614. }
  14615. } // The work expired. Commit immediately.
  14616. commitRoot(root);
  14617. break;
  14618. }
  14619. case RootSuspendedWithDelay: {
  14620. markRootSuspendedAtTime(root, expirationTime);
  14621. var _lastSuspendedTime = root.lastSuspendedTime;
  14622. if (expirationTime === _lastSuspendedTime) {
  14623. root.nextKnownPendingLevel = getRemainingExpirationTime(finishedWork);
  14624. }
  14625. {
  14626. // We're suspended in a state that should be avoided. We'll try to
  14627. // avoid committing it for as long as the timeouts let us.
  14628. if (workInProgressRootHasPendingPing) {
  14629. var _lastPingedTime = root.lastPingedTime;
  14630. if (_lastPingedTime === NoWork || _lastPingedTime >= expirationTime) {
  14631. // This render was pinged but we didn't get to restart earlier
  14632. // so try restarting now instead.
  14633. root.lastPingedTime = expirationTime;
  14634. prepareFreshStack(root, expirationTime);
  14635. break;
  14636. }
  14637. }
  14638. var _nextTime = getNextRootExpirationTimeToWorkOn(root);
  14639. if (_nextTime !== NoWork && _nextTime !== expirationTime) {
  14640. // There's additional work on this root.
  14641. break;
  14642. }
  14643. if (
  14644. _lastSuspendedTime !== NoWork &&
  14645. _lastSuspendedTime !== expirationTime
  14646. ) {
  14647. // We should prefer to render the fallback of at the last
  14648. // suspended level. Ping the last suspended level to try
  14649. // rendering it again.
  14650. root.lastPingedTime = _lastSuspendedTime;
  14651. break;
  14652. }
  14653. var _msUntilTimeout;
  14654. if (workInProgressRootLatestSuspenseTimeout !== Sync) {
  14655. // We have processed a suspense config whose expiration time we
  14656. // can use as the timeout.
  14657. _msUntilTimeout =
  14658. expirationTimeToMs(workInProgressRootLatestSuspenseTimeout) - now();
  14659. } else if (workInProgressRootLatestProcessedExpirationTime === Sync) {
  14660. // This should never normally happen because only new updates
  14661. // cause delayed states, so we should have processed something.
  14662. // However, this could also happen in an offscreen tree.
  14663. _msUntilTimeout = 0;
  14664. } else {
  14665. // If we don't have a suspense config, we're going to use a
  14666. // heuristic to determine how long we can suspend.
  14667. var eventTimeMs = inferTimeFromExpirationTime(
  14668. workInProgressRootLatestProcessedExpirationTime
  14669. );
  14670. var currentTimeMs = now();
  14671. var timeUntilExpirationMs =
  14672. expirationTimeToMs(expirationTime) - currentTimeMs;
  14673. var timeElapsed = currentTimeMs - eventTimeMs;
  14674. if (timeElapsed < 0) {
  14675. // We get this wrong some time since we estimate the time.
  14676. timeElapsed = 0;
  14677. }
  14678. _msUntilTimeout = jnd(timeElapsed) - timeElapsed; // Clamp the timeout to the expiration time. TODO: Once the
  14679. // event time is exact instead of inferred from expiration time
  14680. // we don't need this.
  14681. if (timeUntilExpirationMs < _msUntilTimeout) {
  14682. _msUntilTimeout = timeUntilExpirationMs;
  14683. }
  14684. } // Don't bother with a very short suspense time.
  14685. if (_msUntilTimeout > 10) {
  14686. // The render is suspended, it hasn't timed out, and there's no
  14687. // lower priority work to do. Instead of committing the fallback
  14688. // immediately, wait for more data to arrive.
  14689. root.timeoutHandle = scheduleTimeout(
  14690. commitRoot.bind(null, root),
  14691. _msUntilTimeout
  14692. );
  14693. break;
  14694. }
  14695. } // The work expired. Commit immediately.
  14696. commitRoot(root);
  14697. break;
  14698. }
  14699. case RootCompleted: {
  14700. // The work completed. Ready to commit.
  14701. if (
  14702. // do not delay if we're inside an act() scope
  14703. workInProgressRootLatestProcessedExpirationTime !== Sync &&
  14704. workInProgressRootCanSuspendUsingConfig !== null
  14705. ) {
  14706. // If we have exceeded the minimum loading delay, which probably
  14707. // means we have shown a spinner already, we might have to suspend
  14708. // a bit longer to ensure that the spinner is shown for
  14709. // enough time.
  14710. var _msUntilTimeout2 = computeMsUntilSuspenseLoadingDelay(
  14711. workInProgressRootLatestProcessedExpirationTime,
  14712. expirationTime,
  14713. workInProgressRootCanSuspendUsingConfig
  14714. );
  14715. if (_msUntilTimeout2 > 10) {
  14716. markRootSuspendedAtTime(root, expirationTime);
  14717. root.timeoutHandle = scheduleTimeout(
  14718. commitRoot.bind(null, root),
  14719. _msUntilTimeout2
  14720. );
  14721. break;
  14722. }
  14723. }
  14724. commitRoot(root);
  14725. break;
  14726. }
  14727. default: {
  14728. {
  14729. throw Error("Unknown root exit status.");
  14730. }
  14731. }
  14732. }
  14733. } // This is the entry point for synchronous tasks that don't go
  14734. // through Scheduler
  14735. function performSyncWorkOnRoot(root) {
  14736. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  14737. throw Error("Should not already be working.");
  14738. }
  14739. flushPassiveEffects();
  14740. var lastExpiredTime = root.lastExpiredTime;
  14741. var expirationTime;
  14742. if (lastExpiredTime !== NoWork) {
  14743. // There's expired work on this root. Check if we have a partial tree
  14744. // that we can reuse.
  14745. if (
  14746. root === workInProgressRoot &&
  14747. renderExpirationTime$1 >= lastExpiredTime
  14748. ) {
  14749. // There's a partial tree with equal or greater than priority than the
  14750. // expired level. Finish rendering it before rendering the rest of the
  14751. // expired work.
  14752. expirationTime = renderExpirationTime$1;
  14753. } else {
  14754. // Start a fresh tree.
  14755. expirationTime = lastExpiredTime;
  14756. }
  14757. } else {
  14758. // There's no expired work. This must be a new, synchronous render.
  14759. expirationTime = Sync;
  14760. }
  14761. var exitStatus = renderRootSync(root, expirationTime);
  14762. if (root.tag !== LegacyRoot && exitStatus === RootErrored) {
  14763. // If something threw an error, try rendering one more time. We'll
  14764. // render synchronously to block concurrent data mutations, and we'll
  14765. // render at Idle (or lower) so that all pending updates are included.
  14766. // If it still fails after the second attempt, we'll give up and commit
  14767. // the resulting tree.
  14768. expirationTime = expirationTime > Idle ? Idle : expirationTime;
  14769. exitStatus = renderRootSync(root, expirationTime);
  14770. }
  14771. if (exitStatus === RootFatalErrored) {
  14772. var fatalError = workInProgressRootFatalError;
  14773. prepareFreshStack(root, expirationTime);
  14774. markRootSuspendedAtTime(root, expirationTime);
  14775. ensureRootIsScheduled(root);
  14776. throw fatalError;
  14777. } // We now have a consistent tree. Because this is a sync render, we
  14778. // will commit it even if something suspended.
  14779. root.finishedWork = root.current.alternate;
  14780. root.finishedExpirationTime = expirationTime;
  14781. commitRoot(root); // Before exiting, make sure there's a callback scheduled for the next
  14782. // pending level.
  14783. ensureRootIsScheduled(root);
  14784. return null;
  14785. }
  14786. function syncUpdates(fn, a, b, c) {
  14787. return runWithPriority(ImmediatePriority, fn.bind(null, a, b, c));
  14788. }
  14789. function batchedUpdates$1(fn, a) {
  14790. var prevExecutionContext = executionContext;
  14791. executionContext |= BatchedContext;
  14792. try {
  14793. return fn(a);
  14794. } finally {
  14795. executionContext = prevExecutionContext;
  14796. if (executionContext === NoContext) {
  14797. // Flush the immediate callbacks that were scheduled during this batch
  14798. flushSyncCallbackQueue();
  14799. }
  14800. }
  14801. }
  14802. function flushSync(fn, a) {
  14803. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  14804. {
  14805. throw Error(
  14806. "flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering."
  14807. );
  14808. }
  14809. }
  14810. var prevExecutionContext = executionContext;
  14811. executionContext |= BatchedContext;
  14812. try {
  14813. return runWithPriority(ImmediatePriority, fn.bind(null, a));
  14814. } finally {
  14815. executionContext = prevExecutionContext; // Flush the immediate callbacks that were scheduled during this batch.
  14816. // Note that this will happen even if batchedUpdates is higher up
  14817. // the stack.
  14818. flushSyncCallbackQueue();
  14819. }
  14820. }
  14821. function prepareFreshStack(root, expirationTime) {
  14822. root.finishedWork = null;
  14823. root.finishedExpirationTime = NoWork;
  14824. var timeoutHandle = root.timeoutHandle;
  14825. if (timeoutHandle !== noTimeout) {
  14826. // The root previous suspended and scheduled a timeout to commit a fallback
  14827. // state. Now that we have additional work, cancel the timeout.
  14828. root.timeoutHandle = noTimeout; // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
  14829. cancelTimeout(timeoutHandle);
  14830. }
  14831. if (workInProgress !== null) {
  14832. var interruptedWork = workInProgress.return;
  14833. while (interruptedWork !== null) {
  14834. unwindInterruptedWork(interruptedWork);
  14835. interruptedWork = interruptedWork.return;
  14836. }
  14837. }
  14838. workInProgressRoot = root;
  14839. workInProgress = createWorkInProgress(root.current, null);
  14840. renderExpirationTime$1 = expirationTime;
  14841. workInProgressRootExitStatus = RootIncomplete;
  14842. workInProgressRootFatalError = null;
  14843. workInProgressRootLatestProcessedExpirationTime = Sync;
  14844. workInProgressRootLatestSuspenseTimeout = Sync;
  14845. workInProgressRootCanSuspendUsingConfig = null;
  14846. workInProgressRootNextUnprocessedUpdateTime = NoWork;
  14847. workInProgressRootHasPendingPing = false;
  14848. {
  14849. spawnedWorkDuringRender = null;
  14850. }
  14851. {
  14852. ReactStrictModeWarnings.discardPendingWarnings();
  14853. }
  14854. }
  14855. function handleError(root, thrownValue) {
  14856. do {
  14857. try {
  14858. // Reset module-level state that was set during the render phase.
  14859. resetContextDependencies();
  14860. resetHooksAfterThrow();
  14861. resetCurrentFiber();
  14862. if (workInProgress === null || workInProgress.return === null) {
  14863. // Expected to be working on a non-root fiber. This is a fatal error
  14864. // because there's no ancestor that can handle it; the root is
  14865. // supposed to capture all errors that weren't caught by an error
  14866. // boundary.
  14867. workInProgressRootExitStatus = RootFatalErrored;
  14868. workInProgressRootFatalError = thrownValue; // Set `workInProgress` to null. This represents advancing to the next
  14869. // sibling, or the parent if there are no siblings. But since the root
  14870. // has no siblings nor a parent, we set it to null. Usually this is
  14871. // handled by `completeUnitOfWork` or `unwindWork`, but since we're
  14872. // interntionally not calling those, we need set it here.
  14873. // TODO: Consider calling `unwindWork` to pop the contexts.
  14874. workInProgress = null;
  14875. return null;
  14876. }
  14877. if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
  14878. // Record the time spent rendering before an error was thrown. This
  14879. // avoids inaccurate Profiler durations in the case of a
  14880. // suspended render.
  14881. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
  14882. }
  14883. throwException(
  14884. root,
  14885. workInProgress.return,
  14886. workInProgress,
  14887. thrownValue,
  14888. renderExpirationTime$1
  14889. );
  14890. workInProgress = completeUnitOfWork(workInProgress);
  14891. } catch (yetAnotherThrownValue) {
  14892. // Something in the return path also threw.
  14893. thrownValue = yetAnotherThrownValue;
  14894. continue;
  14895. } // Return to the normal work loop.
  14896. return;
  14897. } while (true);
  14898. }
  14899. function pushDispatcher(root) {
  14900. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14901. ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
  14902. if (prevDispatcher === null) {
  14903. // The React isomorphic package does not include a default dispatcher.
  14904. // Instead the first renderer will lazily attach one, in order to give
  14905. // nicer error messages.
  14906. return ContextOnlyDispatcher;
  14907. } else {
  14908. return prevDispatcher;
  14909. }
  14910. }
  14911. function popDispatcher(prevDispatcher) {
  14912. ReactCurrentDispatcher$1.current = prevDispatcher;
  14913. }
  14914. function pushInteractions(root) {
  14915. {
  14916. var prevInteractions = tracing.__interactionsRef.current;
  14917. tracing.__interactionsRef.current = root.memoizedInteractions;
  14918. return prevInteractions;
  14919. }
  14920. }
  14921. function popInteractions(prevInteractions) {
  14922. {
  14923. tracing.__interactionsRef.current = prevInteractions;
  14924. }
  14925. }
  14926. function markCommitTimeOfFallback() {
  14927. globalMostRecentFallbackTime = now();
  14928. }
  14929. function markRenderEventTimeAndConfig(expirationTime, suspenseConfig) {
  14930. if (
  14931. expirationTime < workInProgressRootLatestProcessedExpirationTime &&
  14932. expirationTime > Idle
  14933. ) {
  14934. workInProgressRootLatestProcessedExpirationTime = expirationTime;
  14935. }
  14936. if (suspenseConfig !== null) {
  14937. if (
  14938. expirationTime < workInProgressRootLatestSuspenseTimeout &&
  14939. expirationTime > Idle
  14940. ) {
  14941. workInProgressRootLatestSuspenseTimeout = expirationTime; // Most of the time we only have one config and getting wrong is not bad.
  14942. workInProgressRootCanSuspendUsingConfig = suspenseConfig;
  14943. }
  14944. }
  14945. }
  14946. function markUnprocessedUpdateTime(expirationTime) {
  14947. if (expirationTime > workInProgressRootNextUnprocessedUpdateTime) {
  14948. workInProgressRootNextUnprocessedUpdateTime = expirationTime;
  14949. }
  14950. }
  14951. function renderDidSuspend() {
  14952. if (workInProgressRootExitStatus === RootIncomplete) {
  14953. workInProgressRootExitStatus = RootSuspended;
  14954. }
  14955. }
  14956. function renderDidSuspendDelayIfPossible() {
  14957. if (
  14958. workInProgressRootExitStatus === RootIncomplete ||
  14959. workInProgressRootExitStatus === RootSuspended
  14960. ) {
  14961. workInProgressRootExitStatus = RootSuspendedWithDelay;
  14962. } // Check if there's a lower priority update somewhere else in the tree.
  14963. if (
  14964. workInProgressRootNextUnprocessedUpdateTime !== NoWork &&
  14965. workInProgressRoot !== null
  14966. ) {
  14967. // Mark the current render as suspended, and then mark that there's a
  14968. // pending update.
  14969. // TODO: This should immediately interrupt the current render, instead
  14970. // of waiting until the next time we yield.
  14971. markRootSuspendedAtTime(workInProgressRoot, renderExpirationTime$1);
  14972. markRootUpdatedAtTime(
  14973. workInProgressRoot,
  14974. workInProgressRootNextUnprocessedUpdateTime
  14975. );
  14976. }
  14977. }
  14978. function renderDidError() {
  14979. if (workInProgressRootExitStatus !== RootCompleted) {
  14980. workInProgressRootExitStatus = RootErrored;
  14981. }
  14982. } // Called during render to determine if anything has suspended.
  14983. // Returns false if we're not sure.
  14984. function renderHasNotSuspendedYet() {
  14985. // If something errored or completed, we can't really be sure,
  14986. // so those are false.
  14987. return workInProgressRootExitStatus === RootIncomplete;
  14988. }
  14989. function inferTimeFromExpirationTime(expirationTime) {
  14990. // We don't know exactly when the update was scheduled, but we can infer an
  14991. // approximate start time from the expiration time.
  14992. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  14993. return earliestExpirationTimeMs - LOW_PRIORITY_EXPIRATION;
  14994. }
  14995. function inferTimeFromExpirationTimeWithSuspenseConfig(
  14996. expirationTime,
  14997. suspenseConfig
  14998. ) {
  14999. // We don't know exactly when the update was scheduled, but we can infer an
  15000. // approximate start time from the expiration time by subtracting the timeout
  15001. // that was added to the event time.
  15002. var earliestExpirationTimeMs = expirationTimeToMs(expirationTime);
  15003. return (
  15004. earliestExpirationTimeMs -
  15005. (suspenseConfig.timeoutMs | 0 || LOW_PRIORITY_EXPIRATION)
  15006. );
  15007. }
  15008. function renderRootSync(root, expirationTime) {
  15009. var prevExecutionContext = executionContext;
  15010. executionContext |= RenderContext;
  15011. var prevDispatcher = pushDispatcher(); // If the root or expiration time have changed, throw out the existing stack
  15012. // and prepare a fresh one. Otherwise we'll continue where we left off.
  15013. if (
  15014. root !== workInProgressRoot ||
  15015. expirationTime !== renderExpirationTime$1
  15016. ) {
  15017. prepareFreshStack(root, expirationTime);
  15018. startWorkOnPendingInteractions(root, expirationTime);
  15019. }
  15020. var prevInteractions = pushInteractions(root);
  15021. startWorkLoopTimer(workInProgress);
  15022. do {
  15023. try {
  15024. workLoopSync();
  15025. break;
  15026. } catch (thrownValue) {
  15027. handleError(root, thrownValue);
  15028. }
  15029. } while (true);
  15030. resetContextDependencies();
  15031. {
  15032. popInteractions(prevInteractions);
  15033. }
  15034. executionContext = prevExecutionContext;
  15035. popDispatcher(prevDispatcher);
  15036. if (workInProgress !== null) {
  15037. // This is a sync render, so we should have finished the whole tree.
  15038. {
  15039. throw Error(
  15040. "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue."
  15041. );
  15042. }
  15043. }
  15044. stopFinishedWorkLoopTimer(); // Set this to null to indicate there's no in-progress render.
  15045. workInProgressRoot = null;
  15046. return workInProgressRootExitStatus;
  15047. } // The work loop is an extremely hot path. Tell Closure not to inline it.
  15048. /** @noinline */
  15049. function workLoopSync() {
  15050. // Already timed out, so perform work without checking if we need to yield.
  15051. while (workInProgress !== null) {
  15052. workInProgress = performUnitOfWork(workInProgress);
  15053. }
  15054. }
  15055. function renderRootConcurrent(root, expirationTime) {
  15056. var prevExecutionContext = executionContext;
  15057. executionContext |= RenderContext;
  15058. var prevDispatcher = pushDispatcher(); // If the root or expiration time have changed, throw out the existing stack
  15059. // and prepare a fresh one. Otherwise we'll continue where we left off.
  15060. if (
  15061. root !== workInProgressRoot ||
  15062. expirationTime !== renderExpirationTime$1
  15063. ) {
  15064. prepareFreshStack(root, expirationTime);
  15065. startWorkOnPendingInteractions(root, expirationTime);
  15066. }
  15067. var prevInteractions = pushInteractions(root);
  15068. startWorkLoopTimer(workInProgress);
  15069. do {
  15070. try {
  15071. workLoopConcurrent();
  15072. break;
  15073. } catch (thrownValue) {
  15074. handleError(root, thrownValue);
  15075. }
  15076. } while (true);
  15077. resetContextDependencies();
  15078. {
  15079. popInteractions(prevInteractions);
  15080. }
  15081. popDispatcher(prevDispatcher);
  15082. executionContext = prevExecutionContext; // Check if the tree has completed.
  15083. if (workInProgress !== null) {
  15084. // Still work remaining.
  15085. stopInterruptedWorkLoopTimer();
  15086. return RootIncomplete;
  15087. } else {
  15088. // Completed the tree.
  15089. stopFinishedWorkLoopTimer(); // Set this to null to indicate there's no in-progress render.
  15090. workInProgressRoot = null; // Return the final exit status.
  15091. return workInProgressRootExitStatus;
  15092. }
  15093. }
  15094. /** @noinline */
  15095. function workLoopConcurrent() {
  15096. // Perform work until Scheduler asks us to yield
  15097. while (workInProgress !== null && !shouldYield()) {
  15098. workInProgress = performUnitOfWork(workInProgress);
  15099. }
  15100. }
  15101. function performUnitOfWork(unitOfWork) {
  15102. // The current, flushed, state of this fiber is the alternate. Ideally
  15103. // nothing should rely on this, but relying on it here means that we don't
  15104. // need an additional field on the work in progress.
  15105. var current = unitOfWork.alternate;
  15106. startWorkTimer(unitOfWork);
  15107. setCurrentFiber(unitOfWork);
  15108. var next;
  15109. if ((unitOfWork.mode & ProfileMode) !== NoMode) {
  15110. startProfilerTimer(unitOfWork);
  15111. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  15112. stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, true);
  15113. } else {
  15114. next = beginWork$1(current, unitOfWork, renderExpirationTime$1);
  15115. }
  15116. resetCurrentFiber();
  15117. unitOfWork.memoizedProps = unitOfWork.pendingProps;
  15118. if (next === null) {
  15119. // If this doesn't spawn new work, complete the current work.
  15120. next = completeUnitOfWork(unitOfWork);
  15121. }
  15122. ReactCurrentOwner$2.current = null;
  15123. return next;
  15124. }
  15125. function completeUnitOfWork(unitOfWork) {
  15126. // Attempt to complete the current unit of work, then move to the next
  15127. // sibling. If there are no more siblings, return to the parent fiber.
  15128. workInProgress = unitOfWork;
  15129. do {
  15130. // The current, flushed, state of this fiber is the alternate. Ideally
  15131. // nothing should rely on this, but relying on it here means that we don't
  15132. // need an additional field on the work in progress.
  15133. var current = workInProgress.alternate;
  15134. var returnFiber = workInProgress.return; // Check if the work completed or if something threw.
  15135. if ((workInProgress.effectTag & Incomplete) === NoEffect) {
  15136. setCurrentFiber(workInProgress);
  15137. var next = void 0;
  15138. if ((workInProgress.mode & ProfileMode) === NoMode) {
  15139. next = completeWork(current, workInProgress, renderExpirationTime$1);
  15140. } else {
  15141. startProfilerTimer(workInProgress);
  15142. next = completeWork(current, workInProgress, renderExpirationTime$1); // Update render duration assuming we didn't error.
  15143. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false);
  15144. }
  15145. stopWorkTimer(workInProgress);
  15146. resetCurrentFiber();
  15147. resetChildExpirationTime(workInProgress);
  15148. if (next !== null) {
  15149. // Completing this fiber spawned new work. Work on that next.
  15150. return next;
  15151. }
  15152. if (
  15153. returnFiber !== null && // Do not append effects to parents if a sibling failed to complete
  15154. (returnFiber.effectTag & Incomplete) === NoEffect
  15155. ) {
  15156. // Append all the effects of the subtree and this fiber onto the effect
  15157. // list of the parent. The completion order of the children affects the
  15158. // side-effect order.
  15159. if (returnFiber.firstEffect === null) {
  15160. returnFiber.firstEffect = workInProgress.firstEffect;
  15161. }
  15162. if (workInProgress.lastEffect !== null) {
  15163. if (returnFiber.lastEffect !== null) {
  15164. returnFiber.lastEffect.nextEffect = workInProgress.firstEffect;
  15165. }
  15166. returnFiber.lastEffect = workInProgress.lastEffect;
  15167. } // If this fiber had side-effects, we append it AFTER the children's
  15168. // side-effects. We can perform certain side-effects earlier if needed,
  15169. // by doing multiple passes over the effect list. We don't want to
  15170. // schedule our own side-effect on our own list because if end up
  15171. // reusing children we'll schedule this effect onto itself since we're
  15172. // at the end.
  15173. var effectTag = workInProgress.effectTag; // Skip both NoWork and PerformedWork tags when creating the effect
  15174. // list. PerformedWork effect is read by React DevTools but shouldn't be
  15175. // committed.
  15176. if (effectTag > PerformedWork) {
  15177. if (returnFiber.lastEffect !== null) {
  15178. returnFiber.lastEffect.nextEffect = workInProgress;
  15179. } else {
  15180. returnFiber.firstEffect = workInProgress;
  15181. }
  15182. returnFiber.lastEffect = workInProgress;
  15183. }
  15184. }
  15185. } else {
  15186. // This fiber did not complete because something threw. Pop values off
  15187. // the stack without entering the complete phase. If this is a boundary,
  15188. // capture values if possible.
  15189. var _next = unwindWork(workInProgress); // Because this fiber did not complete, don't reset its expiration time.
  15190. if ((workInProgress.mode & ProfileMode) !== NoMode) {
  15191. // Record the render duration for the fiber that errored.
  15192. stopProfilerTimerIfRunningAndRecordDelta(workInProgress, false); // Include the time spent working on failed children before continuing.
  15193. var actualDuration = workInProgress.actualDuration;
  15194. var child = workInProgress.child;
  15195. while (child !== null) {
  15196. actualDuration += child.actualDuration;
  15197. child = child.sibling;
  15198. }
  15199. workInProgress.actualDuration = actualDuration;
  15200. }
  15201. if (_next !== null) {
  15202. // If completing this work spawned new work, do that next. We'll come
  15203. // back here again.
  15204. // Since we're restarting, remove anything that is not a host effect
  15205. // from the effect tag.
  15206. // TODO: The name stopFailedWorkTimer is misleading because Suspense
  15207. // also captures and restarts.
  15208. stopFailedWorkTimer(workInProgress);
  15209. _next.effectTag &= HostEffectMask;
  15210. return _next;
  15211. }
  15212. stopWorkTimer(workInProgress);
  15213. if (returnFiber !== null) {
  15214. // Mark the parent fiber as incomplete and clear its effect list.
  15215. returnFiber.firstEffect = returnFiber.lastEffect = null;
  15216. returnFiber.effectTag |= Incomplete;
  15217. }
  15218. }
  15219. var siblingFiber = workInProgress.sibling;
  15220. if (siblingFiber !== null) {
  15221. // If there is more work to do in this returnFiber, do that next.
  15222. return siblingFiber;
  15223. } // Otherwise, return to the parent
  15224. workInProgress = returnFiber;
  15225. } while (workInProgress !== null); // We've reached the root.
  15226. if (workInProgressRootExitStatus === RootIncomplete) {
  15227. workInProgressRootExitStatus = RootCompleted;
  15228. }
  15229. return null;
  15230. }
  15231. function getRemainingExpirationTime(fiber) {
  15232. var updateExpirationTime = fiber.expirationTime;
  15233. var childExpirationTime = fiber.childExpirationTime;
  15234. return updateExpirationTime > childExpirationTime
  15235. ? updateExpirationTime
  15236. : childExpirationTime;
  15237. }
  15238. function resetChildExpirationTime(completedWork) {
  15239. if (
  15240. renderExpirationTime$1 !== Never &&
  15241. completedWork.childExpirationTime === Never
  15242. ) {
  15243. // The children of this component are hidden. Don't bubble their
  15244. // expiration times.
  15245. return;
  15246. }
  15247. var newChildExpirationTime = NoWork; // Bubble up the earliest expiration time.
  15248. if ((completedWork.mode & ProfileMode) !== NoMode) {
  15249. // In profiling mode, resetChildExpirationTime is also used to reset
  15250. // profiler durations.
  15251. var actualDuration = completedWork.actualDuration;
  15252. var treeBaseDuration = completedWork.selfBaseDuration; // When a fiber is cloned, its actualDuration is reset to 0. This value will
  15253. // only be updated if work is done on the fiber (i.e. it doesn't bailout).
  15254. // When work is done, it should bubble to the parent's actualDuration. If
  15255. // the fiber has not been cloned though, (meaning no work was done), then
  15256. // this value will reflect the amount of time spent working on a previous
  15257. // render. In that case it should not bubble. We determine whether it was
  15258. // cloned by comparing the child pointer.
  15259. var shouldBubbleActualDurations =
  15260. completedWork.alternate === null ||
  15261. completedWork.child !== completedWork.alternate.child;
  15262. var child = completedWork.child;
  15263. while (child !== null) {
  15264. var childUpdateExpirationTime = child.expirationTime;
  15265. var childChildExpirationTime = child.childExpirationTime;
  15266. if (childUpdateExpirationTime > newChildExpirationTime) {
  15267. newChildExpirationTime = childUpdateExpirationTime;
  15268. }
  15269. if (childChildExpirationTime > newChildExpirationTime) {
  15270. newChildExpirationTime = childChildExpirationTime;
  15271. }
  15272. if (shouldBubbleActualDurations) {
  15273. actualDuration += child.actualDuration;
  15274. }
  15275. treeBaseDuration += child.treeBaseDuration;
  15276. child = child.sibling;
  15277. }
  15278. completedWork.actualDuration = actualDuration;
  15279. completedWork.treeBaseDuration = treeBaseDuration;
  15280. } else {
  15281. var _child = completedWork.child;
  15282. while (_child !== null) {
  15283. var _childUpdateExpirationTime = _child.expirationTime;
  15284. var _childChildExpirationTime = _child.childExpirationTime;
  15285. if (_childUpdateExpirationTime > newChildExpirationTime) {
  15286. newChildExpirationTime = _childUpdateExpirationTime;
  15287. }
  15288. if (_childChildExpirationTime > newChildExpirationTime) {
  15289. newChildExpirationTime = _childChildExpirationTime;
  15290. }
  15291. _child = _child.sibling;
  15292. }
  15293. }
  15294. completedWork.childExpirationTime = newChildExpirationTime;
  15295. }
  15296. function commitRoot(root) {
  15297. var renderPriorityLevel = getCurrentPriorityLevel();
  15298. runWithPriority(
  15299. ImmediatePriority,
  15300. commitRootImpl.bind(null, root, renderPriorityLevel)
  15301. );
  15302. return null;
  15303. }
  15304. function commitRootImpl(root, renderPriorityLevel) {
  15305. do {
  15306. // `flushPassiveEffects` will call `flushSyncUpdateQueue` at the end, which
  15307. // means `flushPassiveEffects` will sometimes result in additional
  15308. // passive effects. So we need to keep flushing in a loop until there are
  15309. // no more pending effects.
  15310. // TODO: Might be better if `flushPassiveEffects` did not automatically
  15311. // flush synchronous work at the end, to avoid factoring hazards like this.
  15312. flushPassiveEffects();
  15313. } while (rootWithPendingPassiveEffects !== null);
  15314. flushRenderPhaseStrictModeWarningsInDEV();
  15315. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  15316. throw Error("Should not already be working.");
  15317. }
  15318. var finishedWork = root.finishedWork;
  15319. var expirationTime = root.finishedExpirationTime;
  15320. if (finishedWork === null) {
  15321. return null;
  15322. }
  15323. root.finishedWork = null;
  15324. root.finishedExpirationTime = NoWork;
  15325. if (!(finishedWork !== root.current)) {
  15326. throw Error(
  15327. "Cannot commit the same tree as before. This error is likely caused by a bug in React. Please file an issue."
  15328. );
  15329. } // commitRoot never returns a continuation; it always finishes synchronously.
  15330. // So we can clear these now to allow a new callback to be scheduled.
  15331. root.callbackNode = null;
  15332. root.callbackExpirationTime = NoWork;
  15333. root.callbackPriority = NoPriority;
  15334. root.nextKnownPendingLevel = NoWork;
  15335. startCommitTimer(); // Update the first and last pending times on this root. The new first
  15336. // pending time is whatever is left on the root fiber.
  15337. var remainingExpirationTimeBeforeCommit = getRemainingExpirationTime(
  15338. finishedWork
  15339. );
  15340. markRootFinishedAtTime(
  15341. root,
  15342. expirationTime,
  15343. remainingExpirationTimeBeforeCommit
  15344. );
  15345. if (root === workInProgressRoot) {
  15346. // We can reset these now that they are finished.
  15347. workInProgressRoot = null;
  15348. workInProgress = null;
  15349. renderExpirationTime$1 = NoWork;
  15350. } // This indicates that the last root we worked on is not the same one that
  15351. // we're committing now. This most commonly happens when a suspended root
  15352. // times out.
  15353. // Get the list of effects.
  15354. var firstEffect;
  15355. if (finishedWork.effectTag > PerformedWork) {
  15356. // A fiber's effect list consists only of its children, not itself. So if
  15357. // the root has an effect, we need to add it to the end of the list. The
  15358. // resulting list is the set that would belong to the root's parent, if it
  15359. // had one; that is, all the effects in the tree including the root.
  15360. if (finishedWork.lastEffect !== null) {
  15361. finishedWork.lastEffect.nextEffect = finishedWork;
  15362. firstEffect = finishedWork.firstEffect;
  15363. } else {
  15364. firstEffect = finishedWork;
  15365. }
  15366. } else {
  15367. // There is no effect on the root.
  15368. firstEffect = finishedWork.firstEffect;
  15369. }
  15370. if (firstEffect !== null) {
  15371. var prevExecutionContext = executionContext;
  15372. executionContext |= CommitContext;
  15373. var prevInteractions = pushInteractions(root); // Reset this to null before calling lifecycles
  15374. ReactCurrentOwner$2.current = null; // The commit phase is broken into several sub-phases. We do a separate pass
  15375. // of the effect list for each phase: all mutation effects come before all
  15376. // layout effects, and so on.
  15377. // The first phase a "before mutation" phase. We use this phase to read the
  15378. // state of the host tree right before we mutate it. This is where
  15379. // getSnapshotBeforeUpdate is called.
  15380. startCommitSnapshotEffectsTimer();
  15381. prepareForCommit(root.containerInfo);
  15382. nextEffect = firstEffect;
  15383. do {
  15384. {
  15385. invokeGuardedCallback(null, commitBeforeMutationEffects, null);
  15386. if (hasCaughtError()) {
  15387. if (!(nextEffect !== null)) {
  15388. throw Error("Should be working on an effect.");
  15389. }
  15390. var error = clearCaughtError();
  15391. captureCommitPhaseError(nextEffect, error);
  15392. nextEffect = nextEffect.nextEffect;
  15393. }
  15394. }
  15395. } while (nextEffect !== null);
  15396. stopCommitSnapshotEffectsTimer();
  15397. {
  15398. // Mark the current commit time to be shared by all Profilers in this
  15399. // batch. This enables them to be grouped later.
  15400. recordCommitTime();
  15401. } // The next phase is the mutation phase, where we mutate the host tree.
  15402. startCommitHostEffectsTimer();
  15403. nextEffect = firstEffect;
  15404. do {
  15405. {
  15406. invokeGuardedCallback(
  15407. null,
  15408. commitMutationEffects,
  15409. null,
  15410. root,
  15411. renderPriorityLevel
  15412. );
  15413. if (hasCaughtError()) {
  15414. if (!(nextEffect !== null)) {
  15415. throw Error("Should be working on an effect.");
  15416. }
  15417. var _error = clearCaughtError();
  15418. captureCommitPhaseError(nextEffect, _error);
  15419. nextEffect = nextEffect.nextEffect;
  15420. }
  15421. }
  15422. } while (nextEffect !== null);
  15423. stopCommitHostEffectsTimer();
  15424. resetAfterCommit(root.containerInfo); // The work-in-progress tree is now the current tree. This must come after
  15425. // the mutation phase, so that the previous tree is still current during
  15426. // componentWillUnmount, but before the layout phase, so that the finished
  15427. // work is current during componentDidMount/Update.
  15428. root.current = finishedWork; // The next phase is the layout phase, where we call effects that read
  15429. // the host tree after it's been mutated. The idiomatic use case for this is
  15430. // layout, but class component lifecycles also fire here for legacy reasons.
  15431. startCommitLifeCyclesTimer();
  15432. nextEffect = firstEffect;
  15433. do {
  15434. {
  15435. invokeGuardedCallback(
  15436. null,
  15437. commitLayoutEffects,
  15438. null,
  15439. root,
  15440. expirationTime
  15441. );
  15442. if (hasCaughtError()) {
  15443. if (!(nextEffect !== null)) {
  15444. throw Error("Should be working on an effect.");
  15445. }
  15446. var _error2 = clearCaughtError();
  15447. captureCommitPhaseError(nextEffect, _error2);
  15448. nextEffect = nextEffect.nextEffect;
  15449. }
  15450. }
  15451. } while (nextEffect !== null);
  15452. stopCommitLifeCyclesTimer();
  15453. nextEffect = null; // Tell Scheduler to yield at the end of the frame, so the browser has an
  15454. // opportunity to paint.
  15455. requestPaint();
  15456. {
  15457. popInteractions(prevInteractions);
  15458. }
  15459. executionContext = prevExecutionContext;
  15460. } else {
  15461. // No effects.
  15462. root.current = finishedWork; // Measure these anyway so the flamegraph explicitly shows that there were
  15463. // no effects.
  15464. // TODO: Maybe there's a better way to report this.
  15465. startCommitSnapshotEffectsTimer();
  15466. stopCommitSnapshotEffectsTimer();
  15467. {
  15468. recordCommitTime();
  15469. }
  15470. startCommitHostEffectsTimer();
  15471. stopCommitHostEffectsTimer();
  15472. startCommitLifeCyclesTimer();
  15473. stopCommitLifeCyclesTimer();
  15474. }
  15475. stopCommitTimer();
  15476. var rootDidHavePassiveEffects = rootDoesHavePassiveEffects;
  15477. if (rootDoesHavePassiveEffects) {
  15478. // This commit has passive effects. Stash a reference to them. But don't
  15479. // schedule a callback until after flushing layout work.
  15480. rootDoesHavePassiveEffects = false;
  15481. rootWithPendingPassiveEffects = root;
  15482. pendingPassiveEffectsExpirationTime = expirationTime;
  15483. pendingPassiveEffectsRenderPriority = renderPriorityLevel;
  15484. } else {
  15485. // We are done with the effect chain at this point so let's clear the
  15486. // nextEffect pointers to assist with GC. If we have passive effects, we'll
  15487. // clear this in flushPassiveEffects.
  15488. nextEffect = firstEffect;
  15489. while (nextEffect !== null) {
  15490. var nextNextEffect = nextEffect.nextEffect;
  15491. nextEffect.nextEffect = null;
  15492. nextEffect = nextNextEffect;
  15493. }
  15494. } // Check if there's remaining work on this root
  15495. var remainingExpirationTime = root.firstPendingTime;
  15496. if (remainingExpirationTime !== NoWork) {
  15497. {
  15498. if (spawnedWorkDuringRender !== null) {
  15499. var expirationTimes = spawnedWorkDuringRender;
  15500. spawnedWorkDuringRender = null;
  15501. for (var i = 0; i < expirationTimes.length; i++) {
  15502. scheduleInteractions(
  15503. root,
  15504. expirationTimes[i],
  15505. root.memoizedInteractions
  15506. );
  15507. }
  15508. }
  15509. schedulePendingInteractions(root, remainingExpirationTime);
  15510. }
  15511. } else {
  15512. // If there's no remaining work, we can clear the set of already failed
  15513. // error boundaries.
  15514. legacyErrorBoundariesThatAlreadyFailed = null;
  15515. }
  15516. {
  15517. if (!rootDidHavePassiveEffects) {
  15518. // If there are no passive effects, then we can complete the pending interactions.
  15519. // Otherwise, we'll wait until after the passive effects are flushed.
  15520. // Wait to do this until after remaining work has been scheduled,
  15521. // so that we don't prematurely signal complete for interactions when there's e.g. hidden work.
  15522. finishPendingInteractions(root, expirationTime);
  15523. }
  15524. }
  15525. if (remainingExpirationTime === Sync) {
  15526. // Count the number of times the root synchronously re-renders without
  15527. // finishing. If there are too many, it indicates an infinite update loop.
  15528. if (root === rootWithNestedUpdates) {
  15529. nestedUpdateCount++;
  15530. } else {
  15531. nestedUpdateCount = 0;
  15532. rootWithNestedUpdates = root;
  15533. }
  15534. } else {
  15535. nestedUpdateCount = 0;
  15536. }
  15537. onCommitRoot(finishedWork.stateNode, expirationTime); // Always call this before exiting `commitRoot`, to ensure that any
  15538. // additional work on this root is scheduled.
  15539. ensureRootIsScheduled(root);
  15540. if (hasUncaughtError) {
  15541. hasUncaughtError = false;
  15542. var _error3 = firstUncaughtError;
  15543. firstUncaughtError = null;
  15544. throw _error3;
  15545. }
  15546. if ((executionContext & LegacyUnbatchedContext) !== NoContext) {
  15547. // This is a legacy edge case. We just committed the initial mount of
  15548. // a ReactDOM.render-ed root inside of batchedUpdates. The commit fired
  15549. // synchronously, but layout updates should be deferred until the end
  15550. // of the batch.
  15551. return null;
  15552. } // If layout work was scheduled, flush it now.
  15553. flushSyncCallbackQueue();
  15554. return null;
  15555. }
  15556. function commitBeforeMutationEffects() {
  15557. while (nextEffect !== null) {
  15558. var effectTag = nextEffect.effectTag;
  15559. if ((effectTag & Snapshot) !== NoEffect) {
  15560. setCurrentFiber(nextEffect);
  15561. recordEffect();
  15562. var current = nextEffect.alternate;
  15563. commitBeforeMutationLifeCycles(current, nextEffect);
  15564. resetCurrentFiber();
  15565. }
  15566. if ((effectTag & Passive) !== NoEffect) {
  15567. // If there are passive effects, schedule a callback to flush at
  15568. // the earliest opportunity.
  15569. if (!rootDoesHavePassiveEffects) {
  15570. rootDoesHavePassiveEffects = true;
  15571. scheduleCallback(NormalPriority, function() {
  15572. flushPassiveEffects();
  15573. return null;
  15574. });
  15575. }
  15576. }
  15577. nextEffect = nextEffect.nextEffect;
  15578. }
  15579. }
  15580. function commitMutationEffects(root, renderPriorityLevel) {
  15581. // TODO: Should probably move the bulk of this function to commitWork.
  15582. while (nextEffect !== null) {
  15583. setCurrentFiber(nextEffect);
  15584. var effectTag = nextEffect.effectTag;
  15585. if (effectTag & Ref) {
  15586. var current = nextEffect.alternate;
  15587. if (current !== null) {
  15588. commitDetachRef(current);
  15589. }
  15590. } // The following switch statement is only concerned about placement,
  15591. // updates, and deletions. To avoid needing to add a case for every possible
  15592. // bitmap value, we remove the secondary effects from the effect tag and
  15593. // switch on that value.
  15594. var primaryEffectTag =
  15595. effectTag & (Placement | Update | Deletion | Hydrating);
  15596. switch (primaryEffectTag) {
  15597. case Placement: {
  15598. // inserted, before any life-cycles like componentDidMount gets called.
  15599. // TODO: findDOMNode doesn't rely on this any more but isMounted does
  15600. // and isMounted is deprecated anyway so we should be able to kill this.
  15601. nextEffect.effectTag &= ~Placement;
  15602. break;
  15603. }
  15604. case PlacementAndUpdate: {
  15605. // inserted, before any life-cycles like componentDidMount gets called.
  15606. nextEffect.effectTag &= ~Placement; // Update
  15607. var _current = nextEffect.alternate;
  15608. commitWork(_current, nextEffect);
  15609. break;
  15610. }
  15611. case Hydrating: {
  15612. nextEffect.effectTag &= ~Hydrating;
  15613. break;
  15614. }
  15615. case HydratingAndUpdate: {
  15616. nextEffect.effectTag &= ~Hydrating; // Update
  15617. var _current2 = nextEffect.alternate;
  15618. commitWork(_current2, nextEffect);
  15619. break;
  15620. }
  15621. case Update: {
  15622. var _current3 = nextEffect.alternate;
  15623. commitWork(_current3, nextEffect);
  15624. break;
  15625. }
  15626. case Deletion: {
  15627. commitDeletion(root, nextEffect, renderPriorityLevel);
  15628. break;
  15629. }
  15630. } // TODO: Only record a mutation effect if primaryEffectTag is non-zero.
  15631. recordEffect();
  15632. resetCurrentFiber();
  15633. nextEffect = nextEffect.nextEffect;
  15634. }
  15635. }
  15636. function commitLayoutEffects(root, committedExpirationTime) {
  15637. // TODO: Should probably move the bulk of this function to commitWork.
  15638. while (nextEffect !== null) {
  15639. setCurrentFiber(nextEffect);
  15640. var effectTag = nextEffect.effectTag;
  15641. if (effectTag & (Update | Callback)) {
  15642. recordEffect();
  15643. var current = nextEffect.alternate;
  15644. commitLifeCycles(root, current, nextEffect);
  15645. }
  15646. if (effectTag & Ref) {
  15647. recordEffect();
  15648. commitAttachRef(nextEffect);
  15649. }
  15650. resetCurrentFiber();
  15651. nextEffect = nextEffect.nextEffect;
  15652. }
  15653. }
  15654. function flushPassiveEffects() {
  15655. if (pendingPassiveEffectsRenderPriority !== NoPriority) {
  15656. var priorityLevel =
  15657. pendingPassiveEffectsRenderPriority > NormalPriority
  15658. ? NormalPriority
  15659. : pendingPassiveEffectsRenderPriority;
  15660. pendingPassiveEffectsRenderPriority = NoPriority;
  15661. return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
  15662. }
  15663. }
  15664. function flushPassiveEffectsImpl() {
  15665. if (rootWithPendingPassiveEffects === null) {
  15666. return false;
  15667. }
  15668. var root = rootWithPendingPassiveEffects;
  15669. var expirationTime = pendingPassiveEffectsExpirationTime;
  15670. rootWithPendingPassiveEffects = null;
  15671. pendingPassiveEffectsExpirationTime = NoWork;
  15672. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  15673. throw Error("Cannot flush passive effects while already rendering.");
  15674. }
  15675. var prevExecutionContext = executionContext;
  15676. executionContext |= CommitContext;
  15677. var prevInteractions = pushInteractions(root);
  15678. {
  15679. // Note: This currently assumes there are no passive effects on the root fiber
  15680. // because the root is not part of its own effect list.
  15681. // This could change in the future.
  15682. var _effect2 = root.current.firstEffect;
  15683. while (_effect2 !== null) {
  15684. {
  15685. setCurrentFiber(_effect2);
  15686. invokeGuardedCallback(null, commitPassiveHookEffects, null, _effect2);
  15687. if (hasCaughtError()) {
  15688. if (!(_effect2 !== null)) {
  15689. throw Error("Should be working on an effect.");
  15690. }
  15691. var _error5 = clearCaughtError();
  15692. captureCommitPhaseError(_effect2, _error5);
  15693. }
  15694. resetCurrentFiber();
  15695. }
  15696. var nextNextEffect = _effect2.nextEffect; // Remove nextEffect pointer to assist GC
  15697. _effect2.nextEffect = null;
  15698. _effect2 = nextNextEffect;
  15699. }
  15700. }
  15701. {
  15702. popInteractions(prevInteractions);
  15703. finishPendingInteractions(root, expirationTime);
  15704. }
  15705. executionContext = prevExecutionContext;
  15706. flushSyncCallbackQueue(); // If additional passive effects were scheduled, increment a counter. If this
  15707. // exceeds the limit, we'll fire a warning.
  15708. nestedPassiveUpdateCount =
  15709. rootWithPendingPassiveEffects === null ? 0 : nestedPassiveUpdateCount + 1;
  15710. return true;
  15711. }
  15712. function isAlreadyFailedLegacyErrorBoundary(instance) {
  15713. return (
  15714. legacyErrorBoundariesThatAlreadyFailed !== null &&
  15715. legacyErrorBoundariesThatAlreadyFailed.has(instance)
  15716. );
  15717. }
  15718. function markLegacyErrorBoundaryAsFailed(instance) {
  15719. if (legacyErrorBoundariesThatAlreadyFailed === null) {
  15720. legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
  15721. } else {
  15722. legacyErrorBoundariesThatAlreadyFailed.add(instance);
  15723. }
  15724. }
  15725. function prepareToThrowUncaughtError(error) {
  15726. if (!hasUncaughtError) {
  15727. hasUncaughtError = true;
  15728. firstUncaughtError = error;
  15729. }
  15730. }
  15731. var onUncaughtError = prepareToThrowUncaughtError;
  15732. function captureCommitPhaseErrorOnRoot(rootFiber, sourceFiber, error) {
  15733. var errorInfo = createCapturedValue(error, sourceFiber);
  15734. var update = createRootErrorUpdate(rootFiber, errorInfo, Sync);
  15735. enqueueUpdate(rootFiber, update);
  15736. var root = markUpdateTimeFromFiberToRoot(rootFiber, Sync);
  15737. if (root !== null) {
  15738. ensureRootIsScheduled(root);
  15739. schedulePendingInteractions(root, Sync);
  15740. }
  15741. }
  15742. function captureCommitPhaseError(sourceFiber, error) {
  15743. if (sourceFiber.tag === HostRoot) {
  15744. // Error was thrown at the root. There is no parent, so the root
  15745. // itself should capture it.
  15746. captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error);
  15747. return;
  15748. }
  15749. var fiber = sourceFiber.return;
  15750. while (fiber !== null) {
  15751. if (fiber.tag === HostRoot) {
  15752. captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
  15753. return;
  15754. } else if (fiber.tag === ClassComponent) {
  15755. var ctor = fiber.type;
  15756. var instance = fiber.stateNode;
  15757. if (
  15758. typeof ctor.getDerivedStateFromError === "function" ||
  15759. (typeof instance.componentDidCatch === "function" &&
  15760. !isAlreadyFailedLegacyErrorBoundary(instance))
  15761. ) {
  15762. var errorInfo = createCapturedValue(error, sourceFiber);
  15763. var update = createClassErrorUpdate(
  15764. fiber,
  15765. errorInfo, // TODO: This is always sync
  15766. Sync
  15767. );
  15768. enqueueUpdate(fiber, update);
  15769. var root = markUpdateTimeFromFiberToRoot(fiber, Sync);
  15770. if (root !== null) {
  15771. ensureRootIsScheduled(root);
  15772. schedulePendingInteractions(root, Sync);
  15773. }
  15774. return;
  15775. }
  15776. }
  15777. fiber = fiber.return;
  15778. }
  15779. }
  15780. function pingSuspendedRoot(root, thenable, suspendedTime) {
  15781. var pingCache = root.pingCache;
  15782. if (pingCache !== null) {
  15783. // The thenable resolved, so we no longer need to memoize, because it will
  15784. // never be thrown again.
  15785. pingCache.delete(thenable);
  15786. }
  15787. if (workInProgressRoot === root && renderExpirationTime$1 === suspendedTime) {
  15788. // Received a ping at the same priority level at which we're currently
  15789. // rendering. We might want to restart this render. This should mirror
  15790. // the logic of whether or not a root suspends once it completes.
  15791. // TODO: If we're rendering sync either due to Sync, Batched or expired,
  15792. // we should probably never restart.
  15793. // If we're suspended with delay, we'll always suspend so we can always
  15794. // restart. If we're suspended without any updates, it might be a retry.
  15795. // If it's early in the retry we can restart. We can't know for sure
  15796. // whether we'll eventually process an update during this render pass,
  15797. // but it's somewhat unlikely that we get to a ping before that, since
  15798. // getting to the root most update is usually very fast.
  15799. if (
  15800. workInProgressRootExitStatus === RootSuspendedWithDelay ||
  15801. (workInProgressRootExitStatus === RootSuspended &&
  15802. workInProgressRootLatestProcessedExpirationTime === Sync &&
  15803. now() - globalMostRecentFallbackTime < FALLBACK_THROTTLE_MS)
  15804. ) {
  15805. // Restart from the root. Don't need to schedule a ping because
  15806. // we're already working on this tree.
  15807. prepareFreshStack(root, renderExpirationTime$1);
  15808. } else {
  15809. // Even though we can't restart right now, we might get an
  15810. // opportunity later. So we mark this render as having a ping.
  15811. workInProgressRootHasPendingPing = true;
  15812. }
  15813. return;
  15814. }
  15815. if (!isRootSuspendedAtTime(root, suspendedTime)) {
  15816. // The root is no longer suspended at this time.
  15817. return;
  15818. }
  15819. var lastPingedTime = root.lastPingedTime;
  15820. if (lastPingedTime !== NoWork && lastPingedTime < suspendedTime) {
  15821. // There's already a lower priority ping scheduled.
  15822. return;
  15823. } // Mark the time at which this ping was scheduled.
  15824. root.lastPingedTime = suspendedTime;
  15825. ensureRootIsScheduled(root);
  15826. schedulePendingInteractions(root, suspendedTime);
  15827. }
  15828. function retryTimedOutBoundary(boundaryFiber, retryTime) {
  15829. // The boundary fiber (a Suspense component or SuspenseList component)
  15830. // previously was rendered in its fallback state. One of the promises that
  15831. // suspended it has resolved, which means at least part of the tree was
  15832. // likely unblocked. Try rendering again, at a new expiration time.
  15833. if (retryTime === NoWork) {
  15834. var suspenseConfig = null; // Retries don't carry over the already committed update.
  15835. var currentTime = requestCurrentTimeForUpdate();
  15836. retryTime = computeExpirationForFiber(
  15837. currentTime,
  15838. boundaryFiber,
  15839. suspenseConfig
  15840. );
  15841. } // TODO: Special case idle priority?
  15842. var root = markUpdateTimeFromFiberToRoot(boundaryFiber, retryTime);
  15843. if (root !== null) {
  15844. ensureRootIsScheduled(root);
  15845. schedulePendingInteractions(root, retryTime);
  15846. }
  15847. }
  15848. function resolveRetryThenable(boundaryFiber, thenable) {
  15849. var retryTime = NoWork; // Default
  15850. var retryCache;
  15851. {
  15852. retryCache = boundaryFiber.stateNode;
  15853. }
  15854. if (retryCache !== null) {
  15855. // The thenable resolved, so we no longer need to memoize, because it will
  15856. // never be thrown again.
  15857. retryCache.delete(thenable);
  15858. }
  15859. retryTimedOutBoundary(boundaryFiber, retryTime);
  15860. } // Computes the next Just Noticeable Difference (JND) boundary.
  15861. // The theory is that a person can't tell the difference between small differences in time.
  15862. // Therefore, if we wait a bit longer than necessary that won't translate to a noticeable
  15863. // difference in the experience. However, waiting for longer might mean that we can avoid
  15864. // showing an intermediate loading state. The longer we have already waited, the harder it
  15865. // is to tell small differences in time. Therefore, the longer we've already waited,
  15866. // the longer we can wait additionally. At some point we have to give up though.
  15867. // We pick a train model where the next boundary commits at a consistent schedule.
  15868. // These particular numbers are vague estimates. We expect to adjust them based on research.
  15869. function jnd(timeElapsed) {
  15870. return timeElapsed < 120
  15871. ? 120
  15872. : timeElapsed < 480
  15873. ? 480
  15874. : timeElapsed < 1080
  15875. ? 1080
  15876. : timeElapsed < 1920
  15877. ? 1920
  15878. : timeElapsed < 3000
  15879. ? 3000
  15880. : timeElapsed < 4320
  15881. ? 4320
  15882. : ceil(timeElapsed / 1960) * 1960;
  15883. }
  15884. function computeMsUntilSuspenseLoadingDelay(
  15885. mostRecentEventTime,
  15886. committedExpirationTime,
  15887. suspenseConfig
  15888. ) {
  15889. var busyMinDurationMs = suspenseConfig.busyMinDurationMs | 0;
  15890. if (busyMinDurationMs <= 0) {
  15891. return 0;
  15892. }
  15893. var busyDelayMs = suspenseConfig.busyDelayMs | 0; // Compute the time until this render pass would expire.
  15894. var currentTimeMs = now();
  15895. var eventTimeMs = inferTimeFromExpirationTimeWithSuspenseConfig(
  15896. mostRecentEventTime,
  15897. suspenseConfig
  15898. );
  15899. var timeElapsed = currentTimeMs - eventTimeMs;
  15900. if (timeElapsed <= busyDelayMs) {
  15901. // If we haven't yet waited longer than the initial delay, we don't
  15902. // have to wait any additional time.
  15903. return 0;
  15904. }
  15905. var msUntilTimeout = busyDelayMs + busyMinDurationMs - timeElapsed; // This is the value that is passed to `setTimeout`.
  15906. return msUntilTimeout;
  15907. }
  15908. function checkForNestedUpdates() {
  15909. if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
  15910. nestedUpdateCount = 0;
  15911. rootWithNestedUpdates = null;
  15912. {
  15913. throw Error(
  15914. "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."
  15915. );
  15916. }
  15917. }
  15918. {
  15919. if (nestedPassiveUpdateCount > NESTED_PASSIVE_UPDATE_LIMIT) {
  15920. nestedPassiveUpdateCount = 0;
  15921. error(
  15922. "Maximum update depth exceeded. This can happen when a component " +
  15923. "calls setState inside useEffect, but useEffect either doesn't " +
  15924. "have a dependency array, or one of the dependencies changes on " +
  15925. "every render."
  15926. );
  15927. }
  15928. }
  15929. }
  15930. function flushRenderPhaseStrictModeWarningsInDEV() {
  15931. {
  15932. ReactStrictModeWarnings.flushLegacyContextWarning();
  15933. {
  15934. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
  15935. }
  15936. }
  15937. }
  15938. function stopFinishedWorkLoopTimer() {
  15939. var didCompleteRoot = true;
  15940. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  15941. interruptedBy = null;
  15942. }
  15943. function stopInterruptedWorkLoopTimer() {
  15944. // TODO: Track which fiber caused the interruption.
  15945. var didCompleteRoot = false;
  15946. stopWorkLoopTimer(interruptedBy, didCompleteRoot);
  15947. interruptedBy = null;
  15948. }
  15949. function checkForInterruption(fiberThatReceivedUpdate, updateExpirationTime) {
  15950. if (
  15951. workInProgressRoot !== null &&
  15952. updateExpirationTime > renderExpirationTime$1
  15953. ) {
  15954. interruptedBy = fiberThatReceivedUpdate;
  15955. }
  15956. }
  15957. var didWarnStateUpdateForUnmountedComponent = null;
  15958. function warnAboutUpdateOnUnmountedFiberInDEV(fiber) {
  15959. {
  15960. var tag = fiber.tag;
  15961. if (
  15962. tag !== HostRoot &&
  15963. tag !== ClassComponent &&
  15964. tag !== FunctionComponent &&
  15965. tag !== ForwardRef &&
  15966. tag !== MemoComponent &&
  15967. tag !== SimpleMemoComponent &&
  15968. tag !== Block
  15969. ) {
  15970. // Only warn for user-defined components, not internal ones like Suspense.
  15971. return;
  15972. }
  15973. // the problematic code almost always lies inside that component.
  15974. var componentName = getComponentName(fiber.type) || "ReactComponent";
  15975. if (didWarnStateUpdateForUnmountedComponent !== null) {
  15976. if (didWarnStateUpdateForUnmountedComponent.has(componentName)) {
  15977. return;
  15978. }
  15979. didWarnStateUpdateForUnmountedComponent.add(componentName);
  15980. } else {
  15981. didWarnStateUpdateForUnmountedComponent = new Set([componentName]);
  15982. }
  15983. error(
  15984. "Can't perform a React state update on an unmounted component. This " +
  15985. "is a no-op, but it indicates a memory leak in your application. To " +
  15986. "fix, cancel all subscriptions and asynchronous tasks in %s.%s",
  15987. tag === ClassComponent
  15988. ? "the componentWillUnmount method"
  15989. : "a useEffect cleanup function",
  15990. getStackByFiberInDevAndProd(fiber)
  15991. );
  15992. }
  15993. }
  15994. var beginWork$1;
  15995. {
  15996. var dummyFiber = null;
  15997. beginWork$1 = function(current, unitOfWork, expirationTime) {
  15998. // If a component throws an error, we replay it again in a synchronously
  15999. // dispatched event, so that the debugger will treat it as an uncaught
  16000. // error See ReactErrorUtils for more information.
  16001. // Before entering the begin phase, copy the work-in-progress onto a dummy
  16002. // fiber. If beginWork throws, we'll use this to reset the state.
  16003. var originalWorkInProgressCopy = assignFiberPropertiesInDEV(
  16004. dummyFiber,
  16005. unitOfWork
  16006. );
  16007. try {
  16008. return beginWork(current, unitOfWork, expirationTime);
  16009. } catch (originalError) {
  16010. if (
  16011. originalError !== null &&
  16012. typeof originalError === "object" &&
  16013. typeof originalError.then === "function"
  16014. ) {
  16015. // Don't replay promises. Treat everything else like an error.
  16016. throw originalError;
  16017. } // Keep this code in sync with handleError; any changes here must have
  16018. // corresponding changes there.
  16019. resetContextDependencies();
  16020. resetHooksAfterThrow(); // Don't reset current debug fiber, since we're about to work on the
  16021. // same fiber again.
  16022. // Unwind the failed stack frame
  16023. unwindInterruptedWork(unitOfWork); // Restore the original properties of the fiber.
  16024. assignFiberPropertiesInDEV(unitOfWork, originalWorkInProgressCopy);
  16025. if (unitOfWork.mode & ProfileMode) {
  16026. // Reset the profiler timer.
  16027. startProfilerTimer(unitOfWork);
  16028. } // Run beginWork again.
  16029. invokeGuardedCallback(
  16030. null,
  16031. beginWork,
  16032. null,
  16033. current,
  16034. unitOfWork,
  16035. expirationTime
  16036. );
  16037. if (hasCaughtError()) {
  16038. var replayError = clearCaughtError(); // `invokeGuardedCallback` sometimes sets an expando `_suppressLogging`.
  16039. // Rethrow this error instead of the original one.
  16040. throw replayError;
  16041. } else {
  16042. // This branch is reachable if the render phase is impure.
  16043. throw originalError;
  16044. }
  16045. }
  16046. };
  16047. }
  16048. var didWarnAboutUpdateInRender = false;
  16049. function warnAboutRenderPhaseUpdatesInDEV(fiber) {
  16050. {
  16051. if ((executionContext & RenderContext) !== NoContext) {
  16052. switch (fiber.tag) {
  16053. case FunctionComponent:
  16054. case ForwardRef:
  16055. case SimpleMemoComponent: {
  16056. error(
  16057. "Cannot update a component from inside the function body of a " +
  16058. "different component."
  16059. );
  16060. break;
  16061. }
  16062. case ClassComponent: {
  16063. if (isRendering && !didWarnAboutUpdateInRender) {
  16064. error(
  16065. "Cannot update during an existing state transition (such as " +
  16066. "within `render`). Render methods should be a pure " +
  16067. "function of props and state."
  16068. );
  16069. didWarnAboutUpdateInRender = true;
  16070. break;
  16071. }
  16072. }
  16073. }
  16074. }
  16075. }
  16076. } // a 'shared' variable that changes when act() opens/closes in tests.
  16077. var IsThisRendererActing = {
  16078. current: false
  16079. };
  16080. var didWarnAboutUnmockedScheduler = false; // TODO Before we release concurrent mode, revisit this and decide whether a mocked
  16081. // scheduler is the actual recommendation. The alternative could be a testing build,
  16082. // a new lib, or whatever; we dunno just yet. This message is for early adopters
  16083. // to get their tests right.
  16084. function warnIfUnmockedScheduler(fiber) {
  16085. {
  16086. if (
  16087. didWarnAboutUnmockedScheduler === false &&
  16088. Scheduler.unstable_flushAllWithoutAsserting === undefined
  16089. ) {
  16090. if (fiber.mode & BlockingMode || fiber.mode & ConcurrentMode) {
  16091. didWarnAboutUnmockedScheduler = true;
  16092. error(
  16093. 'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
  16094. "to guarantee consistent behaviour across tests and browsers. " +
  16095. "For example, with jest: \n" + // Break up requires to avoid accidentally parsing them as dependencies.
  16096. "jest.mock('scheduler', () => require" +
  16097. "('scheduler/unstable_mock'));\n\n" +
  16098. "For more info, visit https://fb.me/react-mock-scheduler"
  16099. );
  16100. }
  16101. }
  16102. }
  16103. }
  16104. function computeThreadID(root, expirationTime) {
  16105. // Interaction threads are unique per root and expiration time.
  16106. return expirationTime * 1000 + root.interactionThreadID;
  16107. }
  16108. function markSpawnedWork(expirationTime) {
  16109. if (spawnedWorkDuringRender === null) {
  16110. spawnedWorkDuringRender = [expirationTime];
  16111. } else {
  16112. spawnedWorkDuringRender.push(expirationTime);
  16113. }
  16114. }
  16115. function scheduleInteractions(root, expirationTime, interactions) {
  16116. if (interactions.size > 0) {
  16117. var pendingInteractionMap = root.pendingInteractionMap;
  16118. var pendingInteractions = pendingInteractionMap.get(expirationTime);
  16119. if (pendingInteractions != null) {
  16120. interactions.forEach(function(interaction) {
  16121. if (!pendingInteractions.has(interaction)) {
  16122. // Update the pending async work count for previously unscheduled interaction.
  16123. interaction.__count++;
  16124. }
  16125. pendingInteractions.add(interaction);
  16126. });
  16127. } else {
  16128. pendingInteractionMap.set(expirationTime, new Set(interactions)); // Update the pending async work count for the current interactions.
  16129. interactions.forEach(function(interaction) {
  16130. interaction.__count++;
  16131. });
  16132. }
  16133. var subscriber = tracing.__subscriberRef.current;
  16134. if (subscriber !== null) {
  16135. var threadID = computeThreadID(root, expirationTime);
  16136. subscriber.onWorkScheduled(interactions, threadID);
  16137. }
  16138. }
  16139. }
  16140. function schedulePendingInteractions(root, expirationTime) {
  16141. scheduleInteractions(root, expirationTime, tracing.__interactionsRef.current);
  16142. }
  16143. function startWorkOnPendingInteractions(root, expirationTime) {
  16144. // we can accurately attribute time spent working on it, And so that cascading
  16145. // work triggered during the render phase will be associated with it.
  16146. var interactions = new Set();
  16147. root.pendingInteractionMap.forEach(function(
  16148. scheduledInteractions,
  16149. scheduledExpirationTime
  16150. ) {
  16151. if (scheduledExpirationTime >= expirationTime) {
  16152. scheduledInteractions.forEach(function(interaction) {
  16153. return interactions.add(interaction);
  16154. });
  16155. }
  16156. }); // Store the current set of interactions on the FiberRoot for a few reasons:
  16157. // We can re-use it in hot functions like performConcurrentWorkOnRoot()
  16158. // without having to recalculate it. We will also use it in commitWork() to
  16159. // pass to any Profiler onRender() hooks. This also provides DevTools with a
  16160. // way to access it when the onCommitRoot() hook is called.
  16161. root.memoizedInteractions = interactions;
  16162. if (interactions.size > 0) {
  16163. var subscriber = tracing.__subscriberRef.current;
  16164. if (subscriber !== null) {
  16165. var threadID = computeThreadID(root, expirationTime);
  16166. try {
  16167. subscriber.onWorkStarted(interactions, threadID);
  16168. } catch (error) {
  16169. // If the subscriber throws, rethrow it in a separate task
  16170. scheduleCallback(ImmediatePriority, function() {
  16171. throw error;
  16172. });
  16173. }
  16174. }
  16175. }
  16176. }
  16177. function finishPendingInteractions(root, committedExpirationTime) {
  16178. var earliestRemainingTimeAfterCommit = root.firstPendingTime;
  16179. var subscriber;
  16180. try {
  16181. subscriber = tracing.__subscriberRef.current;
  16182. if (subscriber !== null && root.memoizedInteractions.size > 0) {
  16183. var threadID = computeThreadID(root, committedExpirationTime);
  16184. subscriber.onWorkStopped(root.memoizedInteractions, threadID);
  16185. }
  16186. } catch (error) {
  16187. // If the subscriber throws, rethrow it in a separate task
  16188. scheduleCallback(ImmediatePriority, function() {
  16189. throw error;
  16190. });
  16191. } finally {
  16192. // Clear completed interactions from the pending Map.
  16193. // Unless the render was suspended or cascading work was scheduled,
  16194. // In which case– leave pending interactions until the subsequent render.
  16195. var pendingInteractionMap = root.pendingInteractionMap;
  16196. pendingInteractionMap.forEach(function(
  16197. scheduledInteractions,
  16198. scheduledExpirationTime
  16199. ) {
  16200. // Only decrement the pending interaction count if we're done.
  16201. // If there's still work at the current priority,
  16202. // That indicates that we are waiting for suspense data.
  16203. if (scheduledExpirationTime > earliestRemainingTimeAfterCommit) {
  16204. pendingInteractionMap.delete(scheduledExpirationTime);
  16205. scheduledInteractions.forEach(function(interaction) {
  16206. interaction.__count--;
  16207. if (subscriber !== null && interaction.__count === 0) {
  16208. try {
  16209. subscriber.onInteractionScheduledWorkCompleted(interaction);
  16210. } catch (error) {
  16211. // If the subscriber throws, rethrow it in a separate task
  16212. scheduleCallback(ImmediatePriority, function() {
  16213. throw error;
  16214. });
  16215. }
  16216. }
  16217. });
  16218. }
  16219. });
  16220. }
  16221. }
  16222. var onScheduleFiberRoot = null;
  16223. var onCommitFiberRoot = null;
  16224. var onCommitFiberUnmount = null;
  16225. var hasLoggedError = false;
  16226. var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined";
  16227. function injectInternals(internals) {
  16228. if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === "undefined") {
  16229. // No DevTools
  16230. return false;
  16231. }
  16232. var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
  16233. if (hook.isDisabled) {
  16234. // This isn't a real property on the hook, but it can be set to opt out
  16235. // of DevTools integration and associated warnings and logs.
  16236. // https://github.com/facebook/react/issues/3877
  16237. return true;
  16238. }
  16239. if (!hook.supportsFiber) {
  16240. {
  16241. error(
  16242. "The installed version of React DevTools is too old and will not work " +
  16243. "with the current version of React. Please update React DevTools. " +
  16244. "https://fb.me/react-devtools"
  16245. );
  16246. } // DevTools exists, even though it doesn't support Fiber.
  16247. return true;
  16248. }
  16249. try {
  16250. var rendererID = hook.inject(internals); // We have successfully injected, so now it is safe to set up hooks.
  16251. if (true) {
  16252. // Only used by Fast Refresh
  16253. if (typeof hook.onScheduleFiberRoot === "function") {
  16254. onScheduleFiberRoot = function(root, children) {
  16255. try {
  16256. hook.onScheduleFiberRoot(rendererID, root, children);
  16257. } catch (err) {
  16258. if (true && !hasLoggedError) {
  16259. hasLoggedError = true;
  16260. error("React instrumentation encountered an error: %s", err);
  16261. }
  16262. }
  16263. };
  16264. }
  16265. }
  16266. onCommitFiberRoot = function(root, expirationTime) {
  16267. try {
  16268. var didError = (root.current.effectTag & DidCapture) === DidCapture;
  16269. if (enableProfilerTimer) {
  16270. var currentTime = getCurrentTime();
  16271. var priorityLevel = inferPriorityFromExpirationTime(
  16272. currentTime,
  16273. expirationTime
  16274. );
  16275. hook.onCommitFiberRoot(rendererID, root, priorityLevel, didError);
  16276. } else {
  16277. hook.onCommitFiberRoot(rendererID, root, undefined, didError);
  16278. }
  16279. } catch (err) {
  16280. if (true) {
  16281. if (!hasLoggedError) {
  16282. hasLoggedError = true;
  16283. error("React instrumentation encountered an error: %s", err);
  16284. }
  16285. }
  16286. }
  16287. };
  16288. onCommitFiberUnmount = function(fiber) {
  16289. try {
  16290. hook.onCommitFiberUnmount(rendererID, fiber);
  16291. } catch (err) {
  16292. if (true) {
  16293. if (!hasLoggedError) {
  16294. hasLoggedError = true;
  16295. error("React instrumentation encountered an error: %s", err);
  16296. }
  16297. }
  16298. }
  16299. };
  16300. } catch (err) {
  16301. // Catch all errors because it is unsafe to throw during initialization.
  16302. {
  16303. error("React instrumentation encountered an error: %s.", err);
  16304. }
  16305. } // DevTools exists
  16306. return true;
  16307. }
  16308. function onScheduleRoot(root, children) {
  16309. if (typeof onScheduleFiberRoot === "function") {
  16310. onScheduleFiberRoot(root, children);
  16311. }
  16312. }
  16313. function onCommitRoot(root, expirationTime) {
  16314. if (typeof onCommitFiberRoot === "function") {
  16315. onCommitFiberRoot(root, expirationTime);
  16316. }
  16317. }
  16318. function onCommitUnmount(fiber) {
  16319. if (typeof onCommitFiberUnmount === "function") {
  16320. onCommitFiberUnmount(fiber);
  16321. }
  16322. }
  16323. var hasBadMapPolyfill;
  16324. {
  16325. hasBadMapPolyfill = false;
  16326. try {
  16327. var nonExtensibleObject = Object.preventExtensions({});
  16328. var testMap = new Map([[nonExtensibleObject, null]]);
  16329. var testSet = new Set([nonExtensibleObject]); // This is necessary for Rollup to not consider these unused.
  16330. // https://github.com/rollup/rollup/issues/1771
  16331. // TODO: we can remove these if Rollup fixes the bug.
  16332. testMap.set(0, 0);
  16333. testSet.add(0);
  16334. } catch (e) {
  16335. // TODO: Consider warning about bad polyfills
  16336. hasBadMapPolyfill = true;
  16337. }
  16338. }
  16339. var debugCounter = 1;
  16340. function FiberNode(tag, pendingProps, key, mode) {
  16341. // Instance
  16342. this.tag = tag;
  16343. this.key = key;
  16344. this.elementType = null;
  16345. this.type = null;
  16346. this.stateNode = null; // Fiber
  16347. this.return = null;
  16348. this.child = null;
  16349. this.sibling = null;
  16350. this.index = 0;
  16351. this.ref = null;
  16352. this.pendingProps = pendingProps;
  16353. this.memoizedProps = null;
  16354. this.updateQueue = null;
  16355. this.memoizedState = null;
  16356. this.dependencies = null;
  16357. this.mode = mode; // Effects
  16358. this.effectTag = NoEffect;
  16359. this.nextEffect = null;
  16360. this.firstEffect = null;
  16361. this.lastEffect = null;
  16362. this.expirationTime = NoWork;
  16363. this.childExpirationTime = NoWork;
  16364. this.alternate = null;
  16365. {
  16366. // Note: The following is done to avoid a v8 performance cliff.
  16367. //
  16368. // Initializing the fields below to smis and later updating them with
  16369. // double values will cause Fibers to end up having separate shapes.
  16370. // This behavior/bug has something to do with Object.preventExtension().
  16371. // Fortunately this only impacts DEV builds.
  16372. // Unfortunately it makes React unusably slow for some applications.
  16373. // To work around this, initialize the fields below with doubles.
  16374. //
  16375. // Learn more about this here:
  16376. // https://github.com/facebook/react/issues/14365
  16377. // https://bugs.chromium.org/p/v8/issues/detail?id=8538
  16378. this.actualDuration = Number.NaN;
  16379. this.actualStartTime = Number.NaN;
  16380. this.selfBaseDuration = Number.NaN;
  16381. this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization.
  16382. // This won't trigger the performance cliff mentioned above,
  16383. // and it simplifies other profiler code (including DevTools).
  16384. this.actualDuration = 0;
  16385. this.actualStartTime = -1;
  16386. this.selfBaseDuration = 0;
  16387. this.treeBaseDuration = 0;
  16388. } // This is normally DEV-only except www when it adds listeners.
  16389. // TODO: remove the User Timing integration in favor of Root Events.
  16390. {
  16391. this._debugID = debugCounter++;
  16392. this._debugIsCurrentlyTiming = false;
  16393. }
  16394. {
  16395. this._debugSource = null;
  16396. this._debugOwner = null;
  16397. this._debugNeedsRemount = false;
  16398. this._debugHookTypes = null;
  16399. if (!hasBadMapPolyfill && typeof Object.preventExtensions === "function") {
  16400. Object.preventExtensions(this);
  16401. }
  16402. }
  16403. } // This is a constructor function, rather than a POJO constructor, still
  16404. // please ensure we do the following:
  16405. // 1) Nobody should add any instance methods on this. Instance methods can be
  16406. // more difficult to predict when they get optimized and they are almost
  16407. // never inlined properly in static compilers.
  16408. // 2) Nobody should rely on `instanceof Fiber` for type testing. We should
  16409. // always know when it is a fiber.
  16410. // 3) We might want to experiment with using numeric keys since they are easier
  16411. // to optimize in a non-JIT environment.
  16412. // 4) We can easily go from a constructor to a createFiber object literal if that
  16413. // is faster.
  16414. // 5) It should be easy to port this to a C struct and keep a C implementation
  16415. // compatible.
  16416. var createFiber = function(tag, pendingProps, key, mode) {
  16417. // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
  16418. return new FiberNode(tag, pendingProps, key, mode);
  16419. };
  16420. function shouldConstruct(Component) {
  16421. var prototype = Component.prototype;
  16422. return !!(prototype && prototype.isReactComponent);
  16423. }
  16424. function isSimpleFunctionComponent(type) {
  16425. return (
  16426. typeof type === "function" &&
  16427. !shouldConstruct(type) &&
  16428. type.defaultProps === undefined
  16429. );
  16430. }
  16431. function resolveLazyComponentTag(Component) {
  16432. if (typeof Component === "function") {
  16433. return shouldConstruct(Component) ? ClassComponent : FunctionComponent;
  16434. } else if (Component !== undefined && Component !== null) {
  16435. var $$typeof = Component.$$typeof;
  16436. if ($$typeof === REACT_FORWARD_REF_TYPE) {
  16437. return ForwardRef;
  16438. }
  16439. if ($$typeof === REACT_MEMO_TYPE) {
  16440. return MemoComponent;
  16441. }
  16442. }
  16443. return IndeterminateComponent;
  16444. } // This is used to create an alternate fiber to do work on.
  16445. function createWorkInProgress(current, pendingProps) {
  16446. var workInProgress = current.alternate;
  16447. if (workInProgress === null) {
  16448. // We use a double buffering pooling technique because we know that we'll
  16449. // only ever need at most two versions of a tree. We pool the "other" unused
  16450. // node that we're free to reuse. This is lazily created to avoid allocating
  16451. // extra objects for things that are never updated. It also allow us to
  16452. // reclaim the extra memory if needed.
  16453. workInProgress = createFiber(
  16454. current.tag,
  16455. pendingProps,
  16456. current.key,
  16457. current.mode
  16458. );
  16459. workInProgress.elementType = current.elementType;
  16460. workInProgress.type = current.type;
  16461. workInProgress.stateNode = current.stateNode;
  16462. {
  16463. // DEV-only fields
  16464. {
  16465. workInProgress._debugID = current._debugID;
  16466. }
  16467. workInProgress._debugSource = current._debugSource;
  16468. workInProgress._debugOwner = current._debugOwner;
  16469. workInProgress._debugHookTypes = current._debugHookTypes;
  16470. }
  16471. workInProgress.alternate = current;
  16472. current.alternate = workInProgress;
  16473. } else {
  16474. workInProgress.pendingProps = pendingProps; // We already have an alternate.
  16475. // Reset the effect tag.
  16476. workInProgress.effectTag = NoEffect; // The effect list is no longer valid.
  16477. workInProgress.nextEffect = null;
  16478. workInProgress.firstEffect = null;
  16479. workInProgress.lastEffect = null;
  16480. {
  16481. // We intentionally reset, rather than copy, actualDuration & actualStartTime.
  16482. // This prevents time from endlessly accumulating in new commits.
  16483. // This has the downside of resetting values for different priority renders,
  16484. // But works for yielding (the common case) and should support resuming.
  16485. workInProgress.actualDuration = 0;
  16486. workInProgress.actualStartTime = -1;
  16487. }
  16488. }
  16489. workInProgress.childExpirationTime = current.childExpirationTime;
  16490. workInProgress.expirationTime = current.expirationTime;
  16491. workInProgress.child = current.child;
  16492. workInProgress.memoizedProps = current.memoizedProps;
  16493. workInProgress.memoizedState = current.memoizedState;
  16494. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  16495. // it cannot be shared with the current fiber.
  16496. var currentDependencies = current.dependencies;
  16497. workInProgress.dependencies =
  16498. currentDependencies === null
  16499. ? null
  16500. : {
  16501. expirationTime: currentDependencies.expirationTime,
  16502. firstContext: currentDependencies.firstContext,
  16503. responders: currentDependencies.responders
  16504. }; // These will be overridden during the parent's reconciliation
  16505. workInProgress.sibling = current.sibling;
  16506. workInProgress.index = current.index;
  16507. workInProgress.ref = current.ref;
  16508. {
  16509. workInProgress.selfBaseDuration = current.selfBaseDuration;
  16510. workInProgress.treeBaseDuration = current.treeBaseDuration;
  16511. }
  16512. {
  16513. workInProgress._debugNeedsRemount = current._debugNeedsRemount;
  16514. switch (workInProgress.tag) {
  16515. case IndeterminateComponent:
  16516. case FunctionComponent:
  16517. case SimpleMemoComponent:
  16518. workInProgress.type = resolveFunctionForHotReloading(current.type);
  16519. break;
  16520. case ClassComponent:
  16521. workInProgress.type = resolveClassForHotReloading(current.type);
  16522. break;
  16523. case ForwardRef:
  16524. workInProgress.type = resolveForwardRefForHotReloading(current.type);
  16525. break;
  16526. }
  16527. }
  16528. return workInProgress;
  16529. } // Used to reuse a Fiber for a second pass.
  16530. function resetWorkInProgress(workInProgress, renderExpirationTime) {
  16531. // This resets the Fiber to what createFiber or createWorkInProgress would
  16532. // have set the values to before during the first pass. Ideally this wouldn't
  16533. // be necessary but unfortunately many code paths reads from the workInProgress
  16534. // when they should be reading from current and writing to workInProgress.
  16535. // We assume pendingProps, index, key, ref, return are still untouched to
  16536. // avoid doing another reconciliation.
  16537. // Reset the effect tag but keep any Placement tags, since that's something
  16538. // that child fiber is setting, not the reconciliation.
  16539. workInProgress.effectTag &= Placement; // The effect list is no longer valid.
  16540. workInProgress.nextEffect = null;
  16541. workInProgress.firstEffect = null;
  16542. workInProgress.lastEffect = null;
  16543. var current = workInProgress.alternate;
  16544. if (current === null) {
  16545. // Reset to createFiber's initial values.
  16546. workInProgress.childExpirationTime = NoWork;
  16547. workInProgress.expirationTime = renderExpirationTime;
  16548. workInProgress.child = null;
  16549. workInProgress.memoizedProps = null;
  16550. workInProgress.memoizedState = null;
  16551. workInProgress.updateQueue = null;
  16552. workInProgress.dependencies = null;
  16553. {
  16554. // Note: We don't reset the actualTime counts. It's useful to accumulate
  16555. // actual time across multiple render passes.
  16556. workInProgress.selfBaseDuration = 0;
  16557. workInProgress.treeBaseDuration = 0;
  16558. }
  16559. } else {
  16560. // Reset to the cloned values that createWorkInProgress would've.
  16561. workInProgress.childExpirationTime = current.childExpirationTime;
  16562. workInProgress.expirationTime = current.expirationTime;
  16563. workInProgress.child = current.child;
  16564. workInProgress.memoizedProps = current.memoizedProps;
  16565. workInProgress.memoizedState = current.memoizedState;
  16566. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  16567. // it cannot be shared with the current fiber.
  16568. var currentDependencies = current.dependencies;
  16569. workInProgress.dependencies =
  16570. currentDependencies === null
  16571. ? null
  16572. : {
  16573. expirationTime: currentDependencies.expirationTime,
  16574. firstContext: currentDependencies.firstContext,
  16575. responders: currentDependencies.responders
  16576. };
  16577. {
  16578. // Note: We don't reset the actualTime counts. It's useful to accumulate
  16579. // actual time across multiple render passes.
  16580. workInProgress.selfBaseDuration = current.selfBaseDuration;
  16581. workInProgress.treeBaseDuration = current.treeBaseDuration;
  16582. }
  16583. }
  16584. return workInProgress;
  16585. }
  16586. function createHostRootFiber(tag) {
  16587. var mode;
  16588. if (tag === ConcurrentRoot) {
  16589. mode = ConcurrentMode | BlockingMode | StrictMode;
  16590. } else if (tag === BlockingRoot) {
  16591. mode = BlockingMode | StrictMode;
  16592. } else {
  16593. mode = NoMode;
  16594. }
  16595. if (isDevToolsPresent) {
  16596. // Always collect profile timings when DevTools are present.
  16597. // This enables DevTools to start capturing timing at any point–
  16598. // Without some nodes in the tree having empty base times.
  16599. mode |= ProfileMode;
  16600. }
  16601. return createFiber(HostRoot, null, null, mode);
  16602. }
  16603. function createFiberFromTypeAndProps(
  16604. type, // React$ElementType
  16605. key,
  16606. pendingProps,
  16607. owner,
  16608. mode,
  16609. expirationTime
  16610. ) {
  16611. var fiber;
  16612. var fiberTag = IndeterminateComponent; // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
  16613. var resolvedType = type;
  16614. if (typeof type === "function") {
  16615. if (shouldConstruct(type)) {
  16616. fiberTag = ClassComponent;
  16617. {
  16618. resolvedType = resolveClassForHotReloading(resolvedType);
  16619. }
  16620. } else {
  16621. {
  16622. resolvedType = resolveFunctionForHotReloading(resolvedType);
  16623. }
  16624. }
  16625. } else if (typeof type === "string") {
  16626. fiberTag = HostComponent;
  16627. } else {
  16628. getTag: switch (type) {
  16629. case REACT_FRAGMENT_TYPE:
  16630. return createFiberFromFragment(
  16631. pendingProps.children,
  16632. mode,
  16633. expirationTime,
  16634. key
  16635. );
  16636. case REACT_CONCURRENT_MODE_TYPE:
  16637. fiberTag = Mode;
  16638. mode |= ConcurrentMode | BlockingMode | StrictMode;
  16639. break;
  16640. case REACT_STRICT_MODE_TYPE:
  16641. fiberTag = Mode;
  16642. mode |= StrictMode;
  16643. break;
  16644. case REACT_PROFILER_TYPE:
  16645. return createFiberFromProfiler(pendingProps, mode, expirationTime, key);
  16646. case REACT_SUSPENSE_TYPE:
  16647. return createFiberFromSuspense(pendingProps, mode, expirationTime, key);
  16648. case REACT_SUSPENSE_LIST_TYPE:
  16649. return createFiberFromSuspenseList(
  16650. pendingProps,
  16651. mode,
  16652. expirationTime,
  16653. key
  16654. );
  16655. default: {
  16656. if (typeof type === "object" && type !== null) {
  16657. switch (type.$$typeof) {
  16658. case REACT_PROVIDER_TYPE:
  16659. fiberTag = ContextProvider;
  16660. break getTag;
  16661. case REACT_CONTEXT_TYPE:
  16662. // This is a consumer
  16663. fiberTag = ContextConsumer;
  16664. break getTag;
  16665. case REACT_FORWARD_REF_TYPE:
  16666. fiberTag = ForwardRef;
  16667. {
  16668. resolvedType = resolveForwardRefForHotReloading(resolvedType);
  16669. }
  16670. break getTag;
  16671. case REACT_MEMO_TYPE:
  16672. fiberTag = MemoComponent;
  16673. break getTag;
  16674. case REACT_LAZY_TYPE:
  16675. fiberTag = LazyComponent;
  16676. resolvedType = null;
  16677. break getTag;
  16678. case REACT_BLOCK_TYPE:
  16679. fiberTag = Block;
  16680. break getTag;
  16681. }
  16682. }
  16683. var info = "";
  16684. {
  16685. if (
  16686. type === undefined ||
  16687. (typeof type === "object" &&
  16688. type !== null &&
  16689. Object.keys(type).length === 0)
  16690. ) {
  16691. info +=
  16692. " You likely forgot to export your component from the file " +
  16693. "it's defined in, or you might have mixed up default and " +
  16694. "named imports.";
  16695. }
  16696. var ownerName = owner ? getComponentName(owner.type) : null;
  16697. if (ownerName) {
  16698. info += "\n\nCheck the render method of `" + ownerName + "`.";
  16699. }
  16700. }
  16701. {
  16702. throw Error(
  16703. "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: " +
  16704. (type == null ? type : typeof type) +
  16705. "." +
  16706. info
  16707. );
  16708. }
  16709. }
  16710. }
  16711. }
  16712. fiber = createFiber(fiberTag, pendingProps, key, mode);
  16713. fiber.elementType = type;
  16714. fiber.type = resolvedType;
  16715. fiber.expirationTime = expirationTime;
  16716. return fiber;
  16717. }
  16718. function createFiberFromElement(element, mode, expirationTime) {
  16719. var owner = null;
  16720. {
  16721. owner = element._owner;
  16722. }
  16723. var type = element.type;
  16724. var key = element.key;
  16725. var pendingProps = element.props;
  16726. var fiber = createFiberFromTypeAndProps(
  16727. type,
  16728. key,
  16729. pendingProps,
  16730. owner,
  16731. mode,
  16732. expirationTime
  16733. );
  16734. {
  16735. fiber._debugSource = element._source;
  16736. fiber._debugOwner = element._owner;
  16737. }
  16738. return fiber;
  16739. }
  16740. function createFiberFromFragment(elements, mode, expirationTime, key) {
  16741. var fiber = createFiber(Fragment, elements, key, mode);
  16742. fiber.expirationTime = expirationTime;
  16743. return fiber;
  16744. }
  16745. function createFiberFromProfiler(pendingProps, mode, expirationTime, key) {
  16746. {
  16747. if (typeof pendingProps.id !== "string") {
  16748. error('Profiler must specify an "id" as a prop');
  16749. }
  16750. }
  16751. var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); // TODO: The Profiler fiber shouldn't have a type. It has a tag.
  16752. fiber.elementType = REACT_PROFILER_TYPE;
  16753. fiber.type = REACT_PROFILER_TYPE;
  16754. fiber.expirationTime = expirationTime;
  16755. {
  16756. fiber.stateNode = {
  16757. effectDuration: 0,
  16758. passiveEffectDuration: 0
  16759. };
  16760. }
  16761. return fiber;
  16762. }
  16763. function createFiberFromSuspense(pendingProps, mode, expirationTime, key) {
  16764. var fiber = createFiber(SuspenseComponent, pendingProps, key, mode); // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
  16765. // This needs to be fixed in getComponentName so that it relies on the tag
  16766. // instead.
  16767. fiber.type = REACT_SUSPENSE_TYPE;
  16768. fiber.elementType = REACT_SUSPENSE_TYPE;
  16769. fiber.expirationTime = expirationTime;
  16770. return fiber;
  16771. }
  16772. function createFiberFromSuspenseList(pendingProps, mode, expirationTime, key) {
  16773. var fiber = createFiber(SuspenseListComponent, pendingProps, key, mode);
  16774. {
  16775. // TODO: The SuspenseListComponent fiber shouldn't have a type. It has a tag.
  16776. // This needs to be fixed in getComponentName so that it relies on the tag
  16777. // instead.
  16778. fiber.type = REACT_SUSPENSE_LIST_TYPE;
  16779. }
  16780. fiber.elementType = REACT_SUSPENSE_LIST_TYPE;
  16781. fiber.expirationTime = expirationTime;
  16782. return fiber;
  16783. }
  16784. function createFiberFromText(content, mode, expirationTime) {
  16785. var fiber = createFiber(HostText, content, null, mode);
  16786. fiber.expirationTime = expirationTime;
  16787. return fiber;
  16788. }
  16789. function createFiberFromPortal(portal, mode, expirationTime) {
  16790. var pendingProps = portal.children !== null ? portal.children : [];
  16791. var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
  16792. fiber.expirationTime = expirationTime;
  16793. fiber.stateNode = {
  16794. containerInfo: portal.containerInfo,
  16795. pendingChildren: null,
  16796. // Used by persistent updates
  16797. implementation: portal.implementation
  16798. };
  16799. return fiber;
  16800. } // Used for stashing WIP properties to replay failed work in DEV.
  16801. function assignFiberPropertiesInDEV(target, source) {
  16802. if (target === null) {
  16803. // This Fiber's initial properties will always be overwritten.
  16804. // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
  16805. target = createFiber(IndeterminateComponent, null, null, NoMode);
  16806. } // This is intentionally written as a list of all properties.
  16807. // We tried to use Object.assign() instead but this is called in
  16808. // the hottest path, and Object.assign() was too slow:
  16809. // https://github.com/facebook/react/issues/12502
  16810. // This code is DEV-only so size is not a concern.
  16811. target.tag = source.tag;
  16812. target.key = source.key;
  16813. target.elementType = source.elementType;
  16814. target.type = source.type;
  16815. target.stateNode = source.stateNode;
  16816. target.return = source.return;
  16817. target.child = source.child;
  16818. target.sibling = source.sibling;
  16819. target.index = source.index;
  16820. target.ref = source.ref;
  16821. target.pendingProps = source.pendingProps;
  16822. target.memoizedProps = source.memoizedProps;
  16823. target.updateQueue = source.updateQueue;
  16824. target.memoizedState = source.memoizedState;
  16825. target.dependencies = source.dependencies;
  16826. target.mode = source.mode;
  16827. target.effectTag = source.effectTag;
  16828. target.nextEffect = source.nextEffect;
  16829. target.firstEffect = source.firstEffect;
  16830. target.lastEffect = source.lastEffect;
  16831. target.expirationTime = source.expirationTime;
  16832. target.childExpirationTime = source.childExpirationTime;
  16833. target.alternate = source.alternate;
  16834. {
  16835. target.actualDuration = source.actualDuration;
  16836. target.actualStartTime = source.actualStartTime;
  16837. target.selfBaseDuration = source.selfBaseDuration;
  16838. target.treeBaseDuration = source.treeBaseDuration;
  16839. }
  16840. {
  16841. target._debugID = source._debugID;
  16842. target._debugIsCurrentlyTiming = source._debugIsCurrentlyTiming;
  16843. }
  16844. target._debugSource = source._debugSource;
  16845. target._debugOwner = source._debugOwner;
  16846. target._debugNeedsRemount = source._debugNeedsRemount;
  16847. target._debugHookTypes = source._debugHookTypes;
  16848. return target;
  16849. }
  16850. function FiberRootNode(containerInfo, tag, hydrate) {
  16851. this.tag = tag;
  16852. this.current = null;
  16853. this.containerInfo = containerInfo;
  16854. this.pendingChildren = null;
  16855. this.pingCache = null;
  16856. this.finishedExpirationTime = NoWork;
  16857. this.finishedWork = null;
  16858. this.timeoutHandle = noTimeout;
  16859. this.context = null;
  16860. this.pendingContext = null;
  16861. this.hydrate = hydrate;
  16862. this.callbackNode = null;
  16863. this.callbackPriority = NoPriority;
  16864. this.firstPendingTime = NoWork;
  16865. this.firstSuspendedTime = NoWork;
  16866. this.lastSuspendedTime = NoWork;
  16867. this.nextKnownPendingLevel = NoWork;
  16868. this.lastPingedTime = NoWork;
  16869. this.lastExpiredTime = NoWork;
  16870. {
  16871. this.interactionThreadID = tracing.unstable_getThreadID();
  16872. this.memoizedInteractions = new Set();
  16873. this.pendingInteractionMap = new Map();
  16874. }
  16875. }
  16876. function createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks) {
  16877. var root = new FiberRootNode(containerInfo, tag, hydrate);
  16878. // stateNode is any.
  16879. var uninitializedFiber = createHostRootFiber(tag);
  16880. root.current = uninitializedFiber;
  16881. uninitializedFiber.stateNode = root;
  16882. initializeUpdateQueue(uninitializedFiber);
  16883. return root;
  16884. }
  16885. function isRootSuspendedAtTime(root, expirationTime) {
  16886. var firstSuspendedTime = root.firstSuspendedTime;
  16887. var lastSuspendedTime = root.lastSuspendedTime;
  16888. return (
  16889. firstSuspendedTime !== NoWork &&
  16890. firstSuspendedTime >= expirationTime &&
  16891. lastSuspendedTime <= expirationTime
  16892. );
  16893. }
  16894. function markRootSuspendedAtTime(root, expirationTime) {
  16895. var firstSuspendedTime = root.firstSuspendedTime;
  16896. var lastSuspendedTime = root.lastSuspendedTime;
  16897. if (firstSuspendedTime < expirationTime) {
  16898. root.firstSuspendedTime = expirationTime;
  16899. }
  16900. if (lastSuspendedTime > expirationTime || firstSuspendedTime === NoWork) {
  16901. root.lastSuspendedTime = expirationTime;
  16902. }
  16903. if (expirationTime <= root.lastPingedTime) {
  16904. root.lastPingedTime = NoWork;
  16905. }
  16906. if (expirationTime <= root.lastExpiredTime) {
  16907. root.lastExpiredTime = NoWork;
  16908. }
  16909. }
  16910. function markRootUpdatedAtTime(root, expirationTime) {
  16911. // Update the range of pending times
  16912. var firstPendingTime = root.firstPendingTime;
  16913. if (expirationTime > firstPendingTime) {
  16914. root.firstPendingTime = expirationTime;
  16915. } // Update the range of suspended times. Treat everything lower priority or
  16916. // equal to this update as unsuspended.
  16917. var firstSuspendedTime = root.firstSuspendedTime;
  16918. if (firstSuspendedTime !== NoWork) {
  16919. if (expirationTime >= firstSuspendedTime) {
  16920. // The entire suspended range is now unsuspended.
  16921. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  16922. } else if (expirationTime >= root.lastSuspendedTime) {
  16923. root.lastSuspendedTime = expirationTime + 1;
  16924. } // This is a pending level. Check if it's higher priority than the next
  16925. // known pending level.
  16926. if (expirationTime > root.nextKnownPendingLevel) {
  16927. root.nextKnownPendingLevel = expirationTime;
  16928. }
  16929. }
  16930. }
  16931. function markRootFinishedAtTime(
  16932. root,
  16933. finishedExpirationTime,
  16934. remainingExpirationTime
  16935. ) {
  16936. // Update the range of pending times
  16937. root.firstPendingTime = remainingExpirationTime; // Update the range of suspended times. Treat everything higher priority or
  16938. // equal to this update as unsuspended.
  16939. if (finishedExpirationTime <= root.lastSuspendedTime) {
  16940. // The entire suspended range is now unsuspended.
  16941. root.firstSuspendedTime = root.lastSuspendedTime = root.nextKnownPendingLevel = NoWork;
  16942. } else if (finishedExpirationTime <= root.firstSuspendedTime) {
  16943. // Part of the suspended range is now unsuspended. Narrow the range to
  16944. // include everything between the unsuspended time (non-inclusive) and the
  16945. // last suspended time.
  16946. root.firstSuspendedTime = finishedExpirationTime - 1;
  16947. }
  16948. if (finishedExpirationTime <= root.lastPingedTime) {
  16949. // Clear the pinged time
  16950. root.lastPingedTime = NoWork;
  16951. }
  16952. if (finishedExpirationTime <= root.lastExpiredTime) {
  16953. // Clear the expired time
  16954. root.lastExpiredTime = NoWork;
  16955. }
  16956. }
  16957. function markRootExpiredAtTime(root, expirationTime) {
  16958. var lastExpiredTime = root.lastExpiredTime;
  16959. if (lastExpiredTime === NoWork || lastExpiredTime > expirationTime) {
  16960. root.lastExpiredTime = expirationTime;
  16961. }
  16962. }
  16963. var didWarnAboutNestedUpdates;
  16964. var didWarnAboutFindNodeInStrictMode;
  16965. {
  16966. didWarnAboutNestedUpdates = false;
  16967. didWarnAboutFindNodeInStrictMode = {};
  16968. }
  16969. function getContextForSubtree(parentComponent) {
  16970. if (!parentComponent) {
  16971. return emptyContextObject;
  16972. }
  16973. var fiber = get(parentComponent);
  16974. var parentContext = findCurrentUnmaskedContext(fiber);
  16975. if (fiber.tag === ClassComponent) {
  16976. var Component = fiber.type;
  16977. if (isContextProvider(Component)) {
  16978. return processChildContext(fiber, Component, parentContext);
  16979. }
  16980. }
  16981. return parentContext;
  16982. }
  16983. function findHostInstanceWithWarning(component, methodName) {
  16984. {
  16985. var fiber = get(component);
  16986. if (fiber === undefined) {
  16987. if (typeof component.render === "function") {
  16988. {
  16989. throw Error("Unable to find node on an unmounted component.");
  16990. }
  16991. } else {
  16992. {
  16993. throw Error(
  16994. "Argument appears to not be a ReactComponent. Keys: " +
  16995. Object.keys(component)
  16996. );
  16997. }
  16998. }
  16999. }
  17000. var hostFiber = findCurrentHostFiber(fiber);
  17001. if (hostFiber === null) {
  17002. return null;
  17003. }
  17004. if (hostFiber.mode & StrictMode) {
  17005. var componentName = getComponentName(fiber.type) || "Component";
  17006. if (!didWarnAboutFindNodeInStrictMode[componentName]) {
  17007. didWarnAboutFindNodeInStrictMode[componentName] = true;
  17008. if (fiber.mode & StrictMode) {
  17009. error(
  17010. "%s is deprecated in StrictMode. " +
  17011. "%s was passed an instance of %s which is inside StrictMode. " +
  17012. "Instead, add a ref directly to the element you want to reference. " +
  17013. "Learn more about using refs safely here: " +
  17014. "https://fb.me/react-strict-mode-find-node%s",
  17015. methodName,
  17016. methodName,
  17017. componentName,
  17018. getStackByFiberInDevAndProd(hostFiber)
  17019. );
  17020. } else {
  17021. error(
  17022. "%s is deprecated in StrictMode. " +
  17023. "%s was passed an instance of %s which renders StrictMode children. " +
  17024. "Instead, add a ref directly to the element you want to reference. " +
  17025. "Learn more about using refs safely here: " +
  17026. "https://fb.me/react-strict-mode-find-node%s",
  17027. methodName,
  17028. methodName,
  17029. componentName,
  17030. getStackByFiberInDevAndProd(hostFiber)
  17031. );
  17032. }
  17033. }
  17034. }
  17035. return hostFiber.stateNode;
  17036. }
  17037. }
  17038. function createContainer(containerInfo, tag, hydrate, hydrationCallbacks) {
  17039. return createFiberRoot(containerInfo, tag, hydrate);
  17040. }
  17041. function updateContainer(element, container, parentComponent, callback) {
  17042. {
  17043. onScheduleRoot(container, element);
  17044. }
  17045. var current$1 = container.current;
  17046. var currentTime = requestCurrentTimeForUpdate();
  17047. {
  17048. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  17049. if ("undefined" !== typeof jest) {
  17050. warnIfUnmockedScheduler(current$1);
  17051. }
  17052. }
  17053. var suspenseConfig = requestCurrentSuspenseConfig();
  17054. var expirationTime = computeExpirationForFiber(
  17055. currentTime,
  17056. current$1,
  17057. suspenseConfig
  17058. );
  17059. var context = getContextForSubtree(parentComponent);
  17060. if (container.context === null) {
  17061. container.context = context;
  17062. } else {
  17063. container.pendingContext = context;
  17064. }
  17065. {
  17066. if (isRendering && current !== null && !didWarnAboutNestedUpdates) {
  17067. didWarnAboutNestedUpdates = true;
  17068. error(
  17069. "Render methods should be a pure function of props and state; " +
  17070. "triggering nested component updates from render is not allowed. " +
  17071. "If necessary, trigger nested updates in componentDidUpdate.\n\n" +
  17072. "Check the render method of %s.",
  17073. getComponentName(current.type) || "Unknown"
  17074. );
  17075. }
  17076. }
  17077. var update = createUpdate(expirationTime, suspenseConfig); // Caution: React DevTools currently depends on this property
  17078. // being called "element".
  17079. update.payload = {
  17080. element: element
  17081. };
  17082. callback = callback === undefined ? null : callback;
  17083. if (callback !== null) {
  17084. {
  17085. if (typeof callback !== "function") {
  17086. error(
  17087. "render(...): Expected the last optional `callback` argument to be a " +
  17088. "function. Instead received: %s.",
  17089. callback
  17090. );
  17091. }
  17092. }
  17093. update.callback = callback;
  17094. }
  17095. enqueueUpdate(current$1, update);
  17096. scheduleWork(current$1, expirationTime);
  17097. return expirationTime;
  17098. }
  17099. function getPublicRootInstance(container) {
  17100. var containerFiber = container.current;
  17101. if (!containerFiber.child) {
  17102. return null;
  17103. }
  17104. switch (containerFiber.child.tag) {
  17105. case HostComponent:
  17106. return getPublicInstance(containerFiber.child.stateNode);
  17107. default:
  17108. return containerFiber.child.stateNode;
  17109. }
  17110. }
  17111. var shouldSuspendImpl = function(fiber) {
  17112. return false;
  17113. };
  17114. function shouldSuspend(fiber) {
  17115. return shouldSuspendImpl(fiber);
  17116. }
  17117. var overrideHookState = null;
  17118. var overrideProps = null;
  17119. var scheduleUpdate = null;
  17120. var setSuspenseHandler = null;
  17121. {
  17122. var copyWithSetImpl = function(obj, path, idx, value) {
  17123. if (idx >= path.length) {
  17124. return value;
  17125. }
  17126. var key = path[idx];
  17127. var updated = Array.isArray(obj) ? obj.slice() : Object.assign({}, obj); // $FlowFixMe number or string is fine here
  17128. updated[key] = copyWithSetImpl(obj[key], path, idx + 1, value);
  17129. return updated;
  17130. };
  17131. var copyWithSet = function(obj, path, value) {
  17132. return copyWithSetImpl(obj, path, 0, value);
  17133. }; // Support DevTools editable values for useState and useReducer.
  17134. overrideHookState = function(fiber, id, path, value) {
  17135. // For now, the "id" of stateful hooks is just the stateful hook index.
  17136. // This may change in the future with e.g. nested hooks.
  17137. var currentHook = fiber.memoizedState;
  17138. while (currentHook !== null && id > 0) {
  17139. currentHook = currentHook.next;
  17140. id--;
  17141. }
  17142. if (currentHook !== null) {
  17143. var newState = copyWithSet(currentHook.memoizedState, path, value);
  17144. currentHook.memoizedState = newState;
  17145. currentHook.baseState = newState; // We aren't actually adding an update to the queue,
  17146. // because there is no update we can add for useReducer hooks that won't trigger an error.
  17147. // (There's no appropriate action type for DevTools overrides.)
  17148. // As a result though, React will see the scheduled update as a noop and bailout.
  17149. // Shallow cloning props works as a workaround for now to bypass the bailout check.
  17150. fiber.memoizedProps = Object.assign({}, fiber.memoizedProps);
  17151. scheduleWork(fiber, Sync);
  17152. }
  17153. }; // Support DevTools props for function components, forwardRef, memo, host components, etc.
  17154. overrideProps = function(fiber, path, value) {
  17155. fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
  17156. if (fiber.alternate) {
  17157. fiber.alternate.pendingProps = fiber.pendingProps;
  17158. }
  17159. scheduleWork(fiber, Sync);
  17160. };
  17161. scheduleUpdate = function(fiber) {
  17162. scheduleWork(fiber, Sync);
  17163. };
  17164. setSuspenseHandler = function(newShouldSuspendImpl) {
  17165. shouldSuspendImpl = newShouldSuspendImpl;
  17166. };
  17167. }
  17168. function injectIntoDevTools(devToolsConfig) {
  17169. var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
  17170. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
  17171. return injectInternals({
  17172. bundleType: devToolsConfig.bundleType,
  17173. version: devToolsConfig.version,
  17174. rendererPackageName: devToolsConfig.rendererPackageName,
  17175. rendererConfig: devToolsConfig.rendererConfig,
  17176. overrideHookState: overrideHookState,
  17177. overrideProps: overrideProps,
  17178. setSuspenseHandler: setSuspenseHandler,
  17179. scheduleUpdate: scheduleUpdate,
  17180. currentDispatcherRef: ReactCurrentDispatcher,
  17181. findHostInstanceByFiber: function(fiber) {
  17182. var hostFiber = findCurrentHostFiber(fiber);
  17183. if (hostFiber === null) {
  17184. return null;
  17185. }
  17186. return hostFiber.stateNode;
  17187. },
  17188. findFiberByHostInstance: function(instance) {
  17189. if (!findFiberByHostInstance) {
  17190. // Might not be implemented by the renderer.
  17191. return null;
  17192. }
  17193. return findFiberByHostInstance(instance);
  17194. },
  17195. // React Refresh
  17196. findHostInstancesForRefresh: findHostInstancesForRefresh,
  17197. scheduleRefresh: scheduleRefresh,
  17198. scheduleRoot: scheduleRoot,
  17199. setRefreshHandler: setRefreshHandler,
  17200. // Enables DevTools to append owner stacks to error messages in DEV mode.
  17201. getCurrentFiber: function() {
  17202. return current;
  17203. }
  17204. });
  17205. }
  17206. var IsSomeRendererActing$1 = ReactSharedInternals.IsSomeRendererActing;
  17207. function createPortal(
  17208. children,
  17209. containerInfo, // TODO: figure out the API for cross-renderer implementation.
  17210. implementation
  17211. ) {
  17212. var key =
  17213. arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  17214. return {
  17215. // This tag allow us to uniquely identify this as a React Portal
  17216. $$typeof: REACT_PORTAL_TYPE,
  17217. key: key == null ? null : "" + key,
  17218. children: children,
  17219. containerInfo: containerInfo,
  17220. implementation: implementation
  17221. };
  17222. }
  17223. // TODO: this is special because it gets imported during build.
  17224. var ReactVersion = "16.13.0";
  17225. var instanceCache = new Map();
  17226. function getInstanceFromTag(tag) {
  17227. return instanceCache.get(tag) || null;
  17228. }
  17229. var emptyObject$1 = {};
  17230. {
  17231. Object.freeze(emptyObject$1);
  17232. }
  17233. var getInspectorDataForViewTag;
  17234. var getInspectorDataForViewAtPoint;
  17235. {
  17236. var traverseOwnerTreeUp = function(hierarchy, instance) {
  17237. if (instance) {
  17238. hierarchy.unshift(instance);
  17239. traverseOwnerTreeUp(hierarchy, instance._debugOwner);
  17240. }
  17241. };
  17242. var getOwnerHierarchy = function(instance) {
  17243. var hierarchy = [];
  17244. traverseOwnerTreeUp(hierarchy, instance);
  17245. return hierarchy;
  17246. };
  17247. var lastNonHostInstance = function(hierarchy) {
  17248. for (var i = hierarchy.length - 1; i > 1; i--) {
  17249. var instance = hierarchy[i];
  17250. if (instance.tag !== HostComponent) {
  17251. return instance;
  17252. }
  17253. }
  17254. return hierarchy[0];
  17255. };
  17256. var getHostProps = function(fiber) {
  17257. var host = findCurrentHostFiber(fiber);
  17258. if (host) {
  17259. return host.memoizedProps || emptyObject$1;
  17260. }
  17261. return emptyObject$1;
  17262. };
  17263. var getHostNode = function(fiber, findNodeHandle) {
  17264. var hostNode; // look for children first for the hostNode
  17265. // as composite fibers do not have a hostNode
  17266. while (fiber) {
  17267. if (fiber.stateNode !== null && fiber.tag === HostComponent) {
  17268. hostNode = findNodeHandle(fiber.stateNode);
  17269. }
  17270. if (hostNode) {
  17271. return hostNode;
  17272. }
  17273. fiber = fiber.child;
  17274. }
  17275. return null;
  17276. };
  17277. var createHierarchy = function(fiberHierarchy) {
  17278. return fiberHierarchy.map(function(fiber) {
  17279. return {
  17280. name: getComponentName(fiber.type),
  17281. getInspectorData: function(findNodeHandle) {
  17282. return {
  17283. props: getHostProps(fiber),
  17284. source: fiber._debugSource,
  17285. measure: function(callback) {
  17286. // If this is Fabric, we'll find a ShadowNode and use that to measure.
  17287. var hostFiber = findCurrentHostFiber(fiber);
  17288. var shadowNode =
  17289. hostFiber != null &&
  17290. hostFiber.stateNode !== null &&
  17291. hostFiber.stateNode.node;
  17292. if (shadowNode) {
  17293. nativeFabricUIManager.measure(shadowNode, callback);
  17294. } else {
  17295. return ReactNativePrivateInterface.UIManager.measure(
  17296. getHostNode(fiber, findNodeHandle),
  17297. callback
  17298. );
  17299. }
  17300. }
  17301. };
  17302. }
  17303. };
  17304. });
  17305. };
  17306. var getInspectorDataForInstance = function(closestInstance) {
  17307. // Handle case where user clicks outside of ReactNative
  17308. if (!closestInstance) {
  17309. return {
  17310. hierarchy: [],
  17311. props: emptyObject$1,
  17312. selectedIndex: null,
  17313. source: null
  17314. };
  17315. }
  17316. var fiber = findCurrentFiberUsingSlowPath(closestInstance);
  17317. var fiberHierarchy = getOwnerHierarchy(fiber);
  17318. var instance = lastNonHostInstance(fiberHierarchy);
  17319. var hierarchy = createHierarchy(fiberHierarchy);
  17320. var props = getHostProps(instance);
  17321. var source = instance._debugSource;
  17322. var selectedIndex = fiberHierarchy.indexOf(instance);
  17323. return {
  17324. hierarchy: hierarchy,
  17325. props: props,
  17326. selectedIndex: selectedIndex,
  17327. source: source
  17328. };
  17329. };
  17330. getInspectorDataForViewTag = function(viewTag) {
  17331. var closestInstance = getInstanceFromTag(viewTag); // Handle case where user clicks outside of ReactNative
  17332. if (!closestInstance) {
  17333. return {
  17334. hierarchy: [],
  17335. props: emptyObject$1,
  17336. selectedIndex: null,
  17337. source: null
  17338. };
  17339. }
  17340. var fiber = findCurrentFiberUsingSlowPath(closestInstance);
  17341. var fiberHierarchy = getOwnerHierarchy(fiber);
  17342. var instance = lastNonHostInstance(fiberHierarchy);
  17343. var hierarchy = createHierarchy(fiberHierarchy);
  17344. var props = getHostProps(instance);
  17345. var source = instance._debugSource;
  17346. var selectedIndex = fiberHierarchy.indexOf(instance);
  17347. return {
  17348. hierarchy: hierarchy,
  17349. props: props,
  17350. selectedIndex: selectedIndex,
  17351. source: source
  17352. };
  17353. };
  17354. getInspectorDataForViewAtPoint = function(
  17355. findNodeHandle,
  17356. inspectedView,
  17357. locationX,
  17358. locationY,
  17359. callback
  17360. ) {
  17361. var closestInstance = null;
  17362. if (inspectedView._internalInstanceHandle != null) {
  17363. // For Fabric we can look up the instance handle directly and measure it.
  17364. nativeFabricUIManager.findNodeAtPoint(
  17365. inspectedView._internalInstanceHandle.stateNode.node,
  17366. locationX,
  17367. locationY,
  17368. function(internalInstanceHandle) {
  17369. if (internalInstanceHandle == null) {
  17370. callback(
  17371. Object.assign(
  17372. {
  17373. pointerY: locationY,
  17374. frame: {
  17375. left: 0,
  17376. top: 0,
  17377. width: 0,
  17378. height: 0
  17379. }
  17380. },
  17381. getInspectorDataForInstance(closestInstance)
  17382. )
  17383. );
  17384. }
  17385. closestInstance =
  17386. internalInstanceHandle.stateNode.canonical._internalInstanceHandle;
  17387. nativeFabricUIManager.measure(
  17388. internalInstanceHandle.stateNode.node,
  17389. function(x, y, width, height, pageX, pageY) {
  17390. callback(
  17391. Object.assign(
  17392. {
  17393. pointerY: locationY,
  17394. frame: {
  17395. left: pageX,
  17396. top: pageY,
  17397. width: width,
  17398. height: height
  17399. }
  17400. },
  17401. getInspectorDataForInstance(closestInstance)
  17402. )
  17403. );
  17404. }
  17405. );
  17406. }
  17407. );
  17408. } else if (inspectedView._internalFiberInstanceHandleDEV != null) {
  17409. // For Paper we fall back to the old strategy using the React tag.
  17410. ReactNativePrivateInterface.UIManager.findSubviewIn(
  17411. findNodeHandle(inspectedView),
  17412. [locationX, locationY],
  17413. function(nativeViewTag, left, top, width, height) {
  17414. var inspectorData = getInspectorDataForInstance(
  17415. getInstanceFromTag(nativeViewTag)
  17416. );
  17417. callback(
  17418. Object.assign({}, inspectorData, {
  17419. pointerY: locationY,
  17420. frame: {
  17421. left: left,
  17422. top: top,
  17423. width: width,
  17424. height: height
  17425. },
  17426. touchedViewTag: nativeViewTag
  17427. })
  17428. );
  17429. }
  17430. );
  17431. } else {
  17432. error(
  17433. "getInspectorDataForViewAtPoint expects to receieve a host component"
  17434. );
  17435. return;
  17436. }
  17437. };
  17438. }
  17439. var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner;
  17440. function findHostInstance_DEPRECATED(componentOrHandle) {
  17441. {
  17442. var owner = ReactCurrentOwner$3.current;
  17443. if (owner !== null && owner.stateNode !== null) {
  17444. if (!owner.stateNode._warnedAboutRefsInRender) {
  17445. error(
  17446. "%s is accessing findNodeHandle inside its render(). " +
  17447. "render() should be a pure function of props and state. It should " +
  17448. "never access something that requires stale data from the previous " +
  17449. "render, such as refs. Move this logic to componentDidMount and " +
  17450. "componentDidUpdate instead.",
  17451. getComponentName(owner.type) || "A component"
  17452. );
  17453. }
  17454. owner.stateNode._warnedAboutRefsInRender = true;
  17455. }
  17456. }
  17457. if (componentOrHandle == null) {
  17458. return null;
  17459. }
  17460. if (componentOrHandle._nativeTag) {
  17461. return componentOrHandle;
  17462. }
  17463. if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) {
  17464. return componentOrHandle.canonical;
  17465. }
  17466. var hostInstance;
  17467. {
  17468. hostInstance = findHostInstanceWithWarning(
  17469. componentOrHandle,
  17470. "findHostInstance_DEPRECATED"
  17471. );
  17472. }
  17473. if (hostInstance == null) {
  17474. return hostInstance;
  17475. }
  17476. if (hostInstance.canonical) {
  17477. // Fabric
  17478. return hostInstance.canonical;
  17479. }
  17480. return hostInstance;
  17481. }
  17482. function findNodeHandle(componentOrHandle) {
  17483. {
  17484. var owner = ReactCurrentOwner$3.current;
  17485. if (owner !== null && owner.stateNode !== null) {
  17486. if (!owner.stateNode._warnedAboutRefsInRender) {
  17487. error(
  17488. "%s is accessing findNodeHandle inside its render(). " +
  17489. "render() should be a pure function of props and state. It should " +
  17490. "never access something that requires stale data from the previous " +
  17491. "render, such as refs. Move this logic to componentDidMount and " +
  17492. "componentDidUpdate instead.",
  17493. getComponentName(owner.type) || "A component"
  17494. );
  17495. }
  17496. owner.stateNode._warnedAboutRefsInRender = true;
  17497. }
  17498. }
  17499. if (componentOrHandle == null) {
  17500. return null;
  17501. }
  17502. if (typeof componentOrHandle === "number") {
  17503. // Already a node handle
  17504. return componentOrHandle;
  17505. }
  17506. if (componentOrHandle._nativeTag) {
  17507. return componentOrHandle._nativeTag;
  17508. }
  17509. if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) {
  17510. return componentOrHandle.canonical._nativeTag;
  17511. }
  17512. var hostInstance;
  17513. {
  17514. hostInstance = findHostInstanceWithWarning(
  17515. componentOrHandle,
  17516. "findNodeHandle"
  17517. );
  17518. }
  17519. if (hostInstance == null) {
  17520. return hostInstance;
  17521. } // TODO: the code is right but the types here are wrong.
  17522. // https://github.com/facebook/react/pull/12863
  17523. if (hostInstance.canonical) {
  17524. // Fabric
  17525. return hostInstance.canonical._nativeTag;
  17526. }
  17527. return hostInstance._nativeTag;
  17528. }
  17529. function dispatchCommand(handle, command, args) {
  17530. if (handle._nativeTag == null) {
  17531. {
  17532. error(
  17533. "dispatchCommand was called with a ref that isn't a " +
  17534. "native component. Use React.forwardRef to get access to the underlying native component"
  17535. );
  17536. }
  17537. return;
  17538. }
  17539. if (handle._internalInstanceHandle) {
  17540. nativeFabricUIManager.dispatchCommand(
  17541. handle._internalInstanceHandle.stateNode.node,
  17542. command,
  17543. args
  17544. );
  17545. } else {
  17546. ReactNativePrivateInterface.UIManager.dispatchViewManagerCommand(
  17547. handle._nativeTag,
  17548. command,
  17549. args
  17550. );
  17551. }
  17552. }
  17553. function render(element, containerTag, callback) {
  17554. var root = roots.get(containerTag);
  17555. if (!root) {
  17556. // TODO (bvaughn): If we decide to keep the wrapper component,
  17557. // We could create a wrapper for containerTag as well to reduce special casing.
  17558. root = createContainer(containerTag, LegacyRoot, false);
  17559. roots.set(containerTag, root);
  17560. }
  17561. updateContainer(element, root, null, callback);
  17562. return getPublicRootInstance(root);
  17563. }
  17564. function unmountComponentAtNode(containerTag) {
  17565. this.stopSurface(containerTag);
  17566. }
  17567. function stopSurface(containerTag) {
  17568. var root = roots.get(containerTag);
  17569. if (root) {
  17570. // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred?
  17571. updateContainer(null, root, null, function() {
  17572. roots.delete(containerTag);
  17573. });
  17574. }
  17575. }
  17576. function createPortal$1(children, containerTag) {
  17577. var key =
  17578. arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  17579. return createPortal(children, containerTag, null, key);
  17580. }
  17581. setBatchingImplementation(batchedUpdates$1);
  17582. var roots = new Map();
  17583. injectIntoDevTools({
  17584. findFiberByHostInstance: getInstanceFromInstance,
  17585. bundleType: 1,
  17586. version: ReactVersion,
  17587. rendererPackageName: "react-native-renderer",
  17588. rendererConfig: {
  17589. getInspectorDataForViewTag: getInspectorDataForViewTag,
  17590. getInspectorDataForViewAtPoint: getInspectorDataForViewAtPoint.bind(
  17591. null,
  17592. findNodeHandle
  17593. )
  17594. }
  17595. });
  17596. exports.createPortal = createPortal$1;
  17597. exports.dispatchCommand = dispatchCommand;
  17598. exports.findHostInstance_DEPRECATED = findHostInstance_DEPRECATED;
  17599. exports.findNodeHandle = findNodeHandle;
  17600. exports.render = render;
  17601. exports.stopSurface = stopSurface;
  17602. exports.unmountComponentAtNode = unmountComponentAtNode;
  17603. })();
  17604. }