react-dom.development.js 918 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292
  1. /** @license React v17.0.2
  2. * react-dom.development.js
  3. *
  4. * Copyright (c) Facebook, Inc. and its affiliates.
  5. *
  6. * This source code is licensed under the MIT license found in the
  7. * LICENSE file in the root directory of this source tree.
  8. */
  9. (function (global, factory) {
  10. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
  11. typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
  12. (global = global || self, factory(global.ReactDOM = {}, global.React));
  13. }(this, (function (exports, React) { 'use strict';
  14. var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
  15. // by calls to these methods by a Babel plugin.
  16. //
  17. // In PROD (or in packages without access to React internals),
  18. // they are left as they are instead.
  19. function warn(format) {
  20. {
  21. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  22. args[_key - 1] = arguments[_key];
  23. }
  24. printWarning('warn', format, args);
  25. }
  26. }
  27. function error(format) {
  28. {
  29. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  30. args[_key2 - 1] = arguments[_key2];
  31. }
  32. printWarning('error', format, args);
  33. }
  34. }
  35. function printWarning(level, format, args) {
  36. // When changing this logic, you might want to also
  37. // update consoleWithStackDev.www.js as well.
  38. {
  39. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  40. var stack = ReactDebugCurrentFrame.getStackAddendum();
  41. if (stack !== '') {
  42. format += '%s';
  43. args = args.concat([stack]);
  44. }
  45. var argsWithFormat = args.map(function (item) {
  46. return '' + item;
  47. }); // Careful: RN currently depends on this prefix
  48. argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
  49. // breaks IE9: https://github.com/facebook/react/issues/13610
  50. // eslint-disable-next-line react-internal/no-production-logging
  51. Function.prototype.apply.call(console[level], console, argsWithFormat);
  52. }
  53. }
  54. if (!React) {
  55. {
  56. throw Error( "ReactDOM was loaded before React. Make sure you load the React package before loading ReactDOM." );
  57. }
  58. }
  59. var FunctionComponent = 0;
  60. var ClassComponent = 1;
  61. var IndeterminateComponent = 2; // Before we know whether it is function or class
  62. var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
  63. var HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
  64. var HostComponent = 5;
  65. var HostText = 6;
  66. var Fragment = 7;
  67. var Mode = 8;
  68. var ContextConsumer = 9;
  69. var ContextProvider = 10;
  70. var ForwardRef = 11;
  71. var Profiler = 12;
  72. var SuspenseComponent = 13;
  73. var MemoComponent = 14;
  74. var SimpleMemoComponent = 15;
  75. var LazyComponent = 16;
  76. var IncompleteClassComponent = 17;
  77. var DehydratedFragment = 18;
  78. var SuspenseListComponent = 19;
  79. var FundamentalComponent = 20;
  80. var ScopeComponent = 21;
  81. var Block = 22;
  82. var OffscreenComponent = 23;
  83. var LegacyHiddenComponent = 24;
  84. // Filter certain DOM attributes (e.g. src, href) if their values are empty strings.
  85. var enableProfilerTimer = true; // Record durations for commit and passive effects phases.
  86. var enableFundamentalAPI = false; // Experimental Scope support.
  87. var enableNewReconciler = false; // Errors that are thrown while unmounting (or after in the case of passive effects)
  88. var warnAboutStringRefs = false;
  89. var allNativeEvents = new Set();
  90. /**
  91. * Mapping from registration name to event name
  92. */
  93. var registrationNameDependencies = {};
  94. /**
  95. * Mapping from lowercase registration names to the properly cased version,
  96. * used to warn in the case of missing event handlers. Available
  97. * only in true.
  98. * @type {Object}
  99. */
  100. var possibleRegistrationNames = {} ; // Trust the developer to only use possibleRegistrationNames in true
  101. function registerTwoPhaseEvent(registrationName, dependencies) {
  102. registerDirectEvent(registrationName, dependencies);
  103. registerDirectEvent(registrationName + 'Capture', dependencies);
  104. }
  105. function registerDirectEvent(registrationName, dependencies) {
  106. {
  107. if (registrationNameDependencies[registrationName]) {
  108. error('EventRegistry: More than one plugin attempted to publish the same ' + 'registration name, `%s`.', registrationName);
  109. }
  110. }
  111. registrationNameDependencies[registrationName] = dependencies;
  112. {
  113. var lowerCasedName = registrationName.toLowerCase();
  114. possibleRegistrationNames[lowerCasedName] = registrationName;
  115. if (registrationName === 'onDoubleClick') {
  116. possibleRegistrationNames.ondblclick = registrationName;
  117. }
  118. }
  119. for (var i = 0; i < dependencies.length; i++) {
  120. allNativeEvents.add(dependencies[i]);
  121. }
  122. }
  123. var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
  124. // A reserved attribute.
  125. // It is handled by React separately and shouldn't be written to the DOM.
  126. var RESERVED = 0; // A simple string attribute.
  127. // Attributes that aren't in the filter are presumed to have this type.
  128. var STRING = 1; // A string attribute that accepts booleans in React. In HTML, these are called
  129. // "enumerated" attributes with "true" and "false" as possible values.
  130. // When true, it should be set to a "true" string.
  131. // When false, it should be set to a "false" string.
  132. var BOOLEANISH_STRING = 2; // A real boolean attribute.
  133. // When true, it should be present (set either to an empty string or its name).
  134. // When false, it should be omitted.
  135. var BOOLEAN = 3; // An attribute that can be used as a flag as well as with a value.
  136. // When true, it should be present (set either to an empty string or its name).
  137. // When false, it should be omitted.
  138. // For any other value, should be present with that value.
  139. var OVERLOADED_BOOLEAN = 4; // An attribute that must be numeric or parse as a numeric.
  140. // When falsy, it should be removed.
  141. var NUMERIC = 5; // An attribute that must be positive numeric or parse as a positive numeric.
  142. // When falsy, it should be removed.
  143. var POSITIVE_NUMERIC = 6;
  144. /* eslint-disable max-len */
  145. var ATTRIBUTE_NAME_START_CHAR = ":A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
  146. /* eslint-enable max-len */
  147. var ATTRIBUTE_NAME_CHAR = ATTRIBUTE_NAME_START_CHAR + "\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
  148. var ROOT_ATTRIBUTE_NAME = 'data-reactroot';
  149. var VALID_ATTRIBUTE_NAME_REGEX = new RegExp('^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$');
  150. var hasOwnProperty = Object.prototype.hasOwnProperty;
  151. var illegalAttributeNameCache = {};
  152. var validatedAttributeNameCache = {};
  153. function isAttributeNameSafe(attributeName) {
  154. if (hasOwnProperty.call(validatedAttributeNameCache, attributeName)) {
  155. return true;
  156. }
  157. if (hasOwnProperty.call(illegalAttributeNameCache, attributeName)) {
  158. return false;
  159. }
  160. if (VALID_ATTRIBUTE_NAME_REGEX.test(attributeName)) {
  161. validatedAttributeNameCache[attributeName] = true;
  162. return true;
  163. }
  164. illegalAttributeNameCache[attributeName] = true;
  165. {
  166. error('Invalid attribute name: `%s`', attributeName);
  167. }
  168. return false;
  169. }
  170. function shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag) {
  171. if (propertyInfo !== null) {
  172. return propertyInfo.type === RESERVED;
  173. }
  174. if (isCustomComponentTag) {
  175. return false;
  176. }
  177. if (name.length > 2 && (name[0] === 'o' || name[0] === 'O') && (name[1] === 'n' || name[1] === 'N')) {
  178. return true;
  179. }
  180. return false;
  181. }
  182. function shouldRemoveAttributeWithWarning(name, value, propertyInfo, isCustomComponentTag) {
  183. if (propertyInfo !== null && propertyInfo.type === RESERVED) {
  184. return false;
  185. }
  186. switch (typeof value) {
  187. case 'function': // $FlowIssue symbol is perfectly valid here
  188. case 'symbol':
  189. // eslint-disable-line
  190. return true;
  191. case 'boolean':
  192. {
  193. if (isCustomComponentTag) {
  194. return false;
  195. }
  196. if (propertyInfo !== null) {
  197. return !propertyInfo.acceptsBooleans;
  198. } else {
  199. var prefix = name.toLowerCase().slice(0, 5);
  200. return prefix !== 'data-' && prefix !== 'aria-';
  201. }
  202. }
  203. default:
  204. return false;
  205. }
  206. }
  207. function shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag) {
  208. if (value === null || typeof value === 'undefined') {
  209. return true;
  210. }
  211. if (shouldRemoveAttributeWithWarning(name, value, propertyInfo, isCustomComponentTag)) {
  212. return true;
  213. }
  214. if (isCustomComponentTag) {
  215. return false;
  216. }
  217. if (propertyInfo !== null) {
  218. switch (propertyInfo.type) {
  219. case BOOLEAN:
  220. return !value;
  221. case OVERLOADED_BOOLEAN:
  222. return value === false;
  223. case NUMERIC:
  224. return isNaN(value);
  225. case POSITIVE_NUMERIC:
  226. return isNaN(value) || value < 1;
  227. }
  228. }
  229. return false;
  230. }
  231. function getPropertyInfo(name) {
  232. return properties.hasOwnProperty(name) ? properties[name] : null;
  233. }
  234. function PropertyInfoRecord(name, type, mustUseProperty, attributeName, attributeNamespace, sanitizeURL, removeEmptyString) {
  235. this.acceptsBooleans = type === BOOLEANISH_STRING || type === BOOLEAN || type === OVERLOADED_BOOLEAN;
  236. this.attributeName = attributeName;
  237. this.attributeNamespace = attributeNamespace;
  238. this.mustUseProperty = mustUseProperty;
  239. this.propertyName = name;
  240. this.type = type;
  241. this.sanitizeURL = sanitizeURL;
  242. this.removeEmptyString = removeEmptyString;
  243. } // When adding attributes to this list, be sure to also add them to
  244. // the `possibleStandardNames` module to ensure casing and incorrect
  245. // name warnings.
  246. var properties = {}; // These props are reserved by React. They shouldn't be written to the DOM.
  247. var reservedProps = ['children', 'dangerouslySetInnerHTML', // TODO: This prevents the assignment of defaultValue to regular
  248. // elements (not just inputs). Now that ReactDOMInput assigns to the
  249. // defaultValue property -- do we need this?
  250. 'defaultValue', 'defaultChecked', 'innerHTML', 'suppressContentEditableWarning', 'suppressHydrationWarning', 'style'];
  251. reservedProps.forEach(function (name) {
  252. properties[name] = new PropertyInfoRecord(name, RESERVED, false, // mustUseProperty
  253. name, // attributeName
  254. null, // attributeNamespace
  255. false, // sanitizeURL
  256. false);
  257. }); // A few React string attributes have a different name.
  258. // This is a mapping from React prop names to the attribute names.
  259. [['acceptCharset', 'accept-charset'], ['className', 'class'], ['htmlFor', 'for'], ['httpEquiv', 'http-equiv']].forEach(function (_ref) {
  260. var name = _ref[0],
  261. attributeName = _ref[1];
  262. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  263. attributeName, // attributeName
  264. null, // attributeNamespace
  265. false, // sanitizeURL
  266. false);
  267. }); // These are "enumerated" HTML attributes that accept "true" and "false".
  268. // In React, we let users pass `true` and `false` even though technically
  269. // these aren't boolean attributes (they are coerced to strings).
  270. ['contentEditable', 'draggable', 'spellCheck', 'value'].forEach(function (name) {
  271. properties[name] = new PropertyInfoRecord(name, BOOLEANISH_STRING, false, // mustUseProperty
  272. name.toLowerCase(), // attributeName
  273. null, // attributeNamespace
  274. false, // sanitizeURL
  275. false);
  276. }); // These are "enumerated" SVG attributes that accept "true" and "false".
  277. // In React, we let users pass `true` and `false` even though technically
  278. // these aren't boolean attributes (they are coerced to strings).
  279. // Since these are SVG attributes, their attribute names are case-sensitive.
  280. ['autoReverse', 'externalResourcesRequired', 'focusable', 'preserveAlpha'].forEach(function (name) {
  281. properties[name] = new PropertyInfoRecord(name, BOOLEANISH_STRING, false, // mustUseProperty
  282. name, // attributeName
  283. null, // attributeNamespace
  284. false, // sanitizeURL
  285. false);
  286. }); // These are HTML boolean attributes.
  287. ['allowFullScreen', 'async', // Note: there is a special case that prevents it from being written to the DOM
  288. // on the client side because the browsers are inconsistent. Instead we call focus().
  289. 'autoFocus', 'autoPlay', 'controls', 'default', 'defer', 'disabled', 'disablePictureInPicture', 'disableRemotePlayback', 'formNoValidate', 'hidden', 'loop', 'noModule', 'noValidate', 'open', 'playsInline', 'readOnly', 'required', 'reversed', 'scoped', 'seamless', // Microdata
  290. 'itemScope'].forEach(function (name) {
  291. properties[name] = new PropertyInfoRecord(name, BOOLEAN, false, // mustUseProperty
  292. name.toLowerCase(), // attributeName
  293. null, // attributeNamespace
  294. false, // sanitizeURL
  295. false);
  296. }); // These are the few React props that we set as DOM properties
  297. // rather than attributes. These are all booleans.
  298. ['checked', // Note: `option.selected` is not updated if `select.multiple` is
  299. // disabled with `removeAttribute`. We have special logic for handling this.
  300. 'multiple', 'muted', 'selected' // NOTE: if you add a camelCased prop to this list,
  301. // you'll need to set attributeName to name.toLowerCase()
  302. // instead in the assignment below.
  303. ].forEach(function (name) {
  304. properties[name] = new PropertyInfoRecord(name, BOOLEAN, true, // mustUseProperty
  305. name, // attributeName
  306. null, // attributeNamespace
  307. false, // sanitizeURL
  308. false);
  309. }); // These are HTML attributes that are "overloaded booleans": they behave like
  310. // booleans, but can also accept a string value.
  311. ['capture', 'download' // NOTE: if you add a camelCased prop to this list,
  312. // you'll need to set attributeName to name.toLowerCase()
  313. // instead in the assignment below.
  314. ].forEach(function (name) {
  315. properties[name] = new PropertyInfoRecord(name, OVERLOADED_BOOLEAN, false, // mustUseProperty
  316. name, // attributeName
  317. null, // attributeNamespace
  318. false, // sanitizeURL
  319. false);
  320. }); // These are HTML attributes that must be positive numbers.
  321. ['cols', 'rows', 'size', 'span' // NOTE: if you add a camelCased prop to this list,
  322. // you'll need to set attributeName to name.toLowerCase()
  323. // instead in the assignment below.
  324. ].forEach(function (name) {
  325. properties[name] = new PropertyInfoRecord(name, POSITIVE_NUMERIC, false, // mustUseProperty
  326. name, // attributeName
  327. null, // attributeNamespace
  328. false, // sanitizeURL
  329. false);
  330. }); // These are HTML attributes that must be numbers.
  331. ['rowSpan', 'start'].forEach(function (name) {
  332. properties[name] = new PropertyInfoRecord(name, NUMERIC, false, // mustUseProperty
  333. name.toLowerCase(), // attributeName
  334. null, // attributeNamespace
  335. false, // sanitizeURL
  336. false);
  337. });
  338. var CAMELIZE = /[\-\:]([a-z])/g;
  339. var capitalize = function (token) {
  340. return token[1].toUpperCase();
  341. }; // This is a list of all SVG attributes that need special casing, namespacing,
  342. // or boolean value assignment. Regular attributes that just accept strings
  343. // and have the same names are omitted, just like in the HTML attribute filter.
  344. // Some of these attributes can be hard to find. This list was created by
  345. // scraping the MDN documentation.
  346. ['accent-height', 'alignment-baseline', 'arabic-form', 'baseline-shift', 'cap-height', 'clip-path', 'clip-rule', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'dominant-baseline', 'enable-background', 'fill-opacity', 'fill-rule', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'glyph-name', 'glyph-orientation-horizontal', 'glyph-orientation-vertical', 'horiz-adv-x', 'horiz-origin-x', 'image-rendering', 'letter-spacing', 'lighting-color', 'marker-end', 'marker-mid', 'marker-start', 'overline-position', 'overline-thickness', 'paint-order', 'panose-1', 'pointer-events', 'rendering-intent', 'shape-rendering', 'stop-color', 'stop-opacity', 'strikethrough-position', 'strikethrough-thickness', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-decoration', 'text-rendering', 'underline-position', 'underline-thickness', 'unicode-bidi', 'unicode-range', 'units-per-em', 'v-alphabetic', 'v-hanging', 'v-ideographic', 'v-mathematical', 'vector-effect', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'word-spacing', 'writing-mode', 'xmlns:xlink', 'x-height' // NOTE: if you add a camelCased prop to this list,
  347. // you'll need to set attributeName to name.toLowerCase()
  348. // instead in the assignment below.
  349. ].forEach(function (attributeName) {
  350. var name = attributeName.replace(CAMELIZE, capitalize);
  351. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  352. attributeName, null, // attributeNamespace
  353. false, // sanitizeURL
  354. false);
  355. }); // String SVG attributes with the xlink namespace.
  356. ['xlink:actuate', 'xlink:arcrole', 'xlink:role', 'xlink:show', 'xlink:title', 'xlink:type' // NOTE: if you add a camelCased prop to this list,
  357. // you'll need to set attributeName to name.toLowerCase()
  358. // instead in the assignment below.
  359. ].forEach(function (attributeName) {
  360. var name = attributeName.replace(CAMELIZE, capitalize);
  361. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  362. attributeName, 'http://www.w3.org/1999/xlink', false, // sanitizeURL
  363. false);
  364. }); // String SVG attributes with the xml namespace.
  365. ['xml:base', 'xml:lang', 'xml:space' // NOTE: if you add a camelCased prop to this list,
  366. // you'll need to set attributeName to name.toLowerCase()
  367. // instead in the assignment below.
  368. ].forEach(function (attributeName) {
  369. var name = attributeName.replace(CAMELIZE, capitalize);
  370. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  371. attributeName, 'http://www.w3.org/XML/1998/namespace', false, // sanitizeURL
  372. false);
  373. }); // These attribute exists both in HTML and SVG.
  374. // The attribute name is case-sensitive in SVG so we can't just use
  375. // the React name like we do for attributes that exist only in HTML.
  376. ['tabIndex', 'crossOrigin'].forEach(function (attributeName) {
  377. properties[attributeName] = new PropertyInfoRecord(attributeName, STRING, false, // mustUseProperty
  378. attributeName.toLowerCase(), // attributeName
  379. null, // attributeNamespace
  380. false, // sanitizeURL
  381. false);
  382. }); // These attributes accept URLs. These must not allow javascript: URLS.
  383. // These will also need to accept Trusted Types object in the future.
  384. var xlinkHref = 'xlinkHref';
  385. properties[xlinkHref] = new PropertyInfoRecord('xlinkHref', STRING, false, // mustUseProperty
  386. 'xlink:href', 'http://www.w3.org/1999/xlink', true, // sanitizeURL
  387. false);
  388. ['src', 'href', 'action', 'formAction'].forEach(function (attributeName) {
  389. properties[attributeName] = new PropertyInfoRecord(attributeName, STRING, false, // mustUseProperty
  390. attributeName.toLowerCase(), // attributeName
  391. null, // attributeNamespace
  392. true, // sanitizeURL
  393. true);
  394. });
  395. // and any newline or tab are filtered out as if they're not part of the URL.
  396. // https://url.spec.whatwg.org/#url-parsing
  397. // Tab or newline are defined as \r\n\t:
  398. // https://infra.spec.whatwg.org/#ascii-tab-or-newline
  399. // A C0 control is a code point in the range \u0000 NULL to \u001F
  400. // INFORMATION SEPARATOR ONE, inclusive:
  401. // https://infra.spec.whatwg.org/#c0-control-or-space
  402. /* eslint-disable max-len */
  403. var isJavaScriptProtocol = /^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*\:/i;
  404. var didWarn = false;
  405. function sanitizeURL(url) {
  406. {
  407. if (!didWarn && isJavaScriptProtocol.test(url)) {
  408. didWarn = true;
  409. error('A future version of React will block javascript: URLs as a security precaution. ' + 'Use event handlers instead if you can. If you need to generate unsafe HTML try ' + 'using dangerouslySetInnerHTML instead. React was passed %s.', JSON.stringify(url));
  410. }
  411. }
  412. }
  413. /**
  414. * Get the value for a property on a node. Only used in DEV for SSR validation.
  415. * The "expected" argument is used as a hint of what the expected value is.
  416. * Some properties have multiple equivalent values.
  417. */
  418. function getValueForProperty(node, name, expected, propertyInfo) {
  419. {
  420. if (propertyInfo.mustUseProperty) {
  421. var propertyName = propertyInfo.propertyName;
  422. return node[propertyName];
  423. } else {
  424. if ( propertyInfo.sanitizeURL) {
  425. // If we haven't fully disabled javascript: URLs, and if
  426. // the hydration is successful of a javascript: URL, we
  427. // still want to warn on the client.
  428. sanitizeURL('' + expected);
  429. }
  430. var attributeName = propertyInfo.attributeName;
  431. var stringValue = null;
  432. if (propertyInfo.type === OVERLOADED_BOOLEAN) {
  433. if (node.hasAttribute(attributeName)) {
  434. var value = node.getAttribute(attributeName);
  435. if (value === '') {
  436. return true;
  437. }
  438. if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
  439. return value;
  440. }
  441. if (value === '' + expected) {
  442. return expected;
  443. }
  444. return value;
  445. }
  446. } else if (node.hasAttribute(attributeName)) {
  447. if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
  448. // We had an attribute but shouldn't have had one, so read it
  449. // for the error message.
  450. return node.getAttribute(attributeName);
  451. }
  452. if (propertyInfo.type === BOOLEAN) {
  453. // If this was a boolean, it doesn't matter what the value is
  454. // the fact that we have it is the same as the expected.
  455. return expected;
  456. } // Even if this property uses a namespace we use getAttribute
  457. // because we assume its namespaced name is the same as our config.
  458. // To use getAttributeNS we need the local name which we don't have
  459. // in our config atm.
  460. stringValue = node.getAttribute(attributeName);
  461. }
  462. if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
  463. return stringValue === null ? expected : stringValue;
  464. } else if (stringValue === '' + expected) {
  465. return expected;
  466. } else {
  467. return stringValue;
  468. }
  469. }
  470. }
  471. }
  472. /**
  473. * Get the value for a attribute on a node. Only used in DEV for SSR validation.
  474. * The third argument is used as a hint of what the expected value is. Some
  475. * attributes have multiple equivalent values.
  476. */
  477. function getValueForAttribute(node, name, expected) {
  478. {
  479. if (!isAttributeNameSafe(name)) {
  480. return;
  481. } // If the object is an opaque reference ID, it's expected that
  482. // the next prop is different than the server value, so just return
  483. // expected
  484. if (isOpaqueHydratingObject(expected)) {
  485. return expected;
  486. }
  487. if (!node.hasAttribute(name)) {
  488. return expected === undefined ? undefined : null;
  489. }
  490. var value = node.getAttribute(name);
  491. if (value === '' + expected) {
  492. return expected;
  493. }
  494. return value;
  495. }
  496. }
  497. /**
  498. * Sets the value for a property on a node.
  499. *
  500. * @param {DOMElement} node
  501. * @param {string} name
  502. * @param {*} value
  503. */
  504. function setValueForProperty(node, name, value, isCustomComponentTag) {
  505. var propertyInfo = getPropertyInfo(name);
  506. if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) {
  507. return;
  508. }
  509. if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) {
  510. value = null;
  511. } // If the prop isn't in the special list, treat it as a simple attribute.
  512. if (isCustomComponentTag || propertyInfo === null) {
  513. if (isAttributeNameSafe(name)) {
  514. var _attributeName = name;
  515. if (value === null) {
  516. node.removeAttribute(_attributeName);
  517. } else {
  518. node.setAttribute(_attributeName, '' + value);
  519. }
  520. }
  521. return;
  522. }
  523. var mustUseProperty = propertyInfo.mustUseProperty;
  524. if (mustUseProperty) {
  525. var propertyName = propertyInfo.propertyName;
  526. if (value === null) {
  527. var type = propertyInfo.type;
  528. node[propertyName] = type === BOOLEAN ? false : '';
  529. } else {
  530. // Contrary to `setAttribute`, object properties are properly
  531. // `toString`ed by IE8/9.
  532. node[propertyName] = value;
  533. }
  534. return;
  535. } // The rest are treated as attributes with special cases.
  536. var attributeName = propertyInfo.attributeName,
  537. attributeNamespace = propertyInfo.attributeNamespace;
  538. if (value === null) {
  539. node.removeAttribute(attributeName);
  540. } else {
  541. var _type = propertyInfo.type;
  542. var attributeValue;
  543. if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) {
  544. // If attribute type is boolean, we know for sure it won't be an execution sink
  545. // and we won't require Trusted Type here.
  546. attributeValue = '';
  547. } else {
  548. // `setAttribute` with objects becomes only `[object]` in IE8/9,
  549. // ('' + value) makes it output the correct toString()-value.
  550. {
  551. attributeValue = '' + value;
  552. }
  553. if (propertyInfo.sanitizeURL) {
  554. sanitizeURL(attributeValue.toString());
  555. }
  556. }
  557. if (attributeNamespace) {
  558. node.setAttributeNS(attributeNamespace, attributeName, attributeValue);
  559. } else {
  560. node.setAttribute(attributeName, attributeValue);
  561. }
  562. }
  563. }
  564. var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
  565. var _assign = ReactInternals.assign;
  566. // ATTENTION
  567. // When adding new symbols to this file,
  568. // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
  569. // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
  570. // nor polyfill, then a plain number is used for performance.
  571. var REACT_ELEMENT_TYPE = 0xeac7;
  572. var REACT_PORTAL_TYPE = 0xeaca;
  573. var REACT_FRAGMENT_TYPE = 0xeacb;
  574. var REACT_STRICT_MODE_TYPE = 0xeacc;
  575. var REACT_PROFILER_TYPE = 0xead2;
  576. var REACT_PROVIDER_TYPE = 0xeacd;
  577. var REACT_CONTEXT_TYPE = 0xeace;
  578. var REACT_FORWARD_REF_TYPE = 0xead0;
  579. var REACT_SUSPENSE_TYPE = 0xead1;
  580. var REACT_SUSPENSE_LIST_TYPE = 0xead8;
  581. var REACT_MEMO_TYPE = 0xead3;
  582. var REACT_LAZY_TYPE = 0xead4;
  583. var REACT_BLOCK_TYPE = 0xead9;
  584. var REACT_SERVER_BLOCK_TYPE = 0xeada;
  585. var REACT_FUNDAMENTAL_TYPE = 0xead5;
  586. var REACT_SCOPE_TYPE = 0xead7;
  587. var REACT_OPAQUE_ID_TYPE = 0xeae0;
  588. var REACT_DEBUG_TRACING_MODE_TYPE = 0xeae1;
  589. var REACT_OFFSCREEN_TYPE = 0xeae2;
  590. var REACT_LEGACY_HIDDEN_TYPE = 0xeae3;
  591. if (typeof Symbol === 'function' && Symbol.for) {
  592. var symbolFor = Symbol.for;
  593. REACT_ELEMENT_TYPE = symbolFor('react.element');
  594. REACT_PORTAL_TYPE = symbolFor('react.portal');
  595. REACT_FRAGMENT_TYPE = symbolFor('react.fragment');
  596. REACT_STRICT_MODE_TYPE = symbolFor('react.strict_mode');
  597. REACT_PROFILER_TYPE = symbolFor('react.profiler');
  598. REACT_PROVIDER_TYPE = symbolFor('react.provider');
  599. REACT_CONTEXT_TYPE = symbolFor('react.context');
  600. REACT_FORWARD_REF_TYPE = symbolFor('react.forward_ref');
  601. REACT_SUSPENSE_TYPE = symbolFor('react.suspense');
  602. REACT_SUSPENSE_LIST_TYPE = symbolFor('react.suspense_list');
  603. REACT_MEMO_TYPE = symbolFor('react.memo');
  604. REACT_LAZY_TYPE = symbolFor('react.lazy');
  605. REACT_BLOCK_TYPE = symbolFor('react.block');
  606. REACT_SERVER_BLOCK_TYPE = symbolFor('react.server.block');
  607. REACT_FUNDAMENTAL_TYPE = symbolFor('react.fundamental');
  608. REACT_SCOPE_TYPE = symbolFor('react.scope');
  609. REACT_OPAQUE_ID_TYPE = symbolFor('react.opaque.id');
  610. REACT_DEBUG_TRACING_MODE_TYPE = symbolFor('react.debug_trace_mode');
  611. REACT_OFFSCREEN_TYPE = symbolFor('react.offscreen');
  612. REACT_LEGACY_HIDDEN_TYPE = symbolFor('react.legacy_hidden');
  613. }
  614. var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  615. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  616. function getIteratorFn(maybeIterable) {
  617. if (maybeIterable === null || typeof maybeIterable !== 'object') {
  618. return null;
  619. }
  620. var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
  621. if (typeof maybeIterator === 'function') {
  622. return maybeIterator;
  623. }
  624. return null;
  625. }
  626. // Helpers to patch console.logs to avoid logging during side-effect free
  627. // replaying on render function. This currently only patches the object
  628. // lazily which won't cover if the log function was extracted eagerly.
  629. // We could also eagerly patch the method.
  630. var disabledDepth = 0;
  631. var prevLog;
  632. var prevInfo;
  633. var prevWarn;
  634. var prevError;
  635. var prevGroup;
  636. var prevGroupCollapsed;
  637. var prevGroupEnd;
  638. function disabledLog() {}
  639. disabledLog.__reactDisabledLog = true;
  640. function disableLogs() {
  641. {
  642. if (disabledDepth === 0) {
  643. /* eslint-disable react-internal/no-production-logging */
  644. prevLog = console.log;
  645. prevInfo = console.info;
  646. prevWarn = console.warn;
  647. prevError = console.error;
  648. prevGroup = console.group;
  649. prevGroupCollapsed = console.groupCollapsed;
  650. prevGroupEnd = console.groupEnd; // https://github.com/facebook/react/issues/19099
  651. var props = {
  652. configurable: true,
  653. enumerable: true,
  654. value: disabledLog,
  655. writable: true
  656. }; // $FlowFixMe Flow thinks console is immutable.
  657. Object.defineProperties(console, {
  658. info: props,
  659. log: props,
  660. warn: props,
  661. error: props,
  662. group: props,
  663. groupCollapsed: props,
  664. groupEnd: props
  665. });
  666. /* eslint-enable react-internal/no-production-logging */
  667. }
  668. disabledDepth++;
  669. }
  670. }
  671. function reenableLogs() {
  672. {
  673. disabledDepth--;
  674. if (disabledDepth === 0) {
  675. /* eslint-disable react-internal/no-production-logging */
  676. var props = {
  677. configurable: true,
  678. enumerable: true,
  679. writable: true
  680. }; // $FlowFixMe Flow thinks console is immutable.
  681. Object.defineProperties(console, {
  682. log: _assign({}, props, {
  683. value: prevLog
  684. }),
  685. info: _assign({}, props, {
  686. value: prevInfo
  687. }),
  688. warn: _assign({}, props, {
  689. value: prevWarn
  690. }),
  691. error: _assign({}, props, {
  692. value: prevError
  693. }),
  694. group: _assign({}, props, {
  695. value: prevGroup
  696. }),
  697. groupCollapsed: _assign({}, props, {
  698. value: prevGroupCollapsed
  699. }),
  700. groupEnd: _assign({}, props, {
  701. value: prevGroupEnd
  702. })
  703. });
  704. /* eslint-enable react-internal/no-production-logging */
  705. }
  706. if (disabledDepth < 0) {
  707. error('disabledDepth fell below zero. ' + 'This is a bug in React. Please file an issue.');
  708. }
  709. }
  710. }
  711. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
  712. var prefix;
  713. function describeBuiltInComponentFrame(name, source, ownerFn) {
  714. {
  715. if (prefix === undefined) {
  716. // Extract the VM specific prefix used by each line.
  717. try {
  718. throw Error();
  719. } catch (x) {
  720. var match = x.stack.trim().match(/\n( *(at )?)/);
  721. prefix = match && match[1] || '';
  722. }
  723. } // We use the prefix to ensure our stacks line up with native stack frames.
  724. return '\n' + prefix + name;
  725. }
  726. }
  727. var reentry = false;
  728. var componentFrameCache;
  729. {
  730. var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
  731. componentFrameCache = new PossiblyWeakMap();
  732. }
  733. function describeNativeComponentFrame(fn, construct) {
  734. // If something asked for a stack inside a fake render, it should get ignored.
  735. if (!fn || reentry) {
  736. return '';
  737. }
  738. {
  739. var frame = componentFrameCache.get(fn);
  740. if (frame !== undefined) {
  741. return frame;
  742. }
  743. }
  744. var control;
  745. reentry = true;
  746. var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe It does accept undefined.
  747. Error.prepareStackTrace = undefined;
  748. var previousDispatcher;
  749. {
  750. previousDispatcher = ReactCurrentDispatcher.current; // Set the dispatcher in DEV because this might be call in the render function
  751. // for warnings.
  752. ReactCurrentDispatcher.current = null;
  753. disableLogs();
  754. }
  755. try {
  756. // This should throw.
  757. if (construct) {
  758. // Something should be setting the props in the constructor.
  759. var Fake = function () {
  760. throw Error();
  761. }; // $FlowFixMe
  762. Object.defineProperty(Fake.prototype, 'props', {
  763. set: function () {
  764. // We use a throwing setter instead of frozen or non-writable props
  765. // because that won't throw in a non-strict mode function.
  766. throw Error();
  767. }
  768. });
  769. if (typeof Reflect === 'object' && Reflect.construct) {
  770. // We construct a different control for this case to include any extra
  771. // frames added by the construct call.
  772. try {
  773. Reflect.construct(Fake, []);
  774. } catch (x) {
  775. control = x;
  776. }
  777. Reflect.construct(fn, [], Fake);
  778. } else {
  779. try {
  780. Fake.call();
  781. } catch (x) {
  782. control = x;
  783. }
  784. fn.call(Fake.prototype);
  785. }
  786. } else {
  787. try {
  788. throw Error();
  789. } catch (x) {
  790. control = x;
  791. }
  792. fn();
  793. }
  794. } catch (sample) {
  795. // This is inlined manually because closure doesn't do it for us.
  796. if (sample && control && typeof sample.stack === 'string') {
  797. // This extracts the first frame from the sample that isn't also in the control.
  798. // Skipping one frame that we assume is the frame that calls the two.
  799. var sampleLines = sample.stack.split('\n');
  800. var controlLines = control.stack.split('\n');
  801. var s = sampleLines.length - 1;
  802. var c = controlLines.length - 1;
  803. while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) {
  804. // We expect at least one stack frame to be shared.
  805. // Typically this will be the root most one. However, stack frames may be
  806. // cut off due to maximum stack limits. In this case, one maybe cut off
  807. // earlier than the other. We assume that the sample is longer or the same
  808. // and there for cut off earlier. So we should find the root most frame in
  809. // the sample somewhere in the control.
  810. c--;
  811. }
  812. for (; s >= 1 && c >= 0; s--, c--) {
  813. // Next we find the first one that isn't the same which should be the
  814. // frame that called our sample function and the control.
  815. if (sampleLines[s] !== controlLines[c]) {
  816. // In V8, the first line is describing the message but other VMs don't.
  817. // If we're about to return the first line, and the control is also on the same
  818. // line, that's a pretty good indicator that our sample threw at same line as
  819. // the control. I.e. before we entered the sample frame. So we ignore this result.
  820. // This can happen if you passed a class to function component, or non-function.
  821. if (s !== 1 || c !== 1) {
  822. do {
  823. s--;
  824. c--; // We may still have similar intermediate frames from the construct call.
  825. // The next one that isn't the same should be our match though.
  826. if (c < 0 || sampleLines[s] !== controlLines[c]) {
  827. // V8 adds a "new" prefix for native classes. Let's remove it to make it prettier.
  828. var _frame = '\n' + sampleLines[s].replace(' at new ', ' at ');
  829. {
  830. if (typeof fn === 'function') {
  831. componentFrameCache.set(fn, _frame);
  832. }
  833. } // Return the line we found.
  834. return _frame;
  835. }
  836. } while (s >= 1 && c >= 0);
  837. }
  838. break;
  839. }
  840. }
  841. }
  842. } finally {
  843. reentry = false;
  844. {
  845. ReactCurrentDispatcher.current = previousDispatcher;
  846. reenableLogs();
  847. }
  848. Error.prepareStackTrace = previousPrepareStackTrace;
  849. } // Fallback to just using the name if we couldn't make it throw.
  850. var name = fn ? fn.displayName || fn.name : '';
  851. var syntheticFrame = name ? describeBuiltInComponentFrame(name) : '';
  852. {
  853. if (typeof fn === 'function') {
  854. componentFrameCache.set(fn, syntheticFrame);
  855. }
  856. }
  857. return syntheticFrame;
  858. }
  859. function describeClassComponentFrame(ctor, source, ownerFn) {
  860. {
  861. return describeNativeComponentFrame(ctor, true);
  862. }
  863. }
  864. function describeFunctionComponentFrame(fn, source, ownerFn) {
  865. {
  866. return describeNativeComponentFrame(fn, false);
  867. }
  868. }
  869. function shouldConstruct(Component) {
  870. var prototype = Component.prototype;
  871. return !!(prototype && prototype.isReactComponent);
  872. }
  873. function describeUnknownElementTypeFrameInDEV(type, source, ownerFn) {
  874. if (type == null) {
  875. return '';
  876. }
  877. if (typeof type === 'function') {
  878. {
  879. return describeNativeComponentFrame(type, shouldConstruct(type));
  880. }
  881. }
  882. if (typeof type === 'string') {
  883. return describeBuiltInComponentFrame(type);
  884. }
  885. switch (type) {
  886. case REACT_SUSPENSE_TYPE:
  887. return describeBuiltInComponentFrame('Suspense');
  888. case REACT_SUSPENSE_LIST_TYPE:
  889. return describeBuiltInComponentFrame('SuspenseList');
  890. }
  891. if (typeof type === 'object') {
  892. switch (type.$$typeof) {
  893. case REACT_FORWARD_REF_TYPE:
  894. return describeFunctionComponentFrame(type.render);
  895. case REACT_MEMO_TYPE:
  896. // Memo may contain any component type so we recursively resolve it.
  897. return describeUnknownElementTypeFrameInDEV(type.type, source, ownerFn);
  898. case REACT_BLOCK_TYPE:
  899. return describeFunctionComponentFrame(type._render);
  900. case REACT_LAZY_TYPE:
  901. {
  902. var lazyComponent = type;
  903. var payload = lazyComponent._payload;
  904. var init = lazyComponent._init;
  905. try {
  906. // Lazy may contain any component type so we recursively resolve it.
  907. return describeUnknownElementTypeFrameInDEV(init(payload), source, ownerFn);
  908. } catch (x) {}
  909. }
  910. }
  911. }
  912. return '';
  913. }
  914. function describeFiber(fiber) {
  915. var owner = fiber._debugOwner ? fiber._debugOwner.type : null ;
  916. var source = fiber._debugSource ;
  917. switch (fiber.tag) {
  918. case HostComponent:
  919. return describeBuiltInComponentFrame(fiber.type);
  920. case LazyComponent:
  921. return describeBuiltInComponentFrame('Lazy');
  922. case SuspenseComponent:
  923. return describeBuiltInComponentFrame('Suspense');
  924. case SuspenseListComponent:
  925. return describeBuiltInComponentFrame('SuspenseList');
  926. case FunctionComponent:
  927. case IndeterminateComponent:
  928. case SimpleMemoComponent:
  929. return describeFunctionComponentFrame(fiber.type);
  930. case ForwardRef:
  931. return describeFunctionComponentFrame(fiber.type.render);
  932. case Block:
  933. return describeFunctionComponentFrame(fiber.type._render);
  934. case ClassComponent:
  935. return describeClassComponentFrame(fiber.type);
  936. default:
  937. return '';
  938. }
  939. }
  940. function getStackByFiberInDevAndProd(workInProgress) {
  941. try {
  942. var info = '';
  943. var node = workInProgress;
  944. do {
  945. info += describeFiber(node);
  946. node = node.return;
  947. } while (node);
  948. return info;
  949. } catch (x) {
  950. return '\nError generating stack: ' + x.message + '\n' + x.stack;
  951. }
  952. }
  953. function getWrappedName(outerType, innerType, wrapperName) {
  954. var functionName = innerType.displayName || innerType.name || '';
  955. return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName);
  956. }
  957. function getContextName(type) {
  958. return type.displayName || 'Context';
  959. }
  960. function getComponentName(type) {
  961. if (type == null) {
  962. // Host root, text node or just invalid type.
  963. return null;
  964. }
  965. {
  966. if (typeof type.tag === 'number') {
  967. error('Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
  968. }
  969. }
  970. if (typeof type === 'function') {
  971. return type.displayName || type.name || null;
  972. }
  973. if (typeof type === 'string') {
  974. return type;
  975. }
  976. switch (type) {
  977. case REACT_FRAGMENT_TYPE:
  978. return 'Fragment';
  979. case REACT_PORTAL_TYPE:
  980. return 'Portal';
  981. case REACT_PROFILER_TYPE:
  982. return 'Profiler';
  983. case REACT_STRICT_MODE_TYPE:
  984. return 'StrictMode';
  985. case REACT_SUSPENSE_TYPE:
  986. return 'Suspense';
  987. case REACT_SUSPENSE_LIST_TYPE:
  988. return 'SuspenseList';
  989. }
  990. if (typeof type === 'object') {
  991. switch (type.$$typeof) {
  992. case REACT_CONTEXT_TYPE:
  993. var context = type;
  994. return getContextName(context) + '.Consumer';
  995. case REACT_PROVIDER_TYPE:
  996. var provider = type;
  997. return getContextName(provider._context) + '.Provider';
  998. case REACT_FORWARD_REF_TYPE:
  999. return getWrappedName(type, type.render, 'ForwardRef');
  1000. case REACT_MEMO_TYPE:
  1001. return getComponentName(type.type);
  1002. case REACT_BLOCK_TYPE:
  1003. return getComponentName(type._render);
  1004. case REACT_LAZY_TYPE:
  1005. {
  1006. var lazyComponent = type;
  1007. var payload = lazyComponent._payload;
  1008. var init = lazyComponent._init;
  1009. try {
  1010. return getComponentName(init(payload));
  1011. } catch (x) {
  1012. return null;
  1013. }
  1014. }
  1015. }
  1016. }
  1017. return null;
  1018. }
  1019. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  1020. var current = null;
  1021. var isRendering = false;
  1022. function getCurrentFiberOwnerNameInDevOrNull() {
  1023. {
  1024. if (current === null) {
  1025. return null;
  1026. }
  1027. var owner = current._debugOwner;
  1028. if (owner !== null && typeof owner !== 'undefined') {
  1029. return getComponentName(owner.type);
  1030. }
  1031. }
  1032. return null;
  1033. }
  1034. function getCurrentFiberStackInDev() {
  1035. {
  1036. if (current === null) {
  1037. return '';
  1038. } // Safe because if current fiber exists, we are reconciling,
  1039. // and it is guaranteed to be the work-in-progress version.
  1040. return getStackByFiberInDevAndProd(current);
  1041. }
  1042. }
  1043. function resetCurrentFiber() {
  1044. {
  1045. ReactDebugCurrentFrame.getCurrentStack = null;
  1046. current = null;
  1047. isRendering = false;
  1048. }
  1049. }
  1050. function setCurrentFiber(fiber) {
  1051. {
  1052. ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
  1053. current = fiber;
  1054. isRendering = false;
  1055. }
  1056. }
  1057. function setIsRendering(rendering) {
  1058. {
  1059. isRendering = rendering;
  1060. }
  1061. }
  1062. function getIsRendering() {
  1063. {
  1064. return isRendering;
  1065. }
  1066. }
  1067. // Flow does not allow string concatenation of most non-string types. To work
  1068. // around this limitation, we use an opaque type that can only be obtained by
  1069. // passing the value through getToStringValue first.
  1070. function toString(value) {
  1071. return '' + value;
  1072. }
  1073. function getToStringValue(value) {
  1074. switch (typeof value) {
  1075. case 'boolean':
  1076. case 'number':
  1077. case 'object':
  1078. case 'string':
  1079. case 'undefined':
  1080. return value;
  1081. default:
  1082. // function, symbol are assigned as empty strings
  1083. return '';
  1084. }
  1085. }
  1086. var hasReadOnlyValue = {
  1087. button: true,
  1088. checkbox: true,
  1089. image: true,
  1090. hidden: true,
  1091. radio: true,
  1092. reset: true,
  1093. submit: true
  1094. };
  1095. function checkControlledValueProps(tagName, props) {
  1096. {
  1097. if (!(hasReadOnlyValue[props.type] || props.onChange || props.onInput || props.readOnly || props.disabled || props.value == null)) {
  1098. error('You provided a `value` prop to a form field without an ' + '`onChange` handler. This will render a read-only field. If ' + 'the field should be mutable use `defaultValue`. Otherwise, ' + 'set either `onChange` or `readOnly`.');
  1099. }
  1100. if (!(props.onChange || props.readOnly || props.disabled || props.checked == null)) {
  1101. error('You provided a `checked` prop to a form field without an ' + '`onChange` handler. This will render a read-only field. If ' + 'the field should be mutable use `defaultChecked`. Otherwise, ' + 'set either `onChange` or `readOnly`.');
  1102. }
  1103. }
  1104. }
  1105. function isCheckable(elem) {
  1106. var type = elem.type;
  1107. var nodeName = elem.nodeName;
  1108. return nodeName && nodeName.toLowerCase() === 'input' && (type === 'checkbox' || type === 'radio');
  1109. }
  1110. function getTracker(node) {
  1111. return node._valueTracker;
  1112. }
  1113. function detachTracker(node) {
  1114. node._valueTracker = null;
  1115. }
  1116. function getValueFromNode(node) {
  1117. var value = '';
  1118. if (!node) {
  1119. return value;
  1120. }
  1121. if (isCheckable(node)) {
  1122. value = node.checked ? 'true' : 'false';
  1123. } else {
  1124. value = node.value;
  1125. }
  1126. return value;
  1127. }
  1128. function trackValueOnNode(node) {
  1129. var valueField = isCheckable(node) ? 'checked' : 'value';
  1130. var descriptor = Object.getOwnPropertyDescriptor(node.constructor.prototype, valueField);
  1131. var currentValue = '' + node[valueField]; // if someone has already defined a value or Safari, then bail
  1132. // and don't track value will cause over reporting of changes,
  1133. // but it's better then a hard failure
  1134. // (needed for certain tests that spyOn input values and Safari)
  1135. if (node.hasOwnProperty(valueField) || typeof descriptor === 'undefined' || typeof descriptor.get !== 'function' || typeof descriptor.set !== 'function') {
  1136. return;
  1137. }
  1138. var get = descriptor.get,
  1139. set = descriptor.set;
  1140. Object.defineProperty(node, valueField, {
  1141. configurable: true,
  1142. get: function () {
  1143. return get.call(this);
  1144. },
  1145. set: function (value) {
  1146. currentValue = '' + value;
  1147. set.call(this, value);
  1148. }
  1149. }); // We could've passed this the first time
  1150. // but it triggers a bug in IE11 and Edge 14/15.
  1151. // Calling defineProperty() again should be equivalent.
  1152. // https://github.com/facebook/react/issues/11768
  1153. Object.defineProperty(node, valueField, {
  1154. enumerable: descriptor.enumerable
  1155. });
  1156. var tracker = {
  1157. getValue: function () {
  1158. return currentValue;
  1159. },
  1160. setValue: function (value) {
  1161. currentValue = '' + value;
  1162. },
  1163. stopTracking: function () {
  1164. detachTracker(node);
  1165. delete node[valueField];
  1166. }
  1167. };
  1168. return tracker;
  1169. }
  1170. function track(node) {
  1171. if (getTracker(node)) {
  1172. return;
  1173. } // TODO: Once it's just Fiber we can move this to node._wrapperState
  1174. node._valueTracker = trackValueOnNode(node);
  1175. }
  1176. function updateValueIfChanged(node) {
  1177. if (!node) {
  1178. return false;
  1179. }
  1180. var tracker = getTracker(node); // if there is no tracker at this point it's unlikely
  1181. // that trying again will succeed
  1182. if (!tracker) {
  1183. return true;
  1184. }
  1185. var lastValue = tracker.getValue();
  1186. var nextValue = getValueFromNode(node);
  1187. if (nextValue !== lastValue) {
  1188. tracker.setValue(nextValue);
  1189. return true;
  1190. }
  1191. return false;
  1192. }
  1193. function getActiveElement(doc) {
  1194. doc = doc || (typeof document !== 'undefined' ? document : undefined);
  1195. if (typeof doc === 'undefined') {
  1196. return null;
  1197. }
  1198. try {
  1199. return doc.activeElement || doc.body;
  1200. } catch (e) {
  1201. return doc.body;
  1202. }
  1203. }
  1204. var didWarnValueDefaultValue = false;
  1205. var didWarnCheckedDefaultChecked = false;
  1206. var didWarnControlledToUncontrolled = false;
  1207. var didWarnUncontrolledToControlled = false;
  1208. function isControlled(props) {
  1209. var usesChecked = props.type === 'checkbox' || props.type === 'radio';
  1210. return usesChecked ? props.checked != null : props.value != null;
  1211. }
  1212. /**
  1213. * Implements an <input> host component that allows setting these optional
  1214. * props: `checked`, `value`, `defaultChecked`, and `defaultValue`.
  1215. *
  1216. * If `checked` or `value` are not supplied (or null/undefined), user actions
  1217. * that affect the checked state or value will trigger updates to the element.
  1218. *
  1219. * If they are supplied (and not null/undefined), the rendered element will not
  1220. * trigger updates to the element. Instead, the props must change in order for
  1221. * the rendered element to be updated.
  1222. *
  1223. * The rendered element will be initialized as unchecked (or `defaultChecked`)
  1224. * with an empty value (or `defaultValue`).
  1225. *
  1226. * See http://www.w3.org/TR/2012/WD-html5-20121025/the-input-element.html
  1227. */
  1228. function getHostProps(element, props) {
  1229. var node = element;
  1230. var checked = props.checked;
  1231. var hostProps = _assign({}, props, {
  1232. defaultChecked: undefined,
  1233. defaultValue: undefined,
  1234. value: undefined,
  1235. checked: checked != null ? checked : node._wrapperState.initialChecked
  1236. });
  1237. return hostProps;
  1238. }
  1239. function initWrapperState(element, props) {
  1240. {
  1241. checkControlledValueProps('input', props);
  1242. if (props.checked !== undefined && props.defaultChecked !== undefined && !didWarnCheckedDefaultChecked) {
  1243. error('%s contains an input of type %s with both checked and defaultChecked props. ' + 'Input elements must be either controlled or uncontrolled ' + '(specify either the checked prop, or the defaultChecked prop, but not ' + 'both). Decide between using a controlled or uncontrolled input ' + 'element and remove one of these props. More info: ' + 'https://reactjs.org/link/controlled-components', getCurrentFiberOwnerNameInDevOrNull() || 'A component', props.type);
  1244. didWarnCheckedDefaultChecked = true;
  1245. }
  1246. if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValueDefaultValue) {
  1247. error('%s contains an input of type %s with both value and defaultValue props. ' + 'Input elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled input ' + 'element and remove one of these props. More info: ' + 'https://reactjs.org/link/controlled-components', getCurrentFiberOwnerNameInDevOrNull() || 'A component', props.type);
  1248. didWarnValueDefaultValue = true;
  1249. }
  1250. }
  1251. var node = element;
  1252. var defaultValue = props.defaultValue == null ? '' : props.defaultValue;
  1253. node._wrapperState = {
  1254. initialChecked: props.checked != null ? props.checked : props.defaultChecked,
  1255. initialValue: getToStringValue(props.value != null ? props.value : defaultValue),
  1256. controlled: isControlled(props)
  1257. };
  1258. }
  1259. function updateChecked(element, props) {
  1260. var node = element;
  1261. var checked = props.checked;
  1262. if (checked != null) {
  1263. setValueForProperty(node, 'checked', checked, false);
  1264. }
  1265. }
  1266. function updateWrapper(element, props) {
  1267. var node = element;
  1268. {
  1269. var controlled = isControlled(props);
  1270. if (!node._wrapperState.controlled && controlled && !didWarnUncontrolledToControlled) {
  1271. error('A component is changing an uncontrolled input to be controlled. ' + 'This is likely caused by the value changing from undefined to ' + 'a defined value, which should not happen. ' + 'Decide between using a controlled or uncontrolled input ' + 'element for the lifetime of the component. More info: https://reactjs.org/link/controlled-components');
  1272. didWarnUncontrolledToControlled = true;
  1273. }
  1274. if (node._wrapperState.controlled && !controlled && !didWarnControlledToUncontrolled) {
  1275. error('A component is changing a controlled input to be uncontrolled. ' + 'This is likely caused by the value changing from a defined to ' + 'undefined, which should not happen. ' + 'Decide between using a controlled or uncontrolled input ' + 'element for the lifetime of the component. More info: https://reactjs.org/link/controlled-components');
  1276. didWarnControlledToUncontrolled = true;
  1277. }
  1278. }
  1279. updateChecked(element, props);
  1280. var value = getToStringValue(props.value);
  1281. var type = props.type;
  1282. if (value != null) {
  1283. if (type === 'number') {
  1284. if (value === 0 && node.value === '' || // We explicitly want to coerce to number here if possible.
  1285. // eslint-disable-next-line
  1286. node.value != value) {
  1287. node.value = toString(value);
  1288. }
  1289. } else if (node.value !== toString(value)) {
  1290. node.value = toString(value);
  1291. }
  1292. } else if (type === 'submit' || type === 'reset') {
  1293. // Submit/reset inputs need the attribute removed completely to avoid
  1294. // blank-text buttons.
  1295. node.removeAttribute('value');
  1296. return;
  1297. }
  1298. {
  1299. // When syncing the value attribute, the value comes from a cascade of
  1300. // properties:
  1301. // 1. The value React property
  1302. // 2. The defaultValue React property
  1303. // 3. Otherwise there should be no change
  1304. if (props.hasOwnProperty('value')) {
  1305. setDefaultValue(node, props.type, value);
  1306. } else if (props.hasOwnProperty('defaultValue')) {
  1307. setDefaultValue(node, props.type, getToStringValue(props.defaultValue));
  1308. }
  1309. }
  1310. {
  1311. // When syncing the checked attribute, it only changes when it needs
  1312. // to be removed, such as transitioning from a checkbox into a text input
  1313. if (props.checked == null && props.defaultChecked != null) {
  1314. node.defaultChecked = !!props.defaultChecked;
  1315. }
  1316. }
  1317. }
  1318. function postMountWrapper(element, props, isHydrating) {
  1319. var node = element; // Do not assign value if it is already set. This prevents user text input
  1320. // from being lost during SSR hydration.
  1321. if (props.hasOwnProperty('value') || props.hasOwnProperty('defaultValue')) {
  1322. var type = props.type;
  1323. var isButton = type === 'submit' || type === 'reset'; // Avoid setting value attribute on submit/reset inputs as it overrides the
  1324. // default value provided by the browser. See: #12872
  1325. if (isButton && (props.value === undefined || props.value === null)) {
  1326. return;
  1327. }
  1328. var initialValue = toString(node._wrapperState.initialValue); // Do not assign value if it is already set. This prevents user text input
  1329. // from being lost during SSR hydration.
  1330. if (!isHydrating) {
  1331. {
  1332. // When syncing the value attribute, the value property should use
  1333. // the wrapperState._initialValue property. This uses:
  1334. //
  1335. // 1. The value React property when present
  1336. // 2. The defaultValue React property when present
  1337. // 3. An empty string
  1338. if (initialValue !== node.value) {
  1339. node.value = initialValue;
  1340. }
  1341. }
  1342. }
  1343. {
  1344. // Otherwise, the value attribute is synchronized to the property,
  1345. // so we assign defaultValue to the same thing as the value property
  1346. // assignment step above.
  1347. node.defaultValue = initialValue;
  1348. }
  1349. } // Normally, we'd just do `node.checked = node.checked` upon initial mount, less this bug
  1350. // this is needed to work around a chrome bug where setting defaultChecked
  1351. // will sometimes influence the value of checked (even after detachment).
  1352. // Reference: https://bugs.chromium.org/p/chromium/issues/detail?id=608416
  1353. // We need to temporarily unset name to avoid disrupting radio button groups.
  1354. var name = node.name;
  1355. if (name !== '') {
  1356. node.name = '';
  1357. }
  1358. {
  1359. // When syncing the checked attribute, both the checked property and
  1360. // attribute are assigned at the same time using defaultChecked. This uses:
  1361. //
  1362. // 1. The checked React property when present
  1363. // 2. The defaultChecked React property when present
  1364. // 3. Otherwise, false
  1365. node.defaultChecked = !node.defaultChecked;
  1366. node.defaultChecked = !!node._wrapperState.initialChecked;
  1367. }
  1368. if (name !== '') {
  1369. node.name = name;
  1370. }
  1371. }
  1372. function restoreControlledState(element, props) {
  1373. var node = element;
  1374. updateWrapper(node, props);
  1375. updateNamedCousins(node, props);
  1376. }
  1377. function updateNamedCousins(rootNode, props) {
  1378. var name = props.name;
  1379. if (props.type === 'radio' && name != null) {
  1380. var queryRoot = rootNode;
  1381. while (queryRoot.parentNode) {
  1382. queryRoot = queryRoot.parentNode;
  1383. } // If `rootNode.form` was non-null, then we could try `form.elements`,
  1384. // but that sometimes behaves strangely in IE8. We could also try using
  1385. // `form.getElementsByName`, but that will only return direct children
  1386. // and won't include inputs that use the HTML5 `form=` attribute. Since
  1387. // the input might not even be in a form. It might not even be in the
  1388. // document. Let's just use the local `querySelectorAll` to ensure we don't
  1389. // miss anything.
  1390. var group = queryRoot.querySelectorAll('input[name=' + JSON.stringify('' + name) + '][type="radio"]');
  1391. for (var i = 0; i < group.length; i++) {
  1392. var otherNode = group[i];
  1393. if (otherNode === rootNode || otherNode.form !== rootNode.form) {
  1394. continue;
  1395. } // This will throw if radio buttons rendered by different copies of React
  1396. // and the same name are rendered into the same form (same as #1939).
  1397. // That's probably okay; we don't support it just as we don't support
  1398. // mixing React radio buttons with non-React ones.
  1399. var otherProps = getFiberCurrentPropsFromNode(otherNode);
  1400. if (!otherProps) {
  1401. {
  1402. throw Error( "ReactDOMInput: Mixing React and non-React radio inputs with the same `name` is not supported." );
  1403. }
  1404. } // We need update the tracked value on the named cousin since the value
  1405. // was changed but the input saw no event or value set
  1406. updateValueIfChanged(otherNode); // If this is a controlled radio button group, forcing the input that
  1407. // was previously checked to update will cause it to be come re-checked
  1408. // as appropriate.
  1409. updateWrapper(otherNode, otherProps);
  1410. }
  1411. }
  1412. } // In Chrome, assigning defaultValue to certain input types triggers input validation.
  1413. // For number inputs, the display value loses trailing decimal points. For email inputs,
  1414. // Chrome raises "The specified value <x> is not a valid email address".
  1415. //
  1416. // Here we check to see if the defaultValue has actually changed, avoiding these problems
  1417. // when the user is inputting text
  1418. //
  1419. // https://github.com/facebook/react/issues/7253
  1420. function setDefaultValue(node, type, value) {
  1421. if ( // Focused number inputs synchronize on blur. See ChangeEventPlugin.js
  1422. type !== 'number' || getActiveElement(node.ownerDocument) !== node) {
  1423. if (value == null) {
  1424. node.defaultValue = toString(node._wrapperState.initialValue);
  1425. } else if (node.defaultValue !== toString(value)) {
  1426. node.defaultValue = toString(value);
  1427. }
  1428. }
  1429. }
  1430. var didWarnSelectedSetOnOption = false;
  1431. var didWarnInvalidChild = false;
  1432. function flattenChildren(children) {
  1433. var content = ''; // Flatten children. We'll warn if they are invalid
  1434. // during validateProps() which runs for hydration too.
  1435. // Note that this would throw on non-element objects.
  1436. // Elements are stringified (which is normally irrelevant
  1437. // but matters for <fbt>).
  1438. React.Children.forEach(children, function (child) {
  1439. if (child == null) {
  1440. return;
  1441. }
  1442. content += child; // Note: we don't warn about invalid children here.
  1443. // Instead, this is done separately below so that
  1444. // it happens during the hydration code path too.
  1445. });
  1446. return content;
  1447. }
  1448. /**
  1449. * Implements an <option> host component that warns when `selected` is set.
  1450. */
  1451. function validateProps(element, props) {
  1452. {
  1453. // This mirrors the code path above, but runs for hydration too.
  1454. // Warn about invalid children here so that client and hydration are consistent.
  1455. // TODO: this seems like it could cause a DEV-only throw for hydration
  1456. // if children contains a non-element object. We should try to avoid that.
  1457. if (typeof props.children === 'object' && props.children !== null) {
  1458. React.Children.forEach(props.children, function (child) {
  1459. if (child == null) {
  1460. return;
  1461. }
  1462. if (typeof child === 'string' || typeof child === 'number') {
  1463. return;
  1464. }
  1465. if (typeof child.type !== 'string') {
  1466. return;
  1467. }
  1468. if (!didWarnInvalidChild) {
  1469. didWarnInvalidChild = true;
  1470. error('Only strings and numbers are supported as <option> children.');
  1471. }
  1472. });
  1473. } // TODO: Remove support for `selected` in <option>.
  1474. if (props.selected != null && !didWarnSelectedSetOnOption) {
  1475. error('Use the `defaultValue` or `value` props on <select> instead of ' + 'setting `selected` on <option>.');
  1476. didWarnSelectedSetOnOption = true;
  1477. }
  1478. }
  1479. }
  1480. function postMountWrapper$1(element, props) {
  1481. // value="" should make a value attribute (#6219)
  1482. if (props.value != null) {
  1483. element.setAttribute('value', toString(getToStringValue(props.value)));
  1484. }
  1485. }
  1486. function getHostProps$1(element, props) {
  1487. var hostProps = _assign({
  1488. children: undefined
  1489. }, props);
  1490. var content = flattenChildren(props.children);
  1491. if (content) {
  1492. hostProps.children = content;
  1493. }
  1494. return hostProps;
  1495. }
  1496. var didWarnValueDefaultValue$1;
  1497. {
  1498. didWarnValueDefaultValue$1 = false;
  1499. }
  1500. function getDeclarationErrorAddendum() {
  1501. var ownerName = getCurrentFiberOwnerNameInDevOrNull();
  1502. if (ownerName) {
  1503. return '\n\nCheck the render method of `' + ownerName + '`.';
  1504. }
  1505. return '';
  1506. }
  1507. var valuePropNames = ['value', 'defaultValue'];
  1508. /**
  1509. * Validation function for `value` and `defaultValue`.
  1510. */
  1511. function checkSelectPropTypes(props) {
  1512. {
  1513. checkControlledValueProps('select', props);
  1514. for (var i = 0; i < valuePropNames.length; i++) {
  1515. var propName = valuePropNames[i];
  1516. if (props[propName] == null) {
  1517. continue;
  1518. }
  1519. var isArray = Array.isArray(props[propName]);
  1520. if (props.multiple && !isArray) {
  1521. error('The `%s` prop supplied to <select> must be an array if ' + '`multiple` is true.%s', propName, getDeclarationErrorAddendum());
  1522. } else if (!props.multiple && isArray) {
  1523. error('The `%s` prop supplied to <select> must be a scalar ' + 'value if `multiple` is false.%s', propName, getDeclarationErrorAddendum());
  1524. }
  1525. }
  1526. }
  1527. }
  1528. function updateOptions(node, multiple, propValue, setDefaultSelected) {
  1529. var options = node.options;
  1530. if (multiple) {
  1531. var selectedValues = propValue;
  1532. var selectedValue = {};
  1533. for (var i = 0; i < selectedValues.length; i++) {
  1534. // Prefix to avoid chaos with special keys.
  1535. selectedValue['$' + selectedValues[i]] = true;
  1536. }
  1537. for (var _i = 0; _i < options.length; _i++) {
  1538. var selected = selectedValue.hasOwnProperty('$' + options[_i].value);
  1539. if (options[_i].selected !== selected) {
  1540. options[_i].selected = selected;
  1541. }
  1542. if (selected && setDefaultSelected) {
  1543. options[_i].defaultSelected = true;
  1544. }
  1545. }
  1546. } else {
  1547. // Do not set `select.value` as exact behavior isn't consistent across all
  1548. // browsers for all cases.
  1549. var _selectedValue = toString(getToStringValue(propValue));
  1550. var defaultSelected = null;
  1551. for (var _i2 = 0; _i2 < options.length; _i2++) {
  1552. if (options[_i2].value === _selectedValue) {
  1553. options[_i2].selected = true;
  1554. if (setDefaultSelected) {
  1555. options[_i2].defaultSelected = true;
  1556. }
  1557. return;
  1558. }
  1559. if (defaultSelected === null && !options[_i2].disabled) {
  1560. defaultSelected = options[_i2];
  1561. }
  1562. }
  1563. if (defaultSelected !== null) {
  1564. defaultSelected.selected = true;
  1565. }
  1566. }
  1567. }
  1568. /**
  1569. * Implements a <select> host component that allows optionally setting the
  1570. * props `value` and `defaultValue`. If `multiple` is false, the prop must be a
  1571. * stringable. If `multiple` is true, the prop must be an array of stringables.
  1572. *
  1573. * If `value` is not supplied (or null/undefined), user actions that change the
  1574. * selected option will trigger updates to the rendered options.
  1575. *
  1576. * If it is supplied (and not null/undefined), the rendered options will not
  1577. * update in response to user actions. Instead, the `value` prop must change in
  1578. * order for the rendered options to update.
  1579. *
  1580. * If `defaultValue` is provided, any options with the supplied values will be
  1581. * selected.
  1582. */
  1583. function getHostProps$2(element, props) {
  1584. return _assign({}, props, {
  1585. value: undefined
  1586. });
  1587. }
  1588. function initWrapperState$1(element, props) {
  1589. var node = element;
  1590. {
  1591. checkSelectPropTypes(props);
  1592. }
  1593. node._wrapperState = {
  1594. wasMultiple: !!props.multiple
  1595. };
  1596. {
  1597. if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValueDefaultValue$1) {
  1598. error('Select elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled select ' + 'element and remove one of these props. More info: ' + 'https://reactjs.org/link/controlled-components');
  1599. didWarnValueDefaultValue$1 = true;
  1600. }
  1601. }
  1602. }
  1603. function postMountWrapper$2(element, props) {
  1604. var node = element;
  1605. node.multiple = !!props.multiple;
  1606. var value = props.value;
  1607. if (value != null) {
  1608. updateOptions(node, !!props.multiple, value, false);
  1609. } else if (props.defaultValue != null) {
  1610. updateOptions(node, !!props.multiple, props.defaultValue, true);
  1611. }
  1612. }
  1613. function postUpdateWrapper(element, props) {
  1614. var node = element;
  1615. var wasMultiple = node._wrapperState.wasMultiple;
  1616. node._wrapperState.wasMultiple = !!props.multiple;
  1617. var value = props.value;
  1618. if (value != null) {
  1619. updateOptions(node, !!props.multiple, value, false);
  1620. } else if (wasMultiple !== !!props.multiple) {
  1621. // For simplicity, reapply `defaultValue` if `multiple` is toggled.
  1622. if (props.defaultValue != null) {
  1623. updateOptions(node, !!props.multiple, props.defaultValue, true);
  1624. } else {
  1625. // Revert the select back to its default unselected state.
  1626. updateOptions(node, !!props.multiple, props.multiple ? [] : '', false);
  1627. }
  1628. }
  1629. }
  1630. function restoreControlledState$1(element, props) {
  1631. var node = element;
  1632. var value = props.value;
  1633. if (value != null) {
  1634. updateOptions(node, !!props.multiple, value, false);
  1635. }
  1636. }
  1637. var didWarnValDefaultVal = false;
  1638. /**
  1639. * Implements a <textarea> host component that allows setting `value`, and
  1640. * `defaultValue`. This differs from the traditional DOM API because value is
  1641. * usually set as PCDATA children.
  1642. *
  1643. * If `value` is not supplied (or null/undefined), user actions that affect the
  1644. * value will trigger updates to the element.
  1645. *
  1646. * If `value` is supplied (and not null/undefined), the rendered element will
  1647. * not trigger updates to the element. Instead, the `value` prop must change in
  1648. * order for the rendered element to be updated.
  1649. *
  1650. * The rendered element will be initialized with an empty value, the prop
  1651. * `defaultValue` if specified, or the children content (deprecated).
  1652. */
  1653. function getHostProps$3(element, props) {
  1654. var node = element;
  1655. if (!(props.dangerouslySetInnerHTML == null)) {
  1656. {
  1657. throw Error( "`dangerouslySetInnerHTML` does not make sense on <textarea>." );
  1658. }
  1659. } // Always set children to the same thing. In IE9, the selection range will
  1660. // get reset if `textContent` is mutated. We could add a check in setTextContent
  1661. // to only set the value if/when the value differs from the node value (which would
  1662. // completely solve this IE9 bug), but Sebastian+Sophie seemed to like this
  1663. // solution. The value can be a boolean or object so that's why it's forced
  1664. // to be a string.
  1665. var hostProps = _assign({}, props, {
  1666. value: undefined,
  1667. defaultValue: undefined,
  1668. children: toString(node._wrapperState.initialValue)
  1669. });
  1670. return hostProps;
  1671. }
  1672. function initWrapperState$2(element, props) {
  1673. var node = element;
  1674. {
  1675. checkControlledValueProps('textarea', props);
  1676. if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValDefaultVal) {
  1677. error('%s contains a textarea with both value and defaultValue props. ' + 'Textarea elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled textarea ' + 'and remove one of these props. More info: ' + 'https://reactjs.org/link/controlled-components', getCurrentFiberOwnerNameInDevOrNull() || 'A component');
  1678. didWarnValDefaultVal = true;
  1679. }
  1680. }
  1681. var initialValue = props.value; // Only bother fetching default value if we're going to use it
  1682. if (initialValue == null) {
  1683. var children = props.children,
  1684. defaultValue = props.defaultValue;
  1685. if (children != null) {
  1686. {
  1687. error('Use the `defaultValue` or `value` props instead of setting ' + 'children on <textarea>.');
  1688. }
  1689. {
  1690. if (!(defaultValue == null)) {
  1691. {
  1692. throw Error( "If you supply `defaultValue` on a <textarea>, do not pass children." );
  1693. }
  1694. }
  1695. if (Array.isArray(children)) {
  1696. if (!(children.length <= 1)) {
  1697. {
  1698. throw Error( "<textarea> can only have at most one child." );
  1699. }
  1700. }
  1701. children = children[0];
  1702. }
  1703. defaultValue = children;
  1704. }
  1705. }
  1706. if (defaultValue == null) {
  1707. defaultValue = '';
  1708. }
  1709. initialValue = defaultValue;
  1710. }
  1711. node._wrapperState = {
  1712. initialValue: getToStringValue(initialValue)
  1713. };
  1714. }
  1715. function updateWrapper$1(element, props) {
  1716. var node = element;
  1717. var value = getToStringValue(props.value);
  1718. var defaultValue = getToStringValue(props.defaultValue);
  1719. if (value != null) {
  1720. // Cast `value` to a string to ensure the value is set correctly. While
  1721. // browsers typically do this as necessary, jsdom doesn't.
  1722. var newValue = toString(value); // To avoid side effects (such as losing text selection), only set value if changed
  1723. if (newValue !== node.value) {
  1724. node.value = newValue;
  1725. }
  1726. if (props.defaultValue == null && node.defaultValue !== newValue) {
  1727. node.defaultValue = newValue;
  1728. }
  1729. }
  1730. if (defaultValue != null) {
  1731. node.defaultValue = toString(defaultValue);
  1732. }
  1733. }
  1734. function postMountWrapper$3(element, props) {
  1735. var node = element; // This is in postMount because we need access to the DOM node, which is not
  1736. // available until after the component has mounted.
  1737. var textContent = node.textContent; // Only set node.value if textContent is equal to the expected
  1738. // initial value. In IE10/IE11 there is a bug where the placeholder attribute
  1739. // will populate textContent as well.
  1740. // https://developer.microsoft.com/microsoft-edge/platform/issues/101525/
  1741. if (textContent === node._wrapperState.initialValue) {
  1742. if (textContent !== '' && textContent !== null) {
  1743. node.value = textContent;
  1744. }
  1745. }
  1746. }
  1747. function restoreControlledState$2(element, props) {
  1748. // DOM component is still mounted; update
  1749. updateWrapper$1(element, props);
  1750. }
  1751. var HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
  1752. var MATH_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
  1753. var SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
  1754. var Namespaces = {
  1755. html: HTML_NAMESPACE,
  1756. mathml: MATH_NAMESPACE,
  1757. svg: SVG_NAMESPACE
  1758. }; // Assumes there is no parent namespace.
  1759. function getIntrinsicNamespace(type) {
  1760. switch (type) {
  1761. case 'svg':
  1762. return SVG_NAMESPACE;
  1763. case 'math':
  1764. return MATH_NAMESPACE;
  1765. default:
  1766. return HTML_NAMESPACE;
  1767. }
  1768. }
  1769. function getChildNamespace(parentNamespace, type) {
  1770. if (parentNamespace == null || parentNamespace === HTML_NAMESPACE) {
  1771. // No (or default) parent namespace: potential entry point.
  1772. return getIntrinsicNamespace(type);
  1773. }
  1774. if (parentNamespace === SVG_NAMESPACE && type === 'foreignObject') {
  1775. // We're leaving SVG.
  1776. return HTML_NAMESPACE;
  1777. } // By default, pass namespace below.
  1778. return parentNamespace;
  1779. }
  1780. /* globals MSApp */
  1781. /**
  1782. * Create a function which has 'unsafe' privileges (required by windows8 apps)
  1783. */
  1784. var createMicrosoftUnsafeLocalFunction = function (func) {
  1785. if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) {
  1786. return function (arg0, arg1, arg2, arg3) {
  1787. MSApp.execUnsafeLocalFunction(function () {
  1788. return func(arg0, arg1, arg2, arg3);
  1789. });
  1790. };
  1791. } else {
  1792. return func;
  1793. }
  1794. };
  1795. var reusableSVGContainer;
  1796. /**
  1797. * Set the innerHTML property of a node
  1798. *
  1799. * @param {DOMElement} node
  1800. * @param {string} html
  1801. * @internal
  1802. */
  1803. var setInnerHTML = createMicrosoftUnsafeLocalFunction(function (node, html) {
  1804. if (node.namespaceURI === Namespaces.svg) {
  1805. if (!('innerHTML' in node)) {
  1806. // IE does not have innerHTML for SVG nodes, so instead we inject the
  1807. // new markup in a temp node and then move the child nodes across into
  1808. // the target node
  1809. reusableSVGContainer = reusableSVGContainer || document.createElement('div');
  1810. reusableSVGContainer.innerHTML = '<svg>' + html.valueOf().toString() + '</svg>';
  1811. var svgNode = reusableSVGContainer.firstChild;
  1812. while (node.firstChild) {
  1813. node.removeChild(node.firstChild);
  1814. }
  1815. while (svgNode.firstChild) {
  1816. node.appendChild(svgNode.firstChild);
  1817. }
  1818. return;
  1819. }
  1820. }
  1821. node.innerHTML = html;
  1822. });
  1823. /**
  1824. * HTML nodeType values that represent the type of the node
  1825. */
  1826. var ELEMENT_NODE = 1;
  1827. var TEXT_NODE = 3;
  1828. var COMMENT_NODE = 8;
  1829. var DOCUMENT_NODE = 9;
  1830. var DOCUMENT_FRAGMENT_NODE = 11;
  1831. /**
  1832. * Set the textContent property of a node. For text updates, it's faster
  1833. * to set the `nodeValue` of the Text node directly instead of using
  1834. * `.textContent` which will remove the existing node and create a new one.
  1835. *
  1836. * @param {DOMElement} node
  1837. * @param {string} text
  1838. * @internal
  1839. */
  1840. var setTextContent = function (node, text) {
  1841. if (text) {
  1842. var firstChild = node.firstChild;
  1843. if (firstChild && firstChild === node.lastChild && firstChild.nodeType === TEXT_NODE) {
  1844. firstChild.nodeValue = text;
  1845. return;
  1846. }
  1847. }
  1848. node.textContent = text;
  1849. };
  1850. // List derived from Gecko source code:
  1851. // https://github.com/mozilla/gecko-dev/blob/4e638efc71/layout/style/test/property_database.js
  1852. var shorthandToLonghand = {
  1853. animation: ['animationDelay', 'animationDirection', 'animationDuration', 'animationFillMode', 'animationIterationCount', 'animationName', 'animationPlayState', 'animationTimingFunction'],
  1854. background: ['backgroundAttachment', 'backgroundClip', 'backgroundColor', 'backgroundImage', 'backgroundOrigin', 'backgroundPositionX', 'backgroundPositionY', 'backgroundRepeat', 'backgroundSize'],
  1855. backgroundPosition: ['backgroundPositionX', 'backgroundPositionY'],
  1856. border: ['borderBottomColor', 'borderBottomStyle', 'borderBottomWidth', 'borderImageOutset', 'borderImageRepeat', 'borderImageSlice', 'borderImageSource', 'borderImageWidth', 'borderLeftColor', 'borderLeftStyle', 'borderLeftWidth', 'borderRightColor', 'borderRightStyle', 'borderRightWidth', 'borderTopColor', 'borderTopStyle', 'borderTopWidth'],
  1857. borderBlockEnd: ['borderBlockEndColor', 'borderBlockEndStyle', 'borderBlockEndWidth'],
  1858. borderBlockStart: ['borderBlockStartColor', 'borderBlockStartStyle', 'borderBlockStartWidth'],
  1859. borderBottom: ['borderBottomColor', 'borderBottomStyle', 'borderBottomWidth'],
  1860. borderColor: ['borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor'],
  1861. borderImage: ['borderImageOutset', 'borderImageRepeat', 'borderImageSlice', 'borderImageSource', 'borderImageWidth'],
  1862. borderInlineEnd: ['borderInlineEndColor', 'borderInlineEndStyle', 'borderInlineEndWidth'],
  1863. borderInlineStart: ['borderInlineStartColor', 'borderInlineStartStyle', 'borderInlineStartWidth'],
  1864. borderLeft: ['borderLeftColor', 'borderLeftStyle', 'borderLeftWidth'],
  1865. borderRadius: ['borderBottomLeftRadius', 'borderBottomRightRadius', 'borderTopLeftRadius', 'borderTopRightRadius'],
  1866. borderRight: ['borderRightColor', 'borderRightStyle', 'borderRightWidth'],
  1867. borderStyle: ['borderBottomStyle', 'borderLeftStyle', 'borderRightStyle', 'borderTopStyle'],
  1868. borderTop: ['borderTopColor', 'borderTopStyle', 'borderTopWidth'],
  1869. borderWidth: ['borderBottomWidth', 'borderLeftWidth', 'borderRightWidth', 'borderTopWidth'],
  1870. columnRule: ['columnRuleColor', 'columnRuleStyle', 'columnRuleWidth'],
  1871. columns: ['columnCount', 'columnWidth'],
  1872. flex: ['flexBasis', 'flexGrow', 'flexShrink'],
  1873. flexFlow: ['flexDirection', 'flexWrap'],
  1874. font: ['fontFamily', 'fontFeatureSettings', 'fontKerning', 'fontLanguageOverride', 'fontSize', 'fontSizeAdjust', 'fontStretch', 'fontStyle', 'fontVariant', 'fontVariantAlternates', 'fontVariantCaps', 'fontVariantEastAsian', 'fontVariantLigatures', 'fontVariantNumeric', 'fontVariantPosition', 'fontWeight', 'lineHeight'],
  1875. fontVariant: ['fontVariantAlternates', 'fontVariantCaps', 'fontVariantEastAsian', 'fontVariantLigatures', 'fontVariantNumeric', 'fontVariantPosition'],
  1876. gap: ['columnGap', 'rowGap'],
  1877. grid: ['gridAutoColumns', 'gridAutoFlow', 'gridAutoRows', 'gridTemplateAreas', 'gridTemplateColumns', 'gridTemplateRows'],
  1878. gridArea: ['gridColumnEnd', 'gridColumnStart', 'gridRowEnd', 'gridRowStart'],
  1879. gridColumn: ['gridColumnEnd', 'gridColumnStart'],
  1880. gridColumnGap: ['columnGap'],
  1881. gridGap: ['columnGap', 'rowGap'],
  1882. gridRow: ['gridRowEnd', 'gridRowStart'],
  1883. gridRowGap: ['rowGap'],
  1884. gridTemplate: ['gridTemplateAreas', 'gridTemplateColumns', 'gridTemplateRows'],
  1885. listStyle: ['listStyleImage', 'listStylePosition', 'listStyleType'],
  1886. margin: ['marginBottom', 'marginLeft', 'marginRight', 'marginTop'],
  1887. marker: ['markerEnd', 'markerMid', 'markerStart'],
  1888. mask: ['maskClip', 'maskComposite', 'maskImage', 'maskMode', 'maskOrigin', 'maskPositionX', 'maskPositionY', 'maskRepeat', 'maskSize'],
  1889. maskPosition: ['maskPositionX', 'maskPositionY'],
  1890. outline: ['outlineColor', 'outlineStyle', 'outlineWidth'],
  1891. overflow: ['overflowX', 'overflowY'],
  1892. padding: ['paddingBottom', 'paddingLeft', 'paddingRight', 'paddingTop'],
  1893. placeContent: ['alignContent', 'justifyContent'],
  1894. placeItems: ['alignItems', 'justifyItems'],
  1895. placeSelf: ['alignSelf', 'justifySelf'],
  1896. textDecoration: ['textDecorationColor', 'textDecorationLine', 'textDecorationStyle'],
  1897. textEmphasis: ['textEmphasisColor', 'textEmphasisStyle'],
  1898. transition: ['transitionDelay', 'transitionDuration', 'transitionProperty', 'transitionTimingFunction'],
  1899. wordWrap: ['overflowWrap']
  1900. };
  1901. /**
  1902. * CSS properties which accept numbers but are not in units of "px".
  1903. */
  1904. var isUnitlessNumber = {
  1905. animationIterationCount: true,
  1906. borderImageOutset: true,
  1907. borderImageSlice: true,
  1908. borderImageWidth: true,
  1909. boxFlex: true,
  1910. boxFlexGroup: true,
  1911. boxOrdinalGroup: true,
  1912. columnCount: true,
  1913. columns: true,
  1914. flex: true,
  1915. flexGrow: true,
  1916. flexPositive: true,
  1917. flexShrink: true,
  1918. flexNegative: true,
  1919. flexOrder: true,
  1920. gridArea: true,
  1921. gridRow: true,
  1922. gridRowEnd: true,
  1923. gridRowSpan: true,
  1924. gridRowStart: true,
  1925. gridColumn: true,
  1926. gridColumnEnd: true,
  1927. gridColumnSpan: true,
  1928. gridColumnStart: true,
  1929. fontWeight: true,
  1930. lineClamp: true,
  1931. lineHeight: true,
  1932. opacity: true,
  1933. order: true,
  1934. orphans: true,
  1935. tabSize: true,
  1936. widows: true,
  1937. zIndex: true,
  1938. zoom: true,
  1939. // SVG-related properties
  1940. fillOpacity: true,
  1941. floodOpacity: true,
  1942. stopOpacity: true,
  1943. strokeDasharray: true,
  1944. strokeDashoffset: true,
  1945. strokeMiterlimit: true,
  1946. strokeOpacity: true,
  1947. strokeWidth: true
  1948. };
  1949. /**
  1950. * @param {string} prefix vendor-specific prefix, eg: Webkit
  1951. * @param {string} key style name, eg: transitionDuration
  1952. * @return {string} style name prefixed with `prefix`, properly camelCased, eg:
  1953. * WebkitTransitionDuration
  1954. */
  1955. function prefixKey(prefix, key) {
  1956. return prefix + key.charAt(0).toUpperCase() + key.substring(1);
  1957. }
  1958. /**
  1959. * Support style names that may come passed in prefixed by adding permutations
  1960. * of vendor prefixes.
  1961. */
  1962. var prefixes = ['Webkit', 'ms', 'Moz', 'O']; // Using Object.keys here, or else the vanilla for-in loop makes IE8 go into an
  1963. // infinite loop, because it iterates over the newly added props too.
  1964. Object.keys(isUnitlessNumber).forEach(function (prop) {
  1965. prefixes.forEach(function (prefix) {
  1966. isUnitlessNumber[prefixKey(prefix, prop)] = isUnitlessNumber[prop];
  1967. });
  1968. });
  1969. /**
  1970. * Convert a value into the proper css writable value. The style name `name`
  1971. * should be logical (no hyphens), as specified
  1972. * in `CSSProperty.isUnitlessNumber`.
  1973. *
  1974. * @param {string} name CSS property name such as `topMargin`.
  1975. * @param {*} value CSS property value such as `10px`.
  1976. * @return {string} Normalized style value with dimensions applied.
  1977. */
  1978. function dangerousStyleValue(name, value, isCustomProperty) {
  1979. // Note that we've removed escapeTextForBrowser() calls here since the
  1980. // whole string will be escaped when the attribute is injected into
  1981. // the markup. If you provide unsafe user data here they can inject
  1982. // arbitrary CSS which may be problematic (I couldn't repro this):
  1983. // https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
  1984. // http://www.thespanner.co.uk/2007/11/26/ultimate-xss-css-injection/
  1985. // This is not an XSS hole but instead a potential CSS injection issue
  1986. // which has lead to a greater discussion about how we're going to
  1987. // trust URLs moving forward. See #2115901
  1988. var isEmpty = value == null || typeof value === 'boolean' || value === '';
  1989. if (isEmpty) {
  1990. return '';
  1991. }
  1992. if (!isCustomProperty && typeof value === 'number' && value !== 0 && !(isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name])) {
  1993. return value + 'px'; // Presumes implicit 'px' suffix for unitless numbers
  1994. }
  1995. return ('' + value).trim();
  1996. }
  1997. var uppercasePattern = /([A-Z])/g;
  1998. var msPattern = /^ms-/;
  1999. /**
  2000. * Hyphenates a camelcased CSS property name, for example:
  2001. *
  2002. * > hyphenateStyleName('backgroundColor')
  2003. * < "background-color"
  2004. * > hyphenateStyleName('MozTransition')
  2005. * < "-moz-transition"
  2006. * > hyphenateStyleName('msTransition')
  2007. * < "-ms-transition"
  2008. *
  2009. * As Modernizr suggests (http://modernizr.com/docs/#prefixed), an `ms` prefix
  2010. * is converted to `-ms-`.
  2011. */
  2012. function hyphenateStyleName(name) {
  2013. return name.replace(uppercasePattern, '-$1').toLowerCase().replace(msPattern, '-ms-');
  2014. }
  2015. var warnValidStyle = function () {};
  2016. {
  2017. // 'msTransform' is correct, but the other prefixes should be capitalized
  2018. var badVendoredStyleNamePattern = /^(?:webkit|moz|o)[A-Z]/;
  2019. var msPattern$1 = /^-ms-/;
  2020. var hyphenPattern = /-(.)/g; // style values shouldn't contain a semicolon
  2021. var badStyleValueWithSemicolonPattern = /;\s*$/;
  2022. var warnedStyleNames = {};
  2023. var warnedStyleValues = {};
  2024. var warnedForNaNValue = false;
  2025. var warnedForInfinityValue = false;
  2026. var camelize = function (string) {
  2027. return string.replace(hyphenPattern, function (_, character) {
  2028. return character.toUpperCase();
  2029. });
  2030. };
  2031. var warnHyphenatedStyleName = function (name) {
  2032. if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
  2033. return;
  2034. }
  2035. warnedStyleNames[name] = true;
  2036. error('Unsupported style property %s. Did you mean %s?', name, // As Andi Smith suggests
  2037. // (http://www.andismith.com/blog/2012/02/modernizr-prefixed/), an `-ms` prefix
  2038. // is converted to lowercase `ms`.
  2039. camelize(name.replace(msPattern$1, 'ms-')));
  2040. };
  2041. var warnBadVendoredStyleName = function (name) {
  2042. if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
  2043. return;
  2044. }
  2045. warnedStyleNames[name] = true;
  2046. error('Unsupported vendor-prefixed style property %s. Did you mean %s?', name, name.charAt(0).toUpperCase() + name.slice(1));
  2047. };
  2048. var warnStyleValueWithSemicolon = function (name, value) {
  2049. if (warnedStyleValues.hasOwnProperty(value) && warnedStyleValues[value]) {
  2050. return;
  2051. }
  2052. warnedStyleValues[value] = true;
  2053. error("Style property values shouldn't contain a semicolon. " + 'Try "%s: %s" instead.', name, value.replace(badStyleValueWithSemicolonPattern, ''));
  2054. };
  2055. var warnStyleValueIsNaN = function (name, value) {
  2056. if (warnedForNaNValue) {
  2057. return;
  2058. }
  2059. warnedForNaNValue = true;
  2060. error('`NaN` is an invalid value for the `%s` css style property.', name);
  2061. };
  2062. var warnStyleValueIsInfinity = function (name, value) {
  2063. if (warnedForInfinityValue) {
  2064. return;
  2065. }
  2066. warnedForInfinityValue = true;
  2067. error('`Infinity` is an invalid value for the `%s` css style property.', name);
  2068. };
  2069. warnValidStyle = function (name, value) {
  2070. if (name.indexOf('-') > -1) {
  2071. warnHyphenatedStyleName(name);
  2072. } else if (badVendoredStyleNamePattern.test(name)) {
  2073. warnBadVendoredStyleName(name);
  2074. } else if (badStyleValueWithSemicolonPattern.test(value)) {
  2075. warnStyleValueWithSemicolon(name, value);
  2076. }
  2077. if (typeof value === 'number') {
  2078. if (isNaN(value)) {
  2079. warnStyleValueIsNaN(name, value);
  2080. } else if (!isFinite(value)) {
  2081. warnStyleValueIsInfinity(name, value);
  2082. }
  2083. }
  2084. };
  2085. }
  2086. var warnValidStyle$1 = warnValidStyle;
  2087. /**
  2088. * Operations for dealing with CSS properties.
  2089. */
  2090. /**
  2091. * This creates a string that is expected to be equivalent to the style
  2092. * attribute generated by server-side rendering. It by-passes warnings and
  2093. * security checks so it's not safe to use this value for anything other than
  2094. * comparison. It is only used in DEV for SSR validation.
  2095. */
  2096. function createDangerousStringForStyles(styles) {
  2097. {
  2098. var serialized = '';
  2099. var delimiter = '';
  2100. for (var styleName in styles) {
  2101. if (!styles.hasOwnProperty(styleName)) {
  2102. continue;
  2103. }
  2104. var styleValue = styles[styleName];
  2105. if (styleValue != null) {
  2106. var isCustomProperty = styleName.indexOf('--') === 0;
  2107. serialized += delimiter + (isCustomProperty ? styleName : hyphenateStyleName(styleName)) + ':';
  2108. serialized += dangerousStyleValue(styleName, styleValue, isCustomProperty);
  2109. delimiter = ';';
  2110. }
  2111. }
  2112. return serialized || null;
  2113. }
  2114. }
  2115. /**
  2116. * Sets the value for multiple styles on a node. If a value is specified as
  2117. * '' (empty string), the corresponding style property will be unset.
  2118. *
  2119. * @param {DOMElement} node
  2120. * @param {object} styles
  2121. */
  2122. function setValueForStyles(node, styles) {
  2123. var style = node.style;
  2124. for (var styleName in styles) {
  2125. if (!styles.hasOwnProperty(styleName)) {
  2126. continue;
  2127. }
  2128. var isCustomProperty = styleName.indexOf('--') === 0;
  2129. {
  2130. if (!isCustomProperty) {
  2131. warnValidStyle$1(styleName, styles[styleName]);
  2132. }
  2133. }
  2134. var styleValue = dangerousStyleValue(styleName, styles[styleName], isCustomProperty);
  2135. if (styleName === 'float') {
  2136. styleName = 'cssFloat';
  2137. }
  2138. if (isCustomProperty) {
  2139. style.setProperty(styleName, styleValue);
  2140. } else {
  2141. style[styleName] = styleValue;
  2142. }
  2143. }
  2144. }
  2145. function isValueEmpty(value) {
  2146. return value == null || typeof value === 'boolean' || value === '';
  2147. }
  2148. /**
  2149. * Given {color: 'red', overflow: 'hidden'} returns {
  2150. * color: 'color',
  2151. * overflowX: 'overflow',
  2152. * overflowY: 'overflow',
  2153. * }. This can be read as "the overflowY property was set by the overflow
  2154. * shorthand". That is, the values are the property that each was derived from.
  2155. */
  2156. function expandShorthandMap(styles) {
  2157. var expanded = {};
  2158. for (var key in styles) {
  2159. var longhands = shorthandToLonghand[key] || [key];
  2160. for (var i = 0; i < longhands.length; i++) {
  2161. expanded[longhands[i]] = key;
  2162. }
  2163. }
  2164. return expanded;
  2165. }
  2166. /**
  2167. * When mixing shorthand and longhand property names, we warn during updates if
  2168. * we expect an incorrect result to occur. In particular, we warn for:
  2169. *
  2170. * Updating a shorthand property (longhand gets overwritten):
  2171. * {font: 'foo', fontVariant: 'bar'} -> {font: 'baz', fontVariant: 'bar'}
  2172. * becomes .style.font = 'baz'
  2173. * Removing a shorthand property (longhand gets lost too):
  2174. * {font: 'foo', fontVariant: 'bar'} -> {fontVariant: 'bar'}
  2175. * becomes .style.font = ''
  2176. * Removing a longhand property (should revert to shorthand; doesn't):
  2177. * {font: 'foo', fontVariant: 'bar'} -> {font: 'foo'}
  2178. * becomes .style.fontVariant = ''
  2179. */
  2180. function validateShorthandPropertyCollisionInDev(styleUpdates, nextStyles) {
  2181. {
  2182. if (!nextStyles) {
  2183. return;
  2184. }
  2185. var expandedUpdates = expandShorthandMap(styleUpdates);
  2186. var expandedStyles = expandShorthandMap(nextStyles);
  2187. var warnedAbout = {};
  2188. for (var key in expandedUpdates) {
  2189. var originalKey = expandedUpdates[key];
  2190. var correctOriginalKey = expandedStyles[key];
  2191. if (correctOriginalKey && originalKey !== correctOriginalKey) {
  2192. var warningKey = originalKey + ',' + correctOriginalKey;
  2193. if (warnedAbout[warningKey]) {
  2194. continue;
  2195. }
  2196. warnedAbout[warningKey] = true;
  2197. error('%s a style property during rerender (%s) when a ' + 'conflicting property is set (%s) can lead to styling bugs. To ' + "avoid this, don't mix shorthand and non-shorthand properties " + 'for the same value; instead, replace the shorthand with ' + 'separate values.', isValueEmpty(styleUpdates[originalKey]) ? 'Removing' : 'Updating', originalKey, correctOriginalKey);
  2198. }
  2199. }
  2200. }
  2201. }
  2202. // For HTML, certain tags should omit their close tag. We keep a list for
  2203. // those special-case tags.
  2204. var omittedCloseTags = {
  2205. area: true,
  2206. base: true,
  2207. br: true,
  2208. col: true,
  2209. embed: true,
  2210. hr: true,
  2211. img: true,
  2212. input: true,
  2213. keygen: true,
  2214. link: true,
  2215. meta: true,
  2216. param: true,
  2217. source: true,
  2218. track: true,
  2219. wbr: true // NOTE: menuitem's close tag should be omitted, but that causes problems.
  2220. };
  2221. // `omittedCloseTags` except that `menuitem` should still have its closing tag.
  2222. var voidElementTags = _assign({
  2223. menuitem: true
  2224. }, omittedCloseTags);
  2225. var HTML = '__html';
  2226. function assertValidProps(tag, props) {
  2227. if (!props) {
  2228. return;
  2229. } // Note the use of `==` which checks for null or undefined.
  2230. if (voidElementTags[tag]) {
  2231. if (!(props.children == null && props.dangerouslySetInnerHTML == null)) {
  2232. {
  2233. throw Error( tag + " is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`." );
  2234. }
  2235. }
  2236. }
  2237. if (props.dangerouslySetInnerHTML != null) {
  2238. if (!(props.children == null)) {
  2239. {
  2240. throw Error( "Can only set one of `children` or `props.dangerouslySetInnerHTML`." );
  2241. }
  2242. }
  2243. if (!(typeof props.dangerouslySetInnerHTML === 'object' && HTML in props.dangerouslySetInnerHTML)) {
  2244. {
  2245. throw Error( "`props.dangerouslySetInnerHTML` must be in the form `{__html: ...}`. Please visit https://reactjs.org/link/dangerously-set-inner-html for more information." );
  2246. }
  2247. }
  2248. }
  2249. {
  2250. if (!props.suppressContentEditableWarning && props.contentEditable && props.children != null) {
  2251. error('A component is `contentEditable` and contains `children` managed by ' + 'React. It is now your responsibility to guarantee that none of ' + 'those nodes are unexpectedly modified or duplicated. This is ' + 'probably not intentional.');
  2252. }
  2253. }
  2254. if (!(props.style == null || typeof props.style === 'object')) {
  2255. {
  2256. throw Error( "The `style` prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX." );
  2257. }
  2258. }
  2259. }
  2260. function isCustomComponent(tagName, props) {
  2261. if (tagName.indexOf('-') === -1) {
  2262. return typeof props.is === 'string';
  2263. }
  2264. switch (tagName) {
  2265. // These are reserved SVG and MathML elements.
  2266. // We don't mind this list too much because we expect it to never grow.
  2267. // The alternative is to track the namespace in a few places which is convoluted.
  2268. // https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
  2269. case 'annotation-xml':
  2270. case 'color-profile':
  2271. case 'font-face':
  2272. case 'font-face-src':
  2273. case 'font-face-uri':
  2274. case 'font-face-format':
  2275. case 'font-face-name':
  2276. case 'missing-glyph':
  2277. return false;
  2278. default:
  2279. return true;
  2280. }
  2281. }
  2282. // When adding attributes to the HTML or SVG allowed attribute list, be sure to
  2283. // also add them to this module to ensure casing and incorrect name
  2284. // warnings.
  2285. var possibleStandardNames = {
  2286. // HTML
  2287. accept: 'accept',
  2288. acceptcharset: 'acceptCharset',
  2289. 'accept-charset': 'acceptCharset',
  2290. accesskey: 'accessKey',
  2291. action: 'action',
  2292. allowfullscreen: 'allowFullScreen',
  2293. alt: 'alt',
  2294. as: 'as',
  2295. async: 'async',
  2296. autocapitalize: 'autoCapitalize',
  2297. autocomplete: 'autoComplete',
  2298. autocorrect: 'autoCorrect',
  2299. autofocus: 'autoFocus',
  2300. autoplay: 'autoPlay',
  2301. autosave: 'autoSave',
  2302. capture: 'capture',
  2303. cellpadding: 'cellPadding',
  2304. cellspacing: 'cellSpacing',
  2305. challenge: 'challenge',
  2306. charset: 'charSet',
  2307. checked: 'checked',
  2308. children: 'children',
  2309. cite: 'cite',
  2310. class: 'className',
  2311. classid: 'classID',
  2312. classname: 'className',
  2313. cols: 'cols',
  2314. colspan: 'colSpan',
  2315. content: 'content',
  2316. contenteditable: 'contentEditable',
  2317. contextmenu: 'contextMenu',
  2318. controls: 'controls',
  2319. controlslist: 'controlsList',
  2320. coords: 'coords',
  2321. crossorigin: 'crossOrigin',
  2322. dangerouslysetinnerhtml: 'dangerouslySetInnerHTML',
  2323. data: 'data',
  2324. datetime: 'dateTime',
  2325. default: 'default',
  2326. defaultchecked: 'defaultChecked',
  2327. defaultvalue: 'defaultValue',
  2328. defer: 'defer',
  2329. dir: 'dir',
  2330. disabled: 'disabled',
  2331. disablepictureinpicture: 'disablePictureInPicture',
  2332. disableremoteplayback: 'disableRemotePlayback',
  2333. download: 'download',
  2334. draggable: 'draggable',
  2335. enctype: 'encType',
  2336. enterkeyhint: 'enterKeyHint',
  2337. for: 'htmlFor',
  2338. form: 'form',
  2339. formmethod: 'formMethod',
  2340. formaction: 'formAction',
  2341. formenctype: 'formEncType',
  2342. formnovalidate: 'formNoValidate',
  2343. formtarget: 'formTarget',
  2344. frameborder: 'frameBorder',
  2345. headers: 'headers',
  2346. height: 'height',
  2347. hidden: 'hidden',
  2348. high: 'high',
  2349. href: 'href',
  2350. hreflang: 'hrefLang',
  2351. htmlfor: 'htmlFor',
  2352. httpequiv: 'httpEquiv',
  2353. 'http-equiv': 'httpEquiv',
  2354. icon: 'icon',
  2355. id: 'id',
  2356. innerhtml: 'innerHTML',
  2357. inputmode: 'inputMode',
  2358. integrity: 'integrity',
  2359. is: 'is',
  2360. itemid: 'itemID',
  2361. itemprop: 'itemProp',
  2362. itemref: 'itemRef',
  2363. itemscope: 'itemScope',
  2364. itemtype: 'itemType',
  2365. keyparams: 'keyParams',
  2366. keytype: 'keyType',
  2367. kind: 'kind',
  2368. label: 'label',
  2369. lang: 'lang',
  2370. list: 'list',
  2371. loop: 'loop',
  2372. low: 'low',
  2373. manifest: 'manifest',
  2374. marginwidth: 'marginWidth',
  2375. marginheight: 'marginHeight',
  2376. max: 'max',
  2377. maxlength: 'maxLength',
  2378. media: 'media',
  2379. mediagroup: 'mediaGroup',
  2380. method: 'method',
  2381. min: 'min',
  2382. minlength: 'minLength',
  2383. multiple: 'multiple',
  2384. muted: 'muted',
  2385. name: 'name',
  2386. nomodule: 'noModule',
  2387. nonce: 'nonce',
  2388. novalidate: 'noValidate',
  2389. open: 'open',
  2390. optimum: 'optimum',
  2391. pattern: 'pattern',
  2392. placeholder: 'placeholder',
  2393. playsinline: 'playsInline',
  2394. poster: 'poster',
  2395. preload: 'preload',
  2396. profile: 'profile',
  2397. radiogroup: 'radioGroup',
  2398. readonly: 'readOnly',
  2399. referrerpolicy: 'referrerPolicy',
  2400. rel: 'rel',
  2401. required: 'required',
  2402. reversed: 'reversed',
  2403. role: 'role',
  2404. rows: 'rows',
  2405. rowspan: 'rowSpan',
  2406. sandbox: 'sandbox',
  2407. scope: 'scope',
  2408. scoped: 'scoped',
  2409. scrolling: 'scrolling',
  2410. seamless: 'seamless',
  2411. selected: 'selected',
  2412. shape: 'shape',
  2413. size: 'size',
  2414. sizes: 'sizes',
  2415. span: 'span',
  2416. spellcheck: 'spellCheck',
  2417. src: 'src',
  2418. srcdoc: 'srcDoc',
  2419. srclang: 'srcLang',
  2420. srcset: 'srcSet',
  2421. start: 'start',
  2422. step: 'step',
  2423. style: 'style',
  2424. summary: 'summary',
  2425. tabindex: 'tabIndex',
  2426. target: 'target',
  2427. title: 'title',
  2428. type: 'type',
  2429. usemap: 'useMap',
  2430. value: 'value',
  2431. width: 'width',
  2432. wmode: 'wmode',
  2433. wrap: 'wrap',
  2434. // SVG
  2435. about: 'about',
  2436. accentheight: 'accentHeight',
  2437. 'accent-height': 'accentHeight',
  2438. accumulate: 'accumulate',
  2439. additive: 'additive',
  2440. alignmentbaseline: 'alignmentBaseline',
  2441. 'alignment-baseline': 'alignmentBaseline',
  2442. allowreorder: 'allowReorder',
  2443. alphabetic: 'alphabetic',
  2444. amplitude: 'amplitude',
  2445. arabicform: 'arabicForm',
  2446. 'arabic-form': 'arabicForm',
  2447. ascent: 'ascent',
  2448. attributename: 'attributeName',
  2449. attributetype: 'attributeType',
  2450. autoreverse: 'autoReverse',
  2451. azimuth: 'azimuth',
  2452. basefrequency: 'baseFrequency',
  2453. baselineshift: 'baselineShift',
  2454. 'baseline-shift': 'baselineShift',
  2455. baseprofile: 'baseProfile',
  2456. bbox: 'bbox',
  2457. begin: 'begin',
  2458. bias: 'bias',
  2459. by: 'by',
  2460. calcmode: 'calcMode',
  2461. capheight: 'capHeight',
  2462. 'cap-height': 'capHeight',
  2463. clip: 'clip',
  2464. clippath: 'clipPath',
  2465. 'clip-path': 'clipPath',
  2466. clippathunits: 'clipPathUnits',
  2467. cliprule: 'clipRule',
  2468. 'clip-rule': 'clipRule',
  2469. color: 'color',
  2470. colorinterpolation: 'colorInterpolation',
  2471. 'color-interpolation': 'colorInterpolation',
  2472. colorinterpolationfilters: 'colorInterpolationFilters',
  2473. 'color-interpolation-filters': 'colorInterpolationFilters',
  2474. colorprofile: 'colorProfile',
  2475. 'color-profile': 'colorProfile',
  2476. colorrendering: 'colorRendering',
  2477. 'color-rendering': 'colorRendering',
  2478. contentscripttype: 'contentScriptType',
  2479. contentstyletype: 'contentStyleType',
  2480. cursor: 'cursor',
  2481. cx: 'cx',
  2482. cy: 'cy',
  2483. d: 'd',
  2484. datatype: 'datatype',
  2485. decelerate: 'decelerate',
  2486. descent: 'descent',
  2487. diffuseconstant: 'diffuseConstant',
  2488. direction: 'direction',
  2489. display: 'display',
  2490. divisor: 'divisor',
  2491. dominantbaseline: 'dominantBaseline',
  2492. 'dominant-baseline': 'dominantBaseline',
  2493. dur: 'dur',
  2494. dx: 'dx',
  2495. dy: 'dy',
  2496. edgemode: 'edgeMode',
  2497. elevation: 'elevation',
  2498. enablebackground: 'enableBackground',
  2499. 'enable-background': 'enableBackground',
  2500. end: 'end',
  2501. exponent: 'exponent',
  2502. externalresourcesrequired: 'externalResourcesRequired',
  2503. fill: 'fill',
  2504. fillopacity: 'fillOpacity',
  2505. 'fill-opacity': 'fillOpacity',
  2506. fillrule: 'fillRule',
  2507. 'fill-rule': 'fillRule',
  2508. filter: 'filter',
  2509. filterres: 'filterRes',
  2510. filterunits: 'filterUnits',
  2511. floodopacity: 'floodOpacity',
  2512. 'flood-opacity': 'floodOpacity',
  2513. floodcolor: 'floodColor',
  2514. 'flood-color': 'floodColor',
  2515. focusable: 'focusable',
  2516. fontfamily: 'fontFamily',
  2517. 'font-family': 'fontFamily',
  2518. fontsize: 'fontSize',
  2519. 'font-size': 'fontSize',
  2520. fontsizeadjust: 'fontSizeAdjust',
  2521. 'font-size-adjust': 'fontSizeAdjust',
  2522. fontstretch: 'fontStretch',
  2523. 'font-stretch': 'fontStretch',
  2524. fontstyle: 'fontStyle',
  2525. 'font-style': 'fontStyle',
  2526. fontvariant: 'fontVariant',
  2527. 'font-variant': 'fontVariant',
  2528. fontweight: 'fontWeight',
  2529. 'font-weight': 'fontWeight',
  2530. format: 'format',
  2531. from: 'from',
  2532. fx: 'fx',
  2533. fy: 'fy',
  2534. g1: 'g1',
  2535. g2: 'g2',
  2536. glyphname: 'glyphName',
  2537. 'glyph-name': 'glyphName',
  2538. glyphorientationhorizontal: 'glyphOrientationHorizontal',
  2539. 'glyph-orientation-horizontal': 'glyphOrientationHorizontal',
  2540. glyphorientationvertical: 'glyphOrientationVertical',
  2541. 'glyph-orientation-vertical': 'glyphOrientationVertical',
  2542. glyphref: 'glyphRef',
  2543. gradienttransform: 'gradientTransform',
  2544. gradientunits: 'gradientUnits',
  2545. hanging: 'hanging',
  2546. horizadvx: 'horizAdvX',
  2547. 'horiz-adv-x': 'horizAdvX',
  2548. horizoriginx: 'horizOriginX',
  2549. 'horiz-origin-x': 'horizOriginX',
  2550. ideographic: 'ideographic',
  2551. imagerendering: 'imageRendering',
  2552. 'image-rendering': 'imageRendering',
  2553. in2: 'in2',
  2554. in: 'in',
  2555. inlist: 'inlist',
  2556. intercept: 'intercept',
  2557. k1: 'k1',
  2558. k2: 'k2',
  2559. k3: 'k3',
  2560. k4: 'k4',
  2561. k: 'k',
  2562. kernelmatrix: 'kernelMatrix',
  2563. kernelunitlength: 'kernelUnitLength',
  2564. kerning: 'kerning',
  2565. keypoints: 'keyPoints',
  2566. keysplines: 'keySplines',
  2567. keytimes: 'keyTimes',
  2568. lengthadjust: 'lengthAdjust',
  2569. letterspacing: 'letterSpacing',
  2570. 'letter-spacing': 'letterSpacing',
  2571. lightingcolor: 'lightingColor',
  2572. 'lighting-color': 'lightingColor',
  2573. limitingconeangle: 'limitingConeAngle',
  2574. local: 'local',
  2575. markerend: 'markerEnd',
  2576. 'marker-end': 'markerEnd',
  2577. markerheight: 'markerHeight',
  2578. markermid: 'markerMid',
  2579. 'marker-mid': 'markerMid',
  2580. markerstart: 'markerStart',
  2581. 'marker-start': 'markerStart',
  2582. markerunits: 'markerUnits',
  2583. markerwidth: 'markerWidth',
  2584. mask: 'mask',
  2585. maskcontentunits: 'maskContentUnits',
  2586. maskunits: 'maskUnits',
  2587. mathematical: 'mathematical',
  2588. mode: 'mode',
  2589. numoctaves: 'numOctaves',
  2590. offset: 'offset',
  2591. opacity: 'opacity',
  2592. operator: 'operator',
  2593. order: 'order',
  2594. orient: 'orient',
  2595. orientation: 'orientation',
  2596. origin: 'origin',
  2597. overflow: 'overflow',
  2598. overlineposition: 'overlinePosition',
  2599. 'overline-position': 'overlinePosition',
  2600. overlinethickness: 'overlineThickness',
  2601. 'overline-thickness': 'overlineThickness',
  2602. paintorder: 'paintOrder',
  2603. 'paint-order': 'paintOrder',
  2604. panose1: 'panose1',
  2605. 'panose-1': 'panose1',
  2606. pathlength: 'pathLength',
  2607. patterncontentunits: 'patternContentUnits',
  2608. patterntransform: 'patternTransform',
  2609. patternunits: 'patternUnits',
  2610. pointerevents: 'pointerEvents',
  2611. 'pointer-events': 'pointerEvents',
  2612. points: 'points',
  2613. pointsatx: 'pointsAtX',
  2614. pointsaty: 'pointsAtY',
  2615. pointsatz: 'pointsAtZ',
  2616. prefix: 'prefix',
  2617. preservealpha: 'preserveAlpha',
  2618. preserveaspectratio: 'preserveAspectRatio',
  2619. primitiveunits: 'primitiveUnits',
  2620. property: 'property',
  2621. r: 'r',
  2622. radius: 'radius',
  2623. refx: 'refX',
  2624. refy: 'refY',
  2625. renderingintent: 'renderingIntent',
  2626. 'rendering-intent': 'renderingIntent',
  2627. repeatcount: 'repeatCount',
  2628. repeatdur: 'repeatDur',
  2629. requiredextensions: 'requiredExtensions',
  2630. requiredfeatures: 'requiredFeatures',
  2631. resource: 'resource',
  2632. restart: 'restart',
  2633. result: 'result',
  2634. results: 'results',
  2635. rotate: 'rotate',
  2636. rx: 'rx',
  2637. ry: 'ry',
  2638. scale: 'scale',
  2639. security: 'security',
  2640. seed: 'seed',
  2641. shaperendering: 'shapeRendering',
  2642. 'shape-rendering': 'shapeRendering',
  2643. slope: 'slope',
  2644. spacing: 'spacing',
  2645. specularconstant: 'specularConstant',
  2646. specularexponent: 'specularExponent',
  2647. speed: 'speed',
  2648. spreadmethod: 'spreadMethod',
  2649. startoffset: 'startOffset',
  2650. stddeviation: 'stdDeviation',
  2651. stemh: 'stemh',
  2652. stemv: 'stemv',
  2653. stitchtiles: 'stitchTiles',
  2654. stopcolor: 'stopColor',
  2655. 'stop-color': 'stopColor',
  2656. stopopacity: 'stopOpacity',
  2657. 'stop-opacity': 'stopOpacity',
  2658. strikethroughposition: 'strikethroughPosition',
  2659. 'strikethrough-position': 'strikethroughPosition',
  2660. strikethroughthickness: 'strikethroughThickness',
  2661. 'strikethrough-thickness': 'strikethroughThickness',
  2662. string: 'string',
  2663. stroke: 'stroke',
  2664. strokedasharray: 'strokeDasharray',
  2665. 'stroke-dasharray': 'strokeDasharray',
  2666. strokedashoffset: 'strokeDashoffset',
  2667. 'stroke-dashoffset': 'strokeDashoffset',
  2668. strokelinecap: 'strokeLinecap',
  2669. 'stroke-linecap': 'strokeLinecap',
  2670. strokelinejoin: 'strokeLinejoin',
  2671. 'stroke-linejoin': 'strokeLinejoin',
  2672. strokemiterlimit: 'strokeMiterlimit',
  2673. 'stroke-miterlimit': 'strokeMiterlimit',
  2674. strokewidth: 'strokeWidth',
  2675. 'stroke-width': 'strokeWidth',
  2676. strokeopacity: 'strokeOpacity',
  2677. 'stroke-opacity': 'strokeOpacity',
  2678. suppresscontenteditablewarning: 'suppressContentEditableWarning',
  2679. suppresshydrationwarning: 'suppressHydrationWarning',
  2680. surfacescale: 'surfaceScale',
  2681. systemlanguage: 'systemLanguage',
  2682. tablevalues: 'tableValues',
  2683. targetx: 'targetX',
  2684. targety: 'targetY',
  2685. textanchor: 'textAnchor',
  2686. 'text-anchor': 'textAnchor',
  2687. textdecoration: 'textDecoration',
  2688. 'text-decoration': 'textDecoration',
  2689. textlength: 'textLength',
  2690. textrendering: 'textRendering',
  2691. 'text-rendering': 'textRendering',
  2692. to: 'to',
  2693. transform: 'transform',
  2694. typeof: 'typeof',
  2695. u1: 'u1',
  2696. u2: 'u2',
  2697. underlineposition: 'underlinePosition',
  2698. 'underline-position': 'underlinePosition',
  2699. underlinethickness: 'underlineThickness',
  2700. 'underline-thickness': 'underlineThickness',
  2701. unicode: 'unicode',
  2702. unicodebidi: 'unicodeBidi',
  2703. 'unicode-bidi': 'unicodeBidi',
  2704. unicoderange: 'unicodeRange',
  2705. 'unicode-range': 'unicodeRange',
  2706. unitsperem: 'unitsPerEm',
  2707. 'units-per-em': 'unitsPerEm',
  2708. unselectable: 'unselectable',
  2709. valphabetic: 'vAlphabetic',
  2710. 'v-alphabetic': 'vAlphabetic',
  2711. values: 'values',
  2712. vectoreffect: 'vectorEffect',
  2713. 'vector-effect': 'vectorEffect',
  2714. version: 'version',
  2715. vertadvy: 'vertAdvY',
  2716. 'vert-adv-y': 'vertAdvY',
  2717. vertoriginx: 'vertOriginX',
  2718. 'vert-origin-x': 'vertOriginX',
  2719. vertoriginy: 'vertOriginY',
  2720. 'vert-origin-y': 'vertOriginY',
  2721. vhanging: 'vHanging',
  2722. 'v-hanging': 'vHanging',
  2723. videographic: 'vIdeographic',
  2724. 'v-ideographic': 'vIdeographic',
  2725. viewbox: 'viewBox',
  2726. viewtarget: 'viewTarget',
  2727. visibility: 'visibility',
  2728. vmathematical: 'vMathematical',
  2729. 'v-mathematical': 'vMathematical',
  2730. vocab: 'vocab',
  2731. widths: 'widths',
  2732. wordspacing: 'wordSpacing',
  2733. 'word-spacing': 'wordSpacing',
  2734. writingmode: 'writingMode',
  2735. 'writing-mode': 'writingMode',
  2736. x1: 'x1',
  2737. x2: 'x2',
  2738. x: 'x',
  2739. xchannelselector: 'xChannelSelector',
  2740. xheight: 'xHeight',
  2741. 'x-height': 'xHeight',
  2742. xlinkactuate: 'xlinkActuate',
  2743. 'xlink:actuate': 'xlinkActuate',
  2744. xlinkarcrole: 'xlinkArcrole',
  2745. 'xlink:arcrole': 'xlinkArcrole',
  2746. xlinkhref: 'xlinkHref',
  2747. 'xlink:href': 'xlinkHref',
  2748. xlinkrole: 'xlinkRole',
  2749. 'xlink:role': 'xlinkRole',
  2750. xlinkshow: 'xlinkShow',
  2751. 'xlink:show': 'xlinkShow',
  2752. xlinktitle: 'xlinkTitle',
  2753. 'xlink:title': 'xlinkTitle',
  2754. xlinktype: 'xlinkType',
  2755. 'xlink:type': 'xlinkType',
  2756. xmlbase: 'xmlBase',
  2757. 'xml:base': 'xmlBase',
  2758. xmllang: 'xmlLang',
  2759. 'xml:lang': 'xmlLang',
  2760. xmlns: 'xmlns',
  2761. 'xml:space': 'xmlSpace',
  2762. xmlnsxlink: 'xmlnsXlink',
  2763. 'xmlns:xlink': 'xmlnsXlink',
  2764. xmlspace: 'xmlSpace',
  2765. y1: 'y1',
  2766. y2: 'y2',
  2767. y: 'y',
  2768. ychannelselector: 'yChannelSelector',
  2769. z: 'z',
  2770. zoomandpan: 'zoomAndPan'
  2771. };
  2772. var ariaProperties = {
  2773. 'aria-current': 0,
  2774. // state
  2775. 'aria-details': 0,
  2776. 'aria-disabled': 0,
  2777. // state
  2778. 'aria-hidden': 0,
  2779. // state
  2780. 'aria-invalid': 0,
  2781. // state
  2782. 'aria-keyshortcuts': 0,
  2783. 'aria-label': 0,
  2784. 'aria-roledescription': 0,
  2785. // Widget Attributes
  2786. 'aria-autocomplete': 0,
  2787. 'aria-checked': 0,
  2788. 'aria-expanded': 0,
  2789. 'aria-haspopup': 0,
  2790. 'aria-level': 0,
  2791. 'aria-modal': 0,
  2792. 'aria-multiline': 0,
  2793. 'aria-multiselectable': 0,
  2794. 'aria-orientation': 0,
  2795. 'aria-placeholder': 0,
  2796. 'aria-pressed': 0,
  2797. 'aria-readonly': 0,
  2798. 'aria-required': 0,
  2799. 'aria-selected': 0,
  2800. 'aria-sort': 0,
  2801. 'aria-valuemax': 0,
  2802. 'aria-valuemin': 0,
  2803. 'aria-valuenow': 0,
  2804. 'aria-valuetext': 0,
  2805. // Live Region Attributes
  2806. 'aria-atomic': 0,
  2807. 'aria-busy': 0,
  2808. 'aria-live': 0,
  2809. 'aria-relevant': 0,
  2810. // Drag-and-Drop Attributes
  2811. 'aria-dropeffect': 0,
  2812. 'aria-grabbed': 0,
  2813. // Relationship Attributes
  2814. 'aria-activedescendant': 0,
  2815. 'aria-colcount': 0,
  2816. 'aria-colindex': 0,
  2817. 'aria-colspan': 0,
  2818. 'aria-controls': 0,
  2819. 'aria-describedby': 0,
  2820. 'aria-errormessage': 0,
  2821. 'aria-flowto': 0,
  2822. 'aria-labelledby': 0,
  2823. 'aria-owns': 0,
  2824. 'aria-posinset': 0,
  2825. 'aria-rowcount': 0,
  2826. 'aria-rowindex': 0,
  2827. 'aria-rowspan': 0,
  2828. 'aria-setsize': 0
  2829. };
  2830. var warnedProperties = {};
  2831. var rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
  2832. var rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
  2833. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  2834. function validateProperty(tagName, name) {
  2835. {
  2836. if (hasOwnProperty$1.call(warnedProperties, name) && warnedProperties[name]) {
  2837. return true;
  2838. }
  2839. if (rARIACamel.test(name)) {
  2840. var ariaName = 'aria-' + name.slice(4).toLowerCase();
  2841. var correctName = ariaProperties.hasOwnProperty(ariaName) ? ariaName : null; // If this is an aria-* attribute, but is not listed in the known DOM
  2842. // DOM properties, then it is an invalid aria-* attribute.
  2843. if (correctName == null) {
  2844. error('Invalid ARIA attribute `%s`. ARIA attributes follow the pattern aria-* and must be lowercase.', name);
  2845. warnedProperties[name] = true;
  2846. return true;
  2847. } // aria-* attributes should be lowercase; suggest the lowercase version.
  2848. if (name !== correctName) {
  2849. error('Invalid ARIA attribute `%s`. Did you mean `%s`?', name, correctName);
  2850. warnedProperties[name] = true;
  2851. return true;
  2852. }
  2853. }
  2854. if (rARIA.test(name)) {
  2855. var lowerCasedName = name.toLowerCase();
  2856. var standardName = ariaProperties.hasOwnProperty(lowerCasedName) ? lowerCasedName : null; // If this is an aria-* attribute, but is not listed in the known DOM
  2857. // DOM properties, then it is an invalid aria-* attribute.
  2858. if (standardName == null) {
  2859. warnedProperties[name] = true;
  2860. return false;
  2861. } // aria-* attributes should be lowercase; suggest the lowercase version.
  2862. if (name !== standardName) {
  2863. error('Unknown ARIA attribute `%s`. Did you mean `%s`?', name, standardName);
  2864. warnedProperties[name] = true;
  2865. return true;
  2866. }
  2867. }
  2868. }
  2869. return true;
  2870. }
  2871. function warnInvalidARIAProps(type, props) {
  2872. {
  2873. var invalidProps = [];
  2874. for (var key in props) {
  2875. var isValid = validateProperty(type, key);
  2876. if (!isValid) {
  2877. invalidProps.push(key);
  2878. }
  2879. }
  2880. var unknownPropString = invalidProps.map(function (prop) {
  2881. return '`' + prop + '`';
  2882. }).join(', ');
  2883. if (invalidProps.length === 1) {
  2884. error('Invalid aria prop %s on <%s> tag. ' + 'For details, see https://reactjs.org/link/invalid-aria-props', unknownPropString, type);
  2885. } else if (invalidProps.length > 1) {
  2886. error('Invalid aria props %s on <%s> tag. ' + 'For details, see https://reactjs.org/link/invalid-aria-props', unknownPropString, type);
  2887. }
  2888. }
  2889. }
  2890. function validateProperties(type, props) {
  2891. if (isCustomComponent(type, props)) {
  2892. return;
  2893. }
  2894. warnInvalidARIAProps(type, props);
  2895. }
  2896. var didWarnValueNull = false;
  2897. function validateProperties$1(type, props) {
  2898. {
  2899. if (type !== 'input' && type !== 'textarea' && type !== 'select') {
  2900. return;
  2901. }
  2902. if (props != null && props.value === null && !didWarnValueNull) {
  2903. didWarnValueNull = true;
  2904. if (type === 'select' && props.multiple) {
  2905. error('`value` prop on `%s` should not be null. ' + 'Consider using an empty array when `multiple` is set to `true` ' + 'to clear the component or `undefined` for uncontrolled components.', type);
  2906. } else {
  2907. error('`value` prop on `%s` should not be null. ' + 'Consider using an empty string to clear the component or `undefined` ' + 'for uncontrolled components.', type);
  2908. }
  2909. }
  2910. }
  2911. }
  2912. var validateProperty$1 = function () {};
  2913. {
  2914. var warnedProperties$1 = {};
  2915. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  2916. var EVENT_NAME_REGEX = /^on./;
  2917. var INVALID_EVENT_NAME_REGEX = /^on[^A-Z]/;
  2918. var rARIA$1 = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
  2919. var rARIACamel$1 = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
  2920. validateProperty$1 = function (tagName, name, value, eventRegistry) {
  2921. if (_hasOwnProperty.call(warnedProperties$1, name) && warnedProperties$1[name]) {
  2922. return true;
  2923. }
  2924. var lowerCasedName = name.toLowerCase();
  2925. if (lowerCasedName === 'onfocusin' || lowerCasedName === 'onfocusout') {
  2926. error('React uses onFocus and onBlur instead of onFocusIn and onFocusOut. ' + 'All React events are normalized to bubble, so onFocusIn and onFocusOut ' + 'are not needed/supported by React.');
  2927. warnedProperties$1[name] = true;
  2928. return true;
  2929. } // We can't rely on the event system being injected on the server.
  2930. if (eventRegistry != null) {
  2931. var registrationNameDependencies = eventRegistry.registrationNameDependencies,
  2932. possibleRegistrationNames = eventRegistry.possibleRegistrationNames;
  2933. if (registrationNameDependencies.hasOwnProperty(name)) {
  2934. return true;
  2935. }
  2936. var registrationName = possibleRegistrationNames.hasOwnProperty(lowerCasedName) ? possibleRegistrationNames[lowerCasedName] : null;
  2937. if (registrationName != null) {
  2938. error('Invalid event handler property `%s`. Did you mean `%s`?', name, registrationName);
  2939. warnedProperties$1[name] = true;
  2940. return true;
  2941. }
  2942. if (EVENT_NAME_REGEX.test(name)) {
  2943. error('Unknown event handler property `%s`. It will be ignored.', name);
  2944. warnedProperties$1[name] = true;
  2945. return true;
  2946. }
  2947. } else if (EVENT_NAME_REGEX.test(name)) {
  2948. // If no event plugins have been injected, we are in a server environment.
  2949. // So we can't tell if the event name is correct for sure, but we can filter
  2950. // out known bad ones like `onclick`. We can't suggest a specific replacement though.
  2951. if (INVALID_EVENT_NAME_REGEX.test(name)) {
  2952. error('Invalid event handler property `%s`. ' + 'React events use the camelCase naming convention, for example `onClick`.', name);
  2953. }
  2954. warnedProperties$1[name] = true;
  2955. return true;
  2956. } // Let the ARIA attribute hook validate ARIA attributes
  2957. if (rARIA$1.test(name) || rARIACamel$1.test(name)) {
  2958. return true;
  2959. }
  2960. if (lowerCasedName === 'innerhtml') {
  2961. error('Directly setting property `innerHTML` is not permitted. ' + 'For more information, lookup documentation on `dangerouslySetInnerHTML`.');
  2962. warnedProperties$1[name] = true;
  2963. return true;
  2964. }
  2965. if (lowerCasedName === 'aria') {
  2966. error('The `aria` attribute is reserved for future use in React. ' + 'Pass individual `aria-` attributes instead.');
  2967. warnedProperties$1[name] = true;
  2968. return true;
  2969. }
  2970. if (lowerCasedName === 'is' && value !== null && value !== undefined && typeof value !== 'string') {
  2971. error('Received a `%s` for a string attribute `is`. If this is expected, cast ' + 'the value to a string.', typeof value);
  2972. warnedProperties$1[name] = true;
  2973. return true;
  2974. }
  2975. if (typeof value === 'number' && isNaN(value)) {
  2976. error('Received NaN for the `%s` attribute. If this is expected, cast ' + 'the value to a string.', name);
  2977. warnedProperties$1[name] = true;
  2978. return true;
  2979. }
  2980. var propertyInfo = getPropertyInfo(name);
  2981. var isReserved = propertyInfo !== null && propertyInfo.type === RESERVED; // Known attributes should match the casing specified in the property config.
  2982. if (possibleStandardNames.hasOwnProperty(lowerCasedName)) {
  2983. var standardName = possibleStandardNames[lowerCasedName];
  2984. if (standardName !== name) {
  2985. error('Invalid DOM property `%s`. Did you mean `%s`?', name, standardName);
  2986. warnedProperties$1[name] = true;
  2987. return true;
  2988. }
  2989. } else if (!isReserved && name !== lowerCasedName) {
  2990. // Unknown attributes should have lowercase casing since that's how they
  2991. // will be cased anyway with server rendering.
  2992. error('React does not recognize the `%s` prop on a DOM element. If you ' + 'intentionally want it to appear in the DOM as a custom ' + 'attribute, spell it as lowercase `%s` instead. ' + 'If you accidentally passed it from a parent component, remove ' + 'it from the DOM element.', name, lowerCasedName);
  2993. warnedProperties$1[name] = true;
  2994. return true;
  2995. }
  2996. if (typeof value === 'boolean' && shouldRemoveAttributeWithWarning(name, value, propertyInfo, false)) {
  2997. if (value) {
  2998. error('Received `%s` for a non-boolean attribute `%s`.\n\n' + 'If you want to write it to the DOM, pass a string instead: ' + '%s="%s" or %s={value.toString()}.', value, name, name, value, name);
  2999. } else {
  3000. error('Received `%s` for a non-boolean attribute `%s`.\n\n' + 'If you want to write it to the DOM, pass a string instead: ' + '%s="%s" or %s={value.toString()}.\n\n' + 'If you used to conditionally omit it with %s={condition && value}, ' + 'pass %s={condition ? value : undefined} instead.', value, name, name, value, name, name, name);
  3001. }
  3002. warnedProperties$1[name] = true;
  3003. return true;
  3004. } // Now that we've validated casing, do not validate
  3005. // data types for reserved props
  3006. if (isReserved) {
  3007. return true;
  3008. } // Warn when a known attribute is a bad type
  3009. if (shouldRemoveAttributeWithWarning(name, value, propertyInfo, false)) {
  3010. warnedProperties$1[name] = true;
  3011. return false;
  3012. } // Warn when passing the strings 'false' or 'true' into a boolean prop
  3013. if ((value === 'false' || value === 'true') && propertyInfo !== null && propertyInfo.type === BOOLEAN) {
  3014. error('Received the string `%s` for the boolean attribute `%s`. ' + '%s ' + 'Did you mean %s={%s}?', value, name, value === 'false' ? 'The browser will interpret it as a truthy value.' : 'Although this works, it will not work as expected if you pass the string "false".', name, value);
  3015. warnedProperties$1[name] = true;
  3016. return true;
  3017. }
  3018. return true;
  3019. };
  3020. }
  3021. var warnUnknownProperties = function (type, props, eventRegistry) {
  3022. {
  3023. var unknownProps = [];
  3024. for (var key in props) {
  3025. var isValid = validateProperty$1(type, key, props[key], eventRegistry);
  3026. if (!isValid) {
  3027. unknownProps.push(key);
  3028. }
  3029. }
  3030. var unknownPropString = unknownProps.map(function (prop) {
  3031. return '`' + prop + '`';
  3032. }).join(', ');
  3033. if (unknownProps.length === 1) {
  3034. error('Invalid value for prop %s on <%s> tag. Either remove it from the element, ' + 'or pass a string or number value to keep it in the DOM. ' + 'For details, see https://reactjs.org/link/attribute-behavior ', unknownPropString, type);
  3035. } else if (unknownProps.length > 1) {
  3036. error('Invalid values for props %s on <%s> tag. Either remove them from the element, ' + 'or pass a string or number value to keep them in the DOM. ' + 'For details, see https://reactjs.org/link/attribute-behavior ', unknownPropString, type);
  3037. }
  3038. }
  3039. };
  3040. function validateProperties$2(type, props, eventRegistry) {
  3041. if (isCustomComponent(type, props)) {
  3042. return;
  3043. }
  3044. warnUnknownProperties(type, props, eventRegistry);
  3045. }
  3046. var IS_EVENT_HANDLE_NON_MANAGED_NODE = 1;
  3047. var IS_NON_DELEGATED = 1 << 1;
  3048. var IS_CAPTURE_PHASE = 1 << 2;
  3049. var IS_REPLAYED = 1 << 4;
  3050. // set to LEGACY_FB_SUPPORT. LEGACY_FB_SUPPORT only gets set when
  3051. // we call willDeferLaterForLegacyFBSupport, thus not bailing out
  3052. // will result in endless cycles like an infinite loop.
  3053. // We also don't want to defer during event replaying.
  3054. var SHOULD_NOT_PROCESS_POLYFILL_EVENT_PLUGINS = IS_EVENT_HANDLE_NON_MANAGED_NODE | IS_NON_DELEGATED | IS_CAPTURE_PHASE;
  3055. /**
  3056. * Gets the target node from a native browser event by accounting for
  3057. * inconsistencies in browser DOM APIs.
  3058. *
  3059. * @param {object} nativeEvent Native browser event.
  3060. * @return {DOMEventTarget} Target node.
  3061. */
  3062. function getEventTarget(nativeEvent) {
  3063. // Fallback to nativeEvent.srcElement for IE9
  3064. // https://github.com/facebook/react/issues/12506
  3065. var target = nativeEvent.target || nativeEvent.srcElement || window; // Normalize SVG <use> element events #4963
  3066. if (target.correspondingUseElement) {
  3067. target = target.correspondingUseElement;
  3068. } // Safari may fire events on text nodes (Node.TEXT_NODE is 3).
  3069. // @see http://www.quirksmode.org/js/events_properties.html
  3070. return target.nodeType === TEXT_NODE ? target.parentNode : target;
  3071. }
  3072. var restoreImpl = null;
  3073. var restoreTarget = null;
  3074. var restoreQueue = null;
  3075. function restoreStateOfTarget(target) {
  3076. // We perform this translation at the end of the event loop so that we
  3077. // always receive the correct fiber here
  3078. var internalInstance = getInstanceFromNode(target);
  3079. if (!internalInstance) {
  3080. // Unmounted
  3081. return;
  3082. }
  3083. if (!(typeof restoreImpl === 'function')) {
  3084. {
  3085. throw Error( "setRestoreImplementation() needs to be called to handle a target for controlled events. This error is likely caused by a bug in React. Please file an issue." );
  3086. }
  3087. }
  3088. var stateNode = internalInstance.stateNode; // Guard against Fiber being unmounted.
  3089. if (stateNode) {
  3090. var _props = getFiberCurrentPropsFromNode(stateNode);
  3091. restoreImpl(internalInstance.stateNode, internalInstance.type, _props);
  3092. }
  3093. }
  3094. function setRestoreImplementation(impl) {
  3095. restoreImpl = impl;
  3096. }
  3097. function enqueueStateRestore(target) {
  3098. if (restoreTarget) {
  3099. if (restoreQueue) {
  3100. restoreQueue.push(target);
  3101. } else {
  3102. restoreQueue = [target];
  3103. }
  3104. } else {
  3105. restoreTarget = target;
  3106. }
  3107. }
  3108. function needsStateRestore() {
  3109. return restoreTarget !== null || restoreQueue !== null;
  3110. }
  3111. function restoreStateIfNeeded() {
  3112. if (!restoreTarget) {
  3113. return;
  3114. }
  3115. var target = restoreTarget;
  3116. var queuedTargets = restoreQueue;
  3117. restoreTarget = null;
  3118. restoreQueue = null;
  3119. restoreStateOfTarget(target);
  3120. if (queuedTargets) {
  3121. for (var i = 0; i < queuedTargets.length; i++) {
  3122. restoreStateOfTarget(queuedTargets[i]);
  3123. }
  3124. }
  3125. }
  3126. // the renderer. Such as when we're dispatching events or if third party
  3127. // libraries need to call batchedUpdates. Eventually, this API will go away when
  3128. // everything is batched by default. We'll then have a similar API to opt-out of
  3129. // scheduled work and instead do synchronous work.
  3130. // Defaults
  3131. var batchedUpdatesImpl = function (fn, bookkeeping) {
  3132. return fn(bookkeeping);
  3133. };
  3134. var discreteUpdatesImpl = function (fn, a, b, c, d) {
  3135. return fn(a, b, c, d);
  3136. };
  3137. var flushDiscreteUpdatesImpl = function () {};
  3138. var batchedEventUpdatesImpl = batchedUpdatesImpl;
  3139. var isInsideEventHandler = false;
  3140. var isBatchingEventUpdates = false;
  3141. function finishEventHandler() {
  3142. // Here we wait until all updates have propagated, which is important
  3143. // when using controlled components within layers:
  3144. // https://github.com/facebook/react/issues/1698
  3145. // Then we restore state of any controlled component.
  3146. var controlledComponentsHavePendingUpdates = needsStateRestore();
  3147. if (controlledComponentsHavePendingUpdates) {
  3148. // If a controlled event was fired, we may need to restore the state of
  3149. // the DOM node back to the controlled value. This is necessary when React
  3150. // bails out of the update without touching the DOM.
  3151. flushDiscreteUpdatesImpl();
  3152. restoreStateIfNeeded();
  3153. }
  3154. }
  3155. function batchedUpdates(fn, bookkeeping) {
  3156. if (isInsideEventHandler) {
  3157. // If we are currently inside another batch, we need to wait until it
  3158. // fully completes before restoring state.
  3159. return fn(bookkeeping);
  3160. }
  3161. isInsideEventHandler = true;
  3162. try {
  3163. return batchedUpdatesImpl(fn, bookkeeping);
  3164. } finally {
  3165. isInsideEventHandler = false;
  3166. finishEventHandler();
  3167. }
  3168. }
  3169. function batchedEventUpdates(fn, a, b) {
  3170. if (isBatchingEventUpdates) {
  3171. // If we are currently inside another batch, we need to wait until it
  3172. // fully completes before restoring state.
  3173. return fn(a, b);
  3174. }
  3175. isBatchingEventUpdates = true;
  3176. try {
  3177. return batchedEventUpdatesImpl(fn, a, b);
  3178. } finally {
  3179. isBatchingEventUpdates = false;
  3180. finishEventHandler();
  3181. }
  3182. }
  3183. function discreteUpdates(fn, a, b, c, d) {
  3184. var prevIsInsideEventHandler = isInsideEventHandler;
  3185. isInsideEventHandler = true;
  3186. try {
  3187. return discreteUpdatesImpl(fn, a, b, c, d);
  3188. } finally {
  3189. isInsideEventHandler = prevIsInsideEventHandler;
  3190. if (!isInsideEventHandler) {
  3191. finishEventHandler();
  3192. }
  3193. }
  3194. }
  3195. function flushDiscreteUpdatesIfNeeded(timeStamp) {
  3196. {
  3197. if (!isInsideEventHandler) {
  3198. flushDiscreteUpdatesImpl();
  3199. }
  3200. }
  3201. }
  3202. function setBatchingImplementation(_batchedUpdatesImpl, _discreteUpdatesImpl, _flushDiscreteUpdatesImpl, _batchedEventUpdatesImpl) {
  3203. batchedUpdatesImpl = _batchedUpdatesImpl;
  3204. discreteUpdatesImpl = _discreteUpdatesImpl;
  3205. flushDiscreteUpdatesImpl = _flushDiscreteUpdatesImpl;
  3206. batchedEventUpdatesImpl = _batchedEventUpdatesImpl;
  3207. }
  3208. function isInteractive(tag) {
  3209. return tag === 'button' || tag === 'input' || tag === 'select' || tag === 'textarea';
  3210. }
  3211. function shouldPreventMouseEvent(name, type, props) {
  3212. switch (name) {
  3213. case 'onClick':
  3214. case 'onClickCapture':
  3215. case 'onDoubleClick':
  3216. case 'onDoubleClickCapture':
  3217. case 'onMouseDown':
  3218. case 'onMouseDownCapture':
  3219. case 'onMouseMove':
  3220. case 'onMouseMoveCapture':
  3221. case 'onMouseUp':
  3222. case 'onMouseUpCapture':
  3223. case 'onMouseEnter':
  3224. return !!(props.disabled && isInteractive(type));
  3225. default:
  3226. return false;
  3227. }
  3228. }
  3229. /**
  3230. * @param {object} inst The instance, which is the source of events.
  3231. * @param {string} registrationName Name of listener (e.g. `onClick`).
  3232. * @return {?function} The stored callback.
  3233. */
  3234. function getListener(inst, registrationName) {
  3235. var stateNode = inst.stateNode;
  3236. if (stateNode === null) {
  3237. // Work in progress (ex: onload events in incremental mode).
  3238. return null;
  3239. }
  3240. var props = getFiberCurrentPropsFromNode(stateNode);
  3241. if (props === null) {
  3242. // Work in progress.
  3243. return null;
  3244. }
  3245. var listener = props[registrationName];
  3246. if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
  3247. return null;
  3248. }
  3249. if (!(!listener || typeof listener === 'function')) {
  3250. {
  3251. throw Error( "Expected `" + registrationName + "` listener to be a function, instead got a value of `" + typeof listener + "` type." );
  3252. }
  3253. }
  3254. return listener;
  3255. }
  3256. var passiveBrowserEventsSupported = false; // Check if browser support events with passive listeners
  3257. // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
  3258. if (canUseDOM) {
  3259. try {
  3260. var options = {}; // $FlowFixMe: Ignore Flow complaining about needing a value
  3261. Object.defineProperty(options, 'passive', {
  3262. get: function () {
  3263. passiveBrowserEventsSupported = true;
  3264. }
  3265. });
  3266. window.addEventListener('test', options, options);
  3267. window.removeEventListener('test', options, options);
  3268. } catch (e) {
  3269. passiveBrowserEventsSupported = false;
  3270. }
  3271. }
  3272. function invokeGuardedCallbackProd(name, func, context, a, b, c, d, e, f) {
  3273. var funcArgs = Array.prototype.slice.call(arguments, 3);
  3274. try {
  3275. func.apply(context, funcArgs);
  3276. } catch (error) {
  3277. this.onError(error);
  3278. }
  3279. }
  3280. var invokeGuardedCallbackImpl = invokeGuardedCallbackProd;
  3281. {
  3282. // In DEV mode, we swap out invokeGuardedCallback for a special version
  3283. // that plays more nicely with the browser's DevTools. The idea is to preserve
  3284. // "Pause on exceptions" behavior. Because React wraps all user-provided
  3285. // functions in invokeGuardedCallback, and the production version of
  3286. // invokeGuardedCallback uses a try-catch, all user exceptions are treated
  3287. // like caught exceptions, and the DevTools won't pause unless the developer
  3288. // takes the extra step of enabling pause on caught exceptions. This is
  3289. // unintuitive, though, because even though React has caught the error, from
  3290. // the developer's perspective, the error is uncaught.
  3291. //
  3292. // To preserve the expected "Pause on exceptions" behavior, we don't use a
  3293. // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
  3294. // DOM node, and call the user-provided callback from inside an event handler
  3295. // for that fake event. If the callback throws, the error is "captured" using
  3296. // a global event handler. But because the error happens in a different
  3297. // event loop context, it does not interrupt the normal program flow.
  3298. // Effectively, this gives us try-catch behavior without actually using
  3299. // try-catch. Neat!
  3300. // Check that the browser supports the APIs we need to implement our special
  3301. // DEV version of invokeGuardedCallback
  3302. if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
  3303. var fakeNode = document.createElement('react');
  3304. invokeGuardedCallbackImpl = function invokeGuardedCallbackDev(name, func, context, a, b, c, d, e, f) {
  3305. // If document doesn't exist we know for sure we will crash in this method
  3306. // when we call document.createEvent(). However this can cause confusing
  3307. // errors: https://github.com/facebookincubator/create-react-app/issues/3482
  3308. // So we preemptively throw with a better message instead.
  3309. if (!(typeof document !== 'undefined')) {
  3310. {
  3311. throw Error( "The `document` global was defined when React was initialized, but is not defined anymore. This can happen in a test environment if a component schedules an update from an asynchronous callback, but the test has already finished running. To solve this, you can either unmount the component at the end of your test (and ensure that any asynchronous operations get canceled in `componentWillUnmount`), or you can change the test itself to be asynchronous." );
  3312. }
  3313. }
  3314. var evt = document.createEvent('Event');
  3315. var didCall = false; // Keeps track of whether the user-provided callback threw an error. We
  3316. // set this to true at the beginning, then set it to false right after
  3317. // calling the function. If the function errors, `didError` will never be
  3318. // set to false. This strategy works even if the browser is flaky and
  3319. // fails to call our global error handler, because it doesn't rely on
  3320. // the error event at all.
  3321. var didError = true; // Keeps track of the value of window.event so that we can reset it
  3322. // during the callback to let user code access window.event in the
  3323. // browsers that support it.
  3324. var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
  3325. // dispatching: https://github.com/facebook/react/issues/13688
  3326. var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event');
  3327. function restoreAfterDispatch() {
  3328. // We immediately remove the callback from event listeners so that
  3329. // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
  3330. // nested call would trigger the fake event handlers of any call higher
  3331. // in the stack.
  3332. fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
  3333. // window.event assignment in both IE <= 10 as they throw an error
  3334. // "Member not found" in strict mode, and in Firefox which does not
  3335. // support window.event.
  3336. if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
  3337. window.event = windowEvent;
  3338. }
  3339. } // Create an event handler for our fake event. We will synchronously
  3340. // dispatch our fake event using `dispatchEvent`. Inside the handler, we
  3341. // call the user-provided callback.
  3342. var funcArgs = Array.prototype.slice.call(arguments, 3);
  3343. function callCallback() {
  3344. didCall = true;
  3345. restoreAfterDispatch();
  3346. func.apply(context, funcArgs);
  3347. didError = false;
  3348. } // Create a global error event handler. We use this to capture the value
  3349. // that was thrown. It's possible that this error handler will fire more
  3350. // than once; for example, if non-React code also calls `dispatchEvent`
  3351. // and a handler for that event throws. We should be resilient to most of
  3352. // those cases. Even if our error event handler fires more than once, the
  3353. // last error event is always used. If the callback actually does error,
  3354. // we know that the last error event is the correct one, because it's not
  3355. // possible for anything else to have happened in between our callback
  3356. // erroring and the code that follows the `dispatchEvent` call below. If
  3357. // the callback doesn't error, but the error event was fired, we know to
  3358. // ignore it because `didError` will be false, as described above.
  3359. var error; // Use this to track whether the error event is ever called.
  3360. var didSetError = false;
  3361. var isCrossOriginError = false;
  3362. function handleWindowError(event) {
  3363. error = event.error;
  3364. didSetError = true;
  3365. if (error === null && event.colno === 0 && event.lineno === 0) {
  3366. isCrossOriginError = true;
  3367. }
  3368. if (event.defaultPrevented) {
  3369. // Some other error handler has prevented default.
  3370. // Browsers silence the error report if this happens.
  3371. // We'll remember this to later decide whether to log it or not.
  3372. if (error != null && typeof error === 'object') {
  3373. try {
  3374. error._suppressLogging = true;
  3375. } catch (inner) {// Ignore.
  3376. }
  3377. }
  3378. }
  3379. } // Create a fake event type.
  3380. var evtType = "react-" + (name ? name : 'invokeguardedcallback'); // Attach our event handlers
  3381. window.addEventListener('error', handleWindowError);
  3382. fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
  3383. // errors, it will trigger our global error handler.
  3384. evt.initEvent(evtType, false, false);
  3385. fakeNode.dispatchEvent(evt);
  3386. if (windowEventDescriptor) {
  3387. Object.defineProperty(window, 'event', windowEventDescriptor);
  3388. }
  3389. if (didCall && didError) {
  3390. if (!didSetError) {
  3391. // The callback errored, but the error event never fired.
  3392. error = new Error('An error was thrown inside one of your components, but React ' + "doesn't know what it was. This is likely due to browser " + 'flakiness. React does its best to preserve the "Pause on ' + 'exceptions" behavior of the DevTools, which requires some ' + "DEV-mode only tricks. It's possible that these don't work in " + 'your browser. Try triggering the error in production mode, ' + 'or switching to a modern browser. If you suspect that this is ' + 'actually an issue with React, please file an issue.');
  3393. } else if (isCrossOriginError) {
  3394. error = new Error("A cross-origin error was thrown. React doesn't have access to " + 'the actual error object in development. ' + 'See https://reactjs.org/link/crossorigin-error for more information.');
  3395. }
  3396. this.onError(error);
  3397. } // Remove our event listeners
  3398. window.removeEventListener('error', handleWindowError);
  3399. if (!didCall) {
  3400. // Something went really wrong, and our event was not dispatched.
  3401. // https://github.com/facebook/react/issues/16734
  3402. // https://github.com/facebook/react/issues/16585
  3403. // Fall back to the production implementation.
  3404. restoreAfterDispatch();
  3405. return invokeGuardedCallbackProd.apply(this, arguments);
  3406. }
  3407. };
  3408. }
  3409. }
  3410. var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
  3411. var hasError = false;
  3412. var caughtError = null; // Used by event system to capture/rethrow the first error.
  3413. var hasRethrowError = false;
  3414. var rethrowError = null;
  3415. var reporter = {
  3416. onError: function (error) {
  3417. hasError = true;
  3418. caughtError = error;
  3419. }
  3420. };
  3421. /**
  3422. * Call a function while guarding against errors that happens within it.
  3423. * Returns an error if it throws, otherwise null.
  3424. *
  3425. * In production, this is implemented using a try-catch. The reason we don't
  3426. * use a try-catch directly is so that we can swap out a different
  3427. * implementation in DEV mode.
  3428. *
  3429. * @param {String} name of the guard to use for logging or debugging
  3430. * @param {Function} func The function to invoke
  3431. * @param {*} context The context to use when calling the function
  3432. * @param {...*} args Arguments for function
  3433. */
  3434. function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
  3435. hasError = false;
  3436. caughtError = null;
  3437. invokeGuardedCallbackImpl$1.apply(reporter, arguments);
  3438. }
  3439. /**
  3440. * Same as invokeGuardedCallback, but instead of returning an error, it stores
  3441. * it in a global so it can be rethrown by `rethrowCaughtError` later.
  3442. * TODO: See if caughtError and rethrowError can be unified.
  3443. *
  3444. * @param {String} name of the guard to use for logging or debugging
  3445. * @param {Function} func The function to invoke
  3446. * @param {*} context The context to use when calling the function
  3447. * @param {...*} args Arguments for function
  3448. */
  3449. function invokeGuardedCallbackAndCatchFirstError(name, func, context, a, b, c, d, e, f) {
  3450. invokeGuardedCallback.apply(this, arguments);
  3451. if (hasError) {
  3452. var error = clearCaughtError();
  3453. if (!hasRethrowError) {
  3454. hasRethrowError = true;
  3455. rethrowError = error;
  3456. }
  3457. }
  3458. }
  3459. /**
  3460. * During execution of guarded functions we will capture the first error which
  3461. * we will rethrow to be handled by the top level error handler.
  3462. */
  3463. function rethrowCaughtError() {
  3464. if (hasRethrowError) {
  3465. var error = rethrowError;
  3466. hasRethrowError = false;
  3467. rethrowError = null;
  3468. throw error;
  3469. }
  3470. }
  3471. function hasCaughtError() {
  3472. return hasError;
  3473. }
  3474. function clearCaughtError() {
  3475. if (hasError) {
  3476. var error = caughtError;
  3477. hasError = false;
  3478. caughtError = null;
  3479. return error;
  3480. } else {
  3481. {
  3482. {
  3483. throw Error( "clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue." );
  3484. }
  3485. }
  3486. }
  3487. }
  3488. var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
  3489. var _ReactInternals$Sched = ReactInternals$1.Scheduler,
  3490. unstable_cancelCallback = _ReactInternals$Sched.unstable_cancelCallback,
  3491. unstable_now = _ReactInternals$Sched.unstable_now,
  3492. unstable_scheduleCallback = _ReactInternals$Sched.unstable_scheduleCallback,
  3493. unstable_shouldYield = _ReactInternals$Sched.unstable_shouldYield,
  3494. unstable_requestPaint = _ReactInternals$Sched.unstable_requestPaint,
  3495. unstable_getFirstCallbackNode = _ReactInternals$Sched.unstable_getFirstCallbackNode,
  3496. unstable_runWithPriority = _ReactInternals$Sched.unstable_runWithPriority,
  3497. unstable_next = _ReactInternals$Sched.unstable_next,
  3498. unstable_continueExecution = _ReactInternals$Sched.unstable_continueExecution,
  3499. unstable_pauseExecution = _ReactInternals$Sched.unstable_pauseExecution,
  3500. unstable_getCurrentPriorityLevel = _ReactInternals$Sched.unstable_getCurrentPriorityLevel,
  3501. unstable_ImmediatePriority = _ReactInternals$Sched.unstable_ImmediatePriority,
  3502. unstable_UserBlockingPriority = _ReactInternals$Sched.unstable_UserBlockingPriority,
  3503. unstable_NormalPriority = _ReactInternals$Sched.unstable_NormalPriority,
  3504. unstable_LowPriority = _ReactInternals$Sched.unstable_LowPriority,
  3505. unstable_IdlePriority = _ReactInternals$Sched.unstable_IdlePriority,
  3506. unstable_forceFrameRate = _ReactInternals$Sched.unstable_forceFrameRate,
  3507. unstable_flushAllWithoutAsserting = _ReactInternals$Sched.unstable_flushAllWithoutAsserting;
  3508. /**
  3509. * `ReactInstanceMap` maintains a mapping from a public facing stateful
  3510. * instance (key) and the internal representation (value). This allows public
  3511. * methods to accept the user facing instance as an argument and map them back
  3512. * to internal methods.
  3513. *
  3514. * Note that this module is currently shared and assumed to be stateless.
  3515. * If this becomes an actual Map, that will break.
  3516. */
  3517. function get(key) {
  3518. return key._reactInternals;
  3519. }
  3520. function has(key) {
  3521. return key._reactInternals !== undefined;
  3522. }
  3523. function set(key, value) {
  3524. key._reactInternals = value;
  3525. }
  3526. // Don't change these two values. They're used by React Dev Tools.
  3527. var NoFlags =
  3528. /* */
  3529. 0;
  3530. var PerformedWork =
  3531. /* */
  3532. 1; // You can change the rest (and add more).
  3533. var Placement =
  3534. /* */
  3535. 2;
  3536. var Update =
  3537. /* */
  3538. 4;
  3539. var PlacementAndUpdate =
  3540. /* */
  3541. 6;
  3542. var Deletion =
  3543. /* */
  3544. 8;
  3545. var ContentReset =
  3546. /* */
  3547. 16;
  3548. var Callback =
  3549. /* */
  3550. 32;
  3551. var DidCapture =
  3552. /* */
  3553. 64;
  3554. var Ref =
  3555. /* */
  3556. 128;
  3557. var Snapshot =
  3558. /* */
  3559. 256;
  3560. var Passive =
  3561. /* */
  3562. 512; // TODO (effects) Remove this bit once the new reconciler is synced to the old.
  3563. var PassiveUnmountPendingDev =
  3564. /* */
  3565. 8192;
  3566. var Hydrating =
  3567. /* */
  3568. 1024;
  3569. var HydratingAndUpdate =
  3570. /* */
  3571. 1028; // Passive & Update & Callback & Ref & Snapshot
  3572. var LifecycleEffectMask =
  3573. /* */
  3574. 932; // Union of all host effects
  3575. var HostEffectMask =
  3576. /* */
  3577. 2047; // These are not really side effects, but we still reuse this field.
  3578. var Incomplete =
  3579. /* */
  3580. 2048;
  3581. var ShouldCapture =
  3582. /* */
  3583. 4096;
  3584. var ForceUpdateForLegacySuspense =
  3585. /* */
  3586. 16384; // Static tags describe aspects of a fiber that are not specific to a render,
  3587. var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
  3588. function getNearestMountedFiber(fiber) {
  3589. var node = fiber;
  3590. var nearestMounted = fiber;
  3591. if (!fiber.alternate) {
  3592. // If there is no alternate, this might be a new tree that isn't inserted
  3593. // yet. If it is, then it will have a pending insertion effect on it.
  3594. var nextNode = node;
  3595. do {
  3596. node = nextNode;
  3597. if ((node.flags & (Placement | Hydrating)) !== NoFlags) {
  3598. // This is an insertion or in-progress hydration. The nearest possible
  3599. // mounted fiber is the parent but we need to continue to figure out
  3600. // if that one is still mounted.
  3601. nearestMounted = node.return;
  3602. }
  3603. nextNode = node.return;
  3604. } while (nextNode);
  3605. } else {
  3606. while (node.return) {
  3607. node = node.return;
  3608. }
  3609. }
  3610. if (node.tag === HostRoot) {
  3611. // TODO: Check if this was a nested HostRoot when used with
  3612. // renderContainerIntoSubtree.
  3613. return nearestMounted;
  3614. } // If we didn't hit the root, that means that we're in an disconnected tree
  3615. // that has been unmounted.
  3616. return null;
  3617. }
  3618. function getSuspenseInstanceFromFiber(fiber) {
  3619. if (fiber.tag === SuspenseComponent) {
  3620. var suspenseState = fiber.memoizedState;
  3621. if (suspenseState === null) {
  3622. var current = fiber.alternate;
  3623. if (current !== null) {
  3624. suspenseState = current.memoizedState;
  3625. }
  3626. }
  3627. if (suspenseState !== null) {
  3628. return suspenseState.dehydrated;
  3629. }
  3630. }
  3631. return null;
  3632. }
  3633. function getContainerFromFiber(fiber) {
  3634. return fiber.tag === HostRoot ? fiber.stateNode.containerInfo : null;
  3635. }
  3636. function isFiberMounted(fiber) {
  3637. return getNearestMountedFiber(fiber) === fiber;
  3638. }
  3639. function isMounted(component) {
  3640. {
  3641. var owner = ReactCurrentOwner.current;
  3642. if (owner !== null && owner.tag === ClassComponent) {
  3643. var ownerFiber = owner;
  3644. var instance = ownerFiber.stateNode;
  3645. if (!instance._warnedAboutRefsInRender) {
  3646. error('%s is accessing isMounted inside its render() function. ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', getComponentName(ownerFiber.type) || 'A component');
  3647. }
  3648. instance._warnedAboutRefsInRender = true;
  3649. }
  3650. }
  3651. var fiber = get(component);
  3652. if (!fiber) {
  3653. return false;
  3654. }
  3655. return getNearestMountedFiber(fiber) === fiber;
  3656. }
  3657. function assertIsMounted(fiber) {
  3658. if (!(getNearestMountedFiber(fiber) === fiber)) {
  3659. {
  3660. throw Error( "Unable to find node on an unmounted component." );
  3661. }
  3662. }
  3663. }
  3664. function findCurrentFiberUsingSlowPath(fiber) {
  3665. var alternate = fiber.alternate;
  3666. if (!alternate) {
  3667. // If there is no alternate, then we only need to check if it is mounted.
  3668. var nearestMounted = getNearestMountedFiber(fiber);
  3669. if (!(nearestMounted !== null)) {
  3670. {
  3671. throw Error( "Unable to find node on an unmounted component." );
  3672. }
  3673. }
  3674. if (nearestMounted !== fiber) {
  3675. return null;
  3676. }
  3677. return fiber;
  3678. } // If we have two possible branches, we'll walk backwards up to the root
  3679. // to see what path the root points to. On the way we may hit one of the
  3680. // special cases and we'll deal with them.
  3681. var a = fiber;
  3682. var b = alternate;
  3683. while (true) {
  3684. var parentA = a.return;
  3685. if (parentA === null) {
  3686. // We're at the root.
  3687. break;
  3688. }
  3689. var parentB = parentA.alternate;
  3690. if (parentB === null) {
  3691. // There is no alternate. This is an unusual case. Currently, it only
  3692. // happens when a Suspense component is hidden. An extra fragment fiber
  3693. // is inserted in between the Suspense fiber and its children. Skip
  3694. // over this extra fragment fiber and proceed to the next parent.
  3695. var nextParent = parentA.return;
  3696. if (nextParent !== null) {
  3697. a = b = nextParent;
  3698. continue;
  3699. } // If there's no parent, we're at the root.
  3700. break;
  3701. } // If both copies of the parent fiber point to the same child, we can
  3702. // assume that the child is current. This happens when we bailout on low
  3703. // priority: the bailed out fiber's child reuses the current child.
  3704. if (parentA.child === parentB.child) {
  3705. var child = parentA.child;
  3706. while (child) {
  3707. if (child === a) {
  3708. // We've determined that A is the current branch.
  3709. assertIsMounted(parentA);
  3710. return fiber;
  3711. }
  3712. if (child === b) {
  3713. // We've determined that B is the current branch.
  3714. assertIsMounted(parentA);
  3715. return alternate;
  3716. }
  3717. child = child.sibling;
  3718. } // We should never have an alternate for any mounting node. So the only
  3719. // way this could possibly happen is if this was unmounted, if at all.
  3720. {
  3721. {
  3722. throw Error( "Unable to find node on an unmounted component." );
  3723. }
  3724. }
  3725. }
  3726. if (a.return !== b.return) {
  3727. // The return pointer of A and the return pointer of B point to different
  3728. // fibers. We assume that return pointers never criss-cross, so A must
  3729. // belong to the child set of A.return, and B must belong to the child
  3730. // set of B.return.
  3731. a = parentA;
  3732. b = parentB;
  3733. } else {
  3734. // The return pointers point to the same fiber. We'll have to use the
  3735. // default, slow path: scan the child sets of each parent alternate to see
  3736. // which child belongs to which set.
  3737. //
  3738. // Search parent A's child set
  3739. var didFindChild = false;
  3740. var _child = parentA.child;
  3741. while (_child) {
  3742. if (_child === a) {
  3743. didFindChild = true;
  3744. a = parentA;
  3745. b = parentB;
  3746. break;
  3747. }
  3748. if (_child === b) {
  3749. didFindChild = true;
  3750. b = parentA;
  3751. a = parentB;
  3752. break;
  3753. }
  3754. _child = _child.sibling;
  3755. }
  3756. if (!didFindChild) {
  3757. // Search parent B's child set
  3758. _child = parentB.child;
  3759. while (_child) {
  3760. if (_child === a) {
  3761. didFindChild = true;
  3762. a = parentB;
  3763. b = parentA;
  3764. break;
  3765. }
  3766. if (_child === b) {
  3767. didFindChild = true;
  3768. b = parentB;
  3769. a = parentA;
  3770. break;
  3771. }
  3772. _child = _child.sibling;
  3773. }
  3774. if (!didFindChild) {
  3775. {
  3776. throw Error( "Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue." );
  3777. }
  3778. }
  3779. }
  3780. }
  3781. if (!(a.alternate === b)) {
  3782. {
  3783. throw Error( "Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue." );
  3784. }
  3785. }
  3786. } // If the root is not a host container, we're in a disconnected tree. I.e.
  3787. // unmounted.
  3788. if (!(a.tag === HostRoot)) {
  3789. {
  3790. throw Error( "Unable to find node on an unmounted component." );
  3791. }
  3792. }
  3793. if (a.stateNode.current === a) {
  3794. // We've determined that A is the current branch.
  3795. return fiber;
  3796. } // Otherwise B has to be current branch.
  3797. return alternate;
  3798. }
  3799. function findCurrentHostFiber(parent) {
  3800. var currentParent = findCurrentFiberUsingSlowPath(parent);
  3801. if (!currentParent) {
  3802. return null;
  3803. } // Next we'll drill down this component to find the first HostComponent/Text.
  3804. var node = currentParent;
  3805. while (true) {
  3806. if (node.tag === HostComponent || node.tag === HostText) {
  3807. return node;
  3808. } else if (node.child) {
  3809. node.child.return = node;
  3810. node = node.child;
  3811. continue;
  3812. }
  3813. if (node === currentParent) {
  3814. return null;
  3815. }
  3816. while (!node.sibling) {
  3817. if (!node.return || node.return === currentParent) {
  3818. return null;
  3819. }
  3820. node = node.return;
  3821. }
  3822. node.sibling.return = node.return;
  3823. node = node.sibling;
  3824. } // Flow needs the return null here, but ESLint complains about it.
  3825. // eslint-disable-next-line no-unreachable
  3826. return null;
  3827. }
  3828. function findCurrentHostFiberWithNoPortals(parent) {
  3829. var currentParent = findCurrentFiberUsingSlowPath(parent);
  3830. if (!currentParent) {
  3831. return null;
  3832. } // Next we'll drill down this component to find the first HostComponent/Text.
  3833. var node = currentParent;
  3834. while (true) {
  3835. if (node.tag === HostComponent || node.tag === HostText || enableFundamentalAPI ) {
  3836. return node;
  3837. } else if (node.child && node.tag !== HostPortal) {
  3838. node.child.return = node;
  3839. node = node.child;
  3840. continue;
  3841. }
  3842. if (node === currentParent) {
  3843. return null;
  3844. }
  3845. while (!node.sibling) {
  3846. if (!node.return || node.return === currentParent) {
  3847. return null;
  3848. }
  3849. node = node.return;
  3850. }
  3851. node.sibling.return = node.return;
  3852. node = node.sibling;
  3853. } // Flow needs the return null here, but ESLint complains about it.
  3854. // eslint-disable-next-line no-unreachable
  3855. return null;
  3856. }
  3857. function doesFiberContain(parentFiber, childFiber) {
  3858. var node = childFiber;
  3859. var parentFiberAlternate = parentFiber.alternate;
  3860. while (node !== null) {
  3861. if (node === parentFiber || node === parentFiberAlternate) {
  3862. return true;
  3863. }
  3864. node = node.return;
  3865. }
  3866. return false;
  3867. }
  3868. var attemptUserBlockingHydration;
  3869. function setAttemptUserBlockingHydration(fn) {
  3870. attemptUserBlockingHydration = fn;
  3871. }
  3872. var attemptContinuousHydration;
  3873. function setAttemptContinuousHydration(fn) {
  3874. attemptContinuousHydration = fn;
  3875. }
  3876. var attemptHydrationAtCurrentPriority;
  3877. function setAttemptHydrationAtCurrentPriority(fn) {
  3878. attemptHydrationAtCurrentPriority = fn;
  3879. }
  3880. var attemptHydrationAtPriority;
  3881. function setAttemptHydrationAtPriority(fn) {
  3882. attemptHydrationAtPriority = fn;
  3883. } // TODO: Upgrade this definition once we're on a newer version of Flow that
  3884. var hasScheduledReplayAttempt = false; // The queue of discrete events to be replayed.
  3885. var queuedDiscreteEvents = []; // Indicates if any continuous event targets are non-null for early bailout.
  3886. // if the last target was dehydrated.
  3887. var queuedFocus = null;
  3888. var queuedDrag = null;
  3889. var queuedMouse = null; // For pointer events there can be one latest event per pointerId.
  3890. var queuedPointers = new Map();
  3891. var queuedPointerCaptures = new Map(); // We could consider replaying selectionchange and touchmoves too.
  3892. var queuedExplicitHydrationTargets = [];
  3893. function hasQueuedDiscreteEvents() {
  3894. return queuedDiscreteEvents.length > 0;
  3895. }
  3896. var discreteReplayableEvents = ['mousedown', 'mouseup', 'touchcancel', 'touchend', 'touchstart', 'auxclick', 'dblclick', 'pointercancel', 'pointerdown', 'pointerup', 'dragend', 'dragstart', 'drop', 'compositionend', 'compositionstart', 'keydown', 'keypress', 'keyup', 'input', 'textInput', // Intentionally camelCase
  3897. 'copy', 'cut', 'paste', 'click', 'change', 'contextmenu', 'reset', 'submit'];
  3898. function isReplayableDiscreteEvent(eventType) {
  3899. return discreteReplayableEvents.indexOf(eventType) > -1;
  3900. }
  3901. function createQueuedReplayableEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent) {
  3902. return {
  3903. blockedOn: blockedOn,
  3904. domEventName: domEventName,
  3905. eventSystemFlags: eventSystemFlags | IS_REPLAYED,
  3906. nativeEvent: nativeEvent,
  3907. targetContainers: [targetContainer]
  3908. };
  3909. }
  3910. function queueDiscreteEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent) {
  3911. var queuedEvent = createQueuedReplayableEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent);
  3912. queuedDiscreteEvents.push(queuedEvent);
  3913. } // Resets the replaying for this type of continuous event to no event.
  3914. function clearIfContinuousEvent(domEventName, nativeEvent) {
  3915. switch (domEventName) {
  3916. case 'focusin':
  3917. case 'focusout':
  3918. queuedFocus = null;
  3919. break;
  3920. case 'dragenter':
  3921. case 'dragleave':
  3922. queuedDrag = null;
  3923. break;
  3924. case 'mouseover':
  3925. case 'mouseout':
  3926. queuedMouse = null;
  3927. break;
  3928. case 'pointerover':
  3929. case 'pointerout':
  3930. {
  3931. var pointerId = nativeEvent.pointerId;
  3932. queuedPointers.delete(pointerId);
  3933. break;
  3934. }
  3935. case 'gotpointercapture':
  3936. case 'lostpointercapture':
  3937. {
  3938. var _pointerId = nativeEvent.pointerId;
  3939. queuedPointerCaptures.delete(_pointerId);
  3940. break;
  3941. }
  3942. }
  3943. }
  3944. function accumulateOrCreateContinuousQueuedReplayableEvent(existingQueuedEvent, blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent) {
  3945. if (existingQueuedEvent === null || existingQueuedEvent.nativeEvent !== nativeEvent) {
  3946. var queuedEvent = createQueuedReplayableEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent);
  3947. if (blockedOn !== null) {
  3948. var _fiber2 = getInstanceFromNode(blockedOn);
  3949. if (_fiber2 !== null) {
  3950. // Attempt to increase the priority of this target.
  3951. attemptContinuousHydration(_fiber2);
  3952. }
  3953. }
  3954. return queuedEvent;
  3955. } // If we have already queued this exact event, then it's because
  3956. // the different event systems have different DOM event listeners.
  3957. // We can accumulate the flags, and the targetContainers, and
  3958. // store a single event to be replayed.
  3959. existingQueuedEvent.eventSystemFlags |= eventSystemFlags;
  3960. var targetContainers = existingQueuedEvent.targetContainers;
  3961. if (targetContainer !== null && targetContainers.indexOf(targetContainer) === -1) {
  3962. targetContainers.push(targetContainer);
  3963. }
  3964. return existingQueuedEvent;
  3965. }
  3966. function queueIfContinuousEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent) {
  3967. // These set relatedTarget to null because the replayed event will be treated as if we
  3968. // moved from outside the window (no target) onto the target once it hydrates.
  3969. // Instead of mutating we could clone the event.
  3970. switch (domEventName) {
  3971. case 'focusin':
  3972. {
  3973. var focusEvent = nativeEvent;
  3974. queuedFocus = accumulateOrCreateContinuousQueuedReplayableEvent(queuedFocus, blockedOn, domEventName, eventSystemFlags, targetContainer, focusEvent);
  3975. return true;
  3976. }
  3977. case 'dragenter':
  3978. {
  3979. var dragEvent = nativeEvent;
  3980. queuedDrag = accumulateOrCreateContinuousQueuedReplayableEvent(queuedDrag, blockedOn, domEventName, eventSystemFlags, targetContainer, dragEvent);
  3981. return true;
  3982. }
  3983. case 'mouseover':
  3984. {
  3985. var mouseEvent = nativeEvent;
  3986. queuedMouse = accumulateOrCreateContinuousQueuedReplayableEvent(queuedMouse, blockedOn, domEventName, eventSystemFlags, targetContainer, mouseEvent);
  3987. return true;
  3988. }
  3989. case 'pointerover':
  3990. {
  3991. var pointerEvent = nativeEvent;
  3992. var pointerId = pointerEvent.pointerId;
  3993. queuedPointers.set(pointerId, accumulateOrCreateContinuousQueuedReplayableEvent(queuedPointers.get(pointerId) || null, blockedOn, domEventName, eventSystemFlags, targetContainer, pointerEvent));
  3994. return true;
  3995. }
  3996. case 'gotpointercapture':
  3997. {
  3998. var _pointerEvent = nativeEvent;
  3999. var _pointerId2 = _pointerEvent.pointerId;
  4000. queuedPointerCaptures.set(_pointerId2, accumulateOrCreateContinuousQueuedReplayableEvent(queuedPointerCaptures.get(_pointerId2) || null, blockedOn, domEventName, eventSystemFlags, targetContainer, _pointerEvent));
  4001. return true;
  4002. }
  4003. }
  4004. return false;
  4005. } // Check if this target is unblocked. Returns true if it's unblocked.
  4006. function attemptExplicitHydrationTarget(queuedTarget) {
  4007. // TODO: This function shares a lot of logic with attemptToDispatchEvent.
  4008. // Try to unify them. It's a bit tricky since it would require two return
  4009. // values.
  4010. var targetInst = getClosestInstanceFromNode(queuedTarget.target);
  4011. if (targetInst !== null) {
  4012. var nearestMounted = getNearestMountedFiber(targetInst);
  4013. if (nearestMounted !== null) {
  4014. var tag = nearestMounted.tag;
  4015. if (tag === SuspenseComponent) {
  4016. var instance = getSuspenseInstanceFromFiber(nearestMounted);
  4017. if (instance !== null) {
  4018. // We're blocked on hydrating this boundary.
  4019. // Increase its priority.
  4020. queuedTarget.blockedOn = instance;
  4021. attemptHydrationAtPriority(queuedTarget.lanePriority, function () {
  4022. unstable_runWithPriority(queuedTarget.priority, function () {
  4023. attemptHydrationAtCurrentPriority(nearestMounted);
  4024. });
  4025. });
  4026. return;
  4027. }
  4028. } else if (tag === HostRoot) {
  4029. var root = nearestMounted.stateNode;
  4030. if (root.hydrate) {
  4031. queuedTarget.blockedOn = getContainerFromFiber(nearestMounted); // We don't currently have a way to increase the priority of
  4032. // a root other than sync.
  4033. return;
  4034. }
  4035. }
  4036. }
  4037. }
  4038. queuedTarget.blockedOn = null;
  4039. }
  4040. function attemptReplayContinuousQueuedEvent(queuedEvent) {
  4041. if (queuedEvent.blockedOn !== null) {
  4042. return false;
  4043. }
  4044. var targetContainers = queuedEvent.targetContainers;
  4045. while (targetContainers.length > 0) {
  4046. var targetContainer = targetContainers[0];
  4047. var nextBlockedOn = attemptToDispatchEvent(queuedEvent.domEventName, queuedEvent.eventSystemFlags, targetContainer, queuedEvent.nativeEvent);
  4048. if (nextBlockedOn !== null) {
  4049. // We're still blocked. Try again later.
  4050. var _fiber3 = getInstanceFromNode(nextBlockedOn);
  4051. if (_fiber3 !== null) {
  4052. attemptContinuousHydration(_fiber3);
  4053. }
  4054. queuedEvent.blockedOn = nextBlockedOn;
  4055. return false;
  4056. } // This target container was successfully dispatched. Try the next.
  4057. targetContainers.shift();
  4058. }
  4059. return true;
  4060. }
  4061. function attemptReplayContinuousQueuedEventInMap(queuedEvent, key, map) {
  4062. if (attemptReplayContinuousQueuedEvent(queuedEvent)) {
  4063. map.delete(key);
  4064. }
  4065. }
  4066. function replayUnblockedEvents() {
  4067. hasScheduledReplayAttempt = false; // First replay discrete events.
  4068. while (queuedDiscreteEvents.length > 0) {
  4069. var nextDiscreteEvent = queuedDiscreteEvents[0];
  4070. if (nextDiscreteEvent.blockedOn !== null) {
  4071. // We're still blocked.
  4072. // Increase the priority of this boundary to unblock
  4073. // the next discrete event.
  4074. var _fiber4 = getInstanceFromNode(nextDiscreteEvent.blockedOn);
  4075. if (_fiber4 !== null) {
  4076. attemptUserBlockingHydration(_fiber4);
  4077. }
  4078. break;
  4079. }
  4080. var targetContainers = nextDiscreteEvent.targetContainers;
  4081. while (targetContainers.length > 0) {
  4082. var targetContainer = targetContainers[0];
  4083. var nextBlockedOn = attemptToDispatchEvent(nextDiscreteEvent.domEventName, nextDiscreteEvent.eventSystemFlags, targetContainer, nextDiscreteEvent.nativeEvent);
  4084. if (nextBlockedOn !== null) {
  4085. // We're still blocked. Try again later.
  4086. nextDiscreteEvent.blockedOn = nextBlockedOn;
  4087. break;
  4088. } // This target container was successfully dispatched. Try the next.
  4089. targetContainers.shift();
  4090. }
  4091. if (nextDiscreteEvent.blockedOn === null) {
  4092. // We've successfully replayed the first event. Let's try the next one.
  4093. queuedDiscreteEvents.shift();
  4094. }
  4095. } // Next replay any continuous events.
  4096. if (queuedFocus !== null && attemptReplayContinuousQueuedEvent(queuedFocus)) {
  4097. queuedFocus = null;
  4098. }
  4099. if (queuedDrag !== null && attemptReplayContinuousQueuedEvent(queuedDrag)) {
  4100. queuedDrag = null;
  4101. }
  4102. if (queuedMouse !== null && attemptReplayContinuousQueuedEvent(queuedMouse)) {
  4103. queuedMouse = null;
  4104. }
  4105. queuedPointers.forEach(attemptReplayContinuousQueuedEventInMap);
  4106. queuedPointerCaptures.forEach(attemptReplayContinuousQueuedEventInMap);
  4107. }
  4108. function scheduleCallbackIfUnblocked(queuedEvent, unblocked) {
  4109. if (queuedEvent.blockedOn === unblocked) {
  4110. queuedEvent.blockedOn = null;
  4111. if (!hasScheduledReplayAttempt) {
  4112. hasScheduledReplayAttempt = true; // Schedule a callback to attempt replaying as many events as are
  4113. // now unblocked. This first might not actually be unblocked yet.
  4114. // We could check it early to avoid scheduling an unnecessary callback.
  4115. unstable_scheduleCallback(unstable_NormalPriority, replayUnblockedEvents);
  4116. }
  4117. }
  4118. }
  4119. function retryIfBlockedOn(unblocked) {
  4120. // Mark anything that was blocked on this as no longer blocked
  4121. // and eligible for a replay.
  4122. if (queuedDiscreteEvents.length > 0) {
  4123. scheduleCallbackIfUnblocked(queuedDiscreteEvents[0], unblocked); // This is a exponential search for each boundary that commits. I think it's
  4124. // worth it because we expect very few discrete events to queue up and once
  4125. // we are actually fully unblocked it will be fast to replay them.
  4126. for (var i = 1; i < queuedDiscreteEvents.length; i++) {
  4127. var queuedEvent = queuedDiscreteEvents[i];
  4128. if (queuedEvent.blockedOn === unblocked) {
  4129. queuedEvent.blockedOn = null;
  4130. }
  4131. }
  4132. }
  4133. if (queuedFocus !== null) {
  4134. scheduleCallbackIfUnblocked(queuedFocus, unblocked);
  4135. }
  4136. if (queuedDrag !== null) {
  4137. scheduleCallbackIfUnblocked(queuedDrag, unblocked);
  4138. }
  4139. if (queuedMouse !== null) {
  4140. scheduleCallbackIfUnblocked(queuedMouse, unblocked);
  4141. }
  4142. var unblock = function (queuedEvent) {
  4143. return scheduleCallbackIfUnblocked(queuedEvent, unblocked);
  4144. };
  4145. queuedPointers.forEach(unblock);
  4146. queuedPointerCaptures.forEach(unblock);
  4147. for (var _i = 0; _i < queuedExplicitHydrationTargets.length; _i++) {
  4148. var queuedTarget = queuedExplicitHydrationTargets[_i];
  4149. if (queuedTarget.blockedOn === unblocked) {
  4150. queuedTarget.blockedOn = null;
  4151. }
  4152. }
  4153. while (queuedExplicitHydrationTargets.length > 0) {
  4154. var nextExplicitTarget = queuedExplicitHydrationTargets[0];
  4155. if (nextExplicitTarget.blockedOn !== null) {
  4156. // We're still blocked.
  4157. break;
  4158. } else {
  4159. attemptExplicitHydrationTarget(nextExplicitTarget);
  4160. if (nextExplicitTarget.blockedOn === null) {
  4161. // We're unblocked.
  4162. queuedExplicitHydrationTargets.shift();
  4163. }
  4164. }
  4165. }
  4166. }
  4167. var DiscreteEvent = 0;
  4168. var UserBlockingEvent = 1;
  4169. var ContinuousEvent = 2;
  4170. /**
  4171. * Generate a mapping of standard vendor prefixes using the defined style property and event name.
  4172. *
  4173. * @param {string} styleProp
  4174. * @param {string} eventName
  4175. * @returns {object}
  4176. */
  4177. function makePrefixMap(styleProp, eventName) {
  4178. var prefixes = {};
  4179. prefixes[styleProp.toLowerCase()] = eventName.toLowerCase();
  4180. prefixes['Webkit' + styleProp] = 'webkit' + eventName;
  4181. prefixes['Moz' + styleProp] = 'moz' + eventName;
  4182. return prefixes;
  4183. }
  4184. /**
  4185. * A list of event names to a configurable list of vendor prefixes.
  4186. */
  4187. var vendorPrefixes = {
  4188. animationend: makePrefixMap('Animation', 'AnimationEnd'),
  4189. animationiteration: makePrefixMap('Animation', 'AnimationIteration'),
  4190. animationstart: makePrefixMap('Animation', 'AnimationStart'),
  4191. transitionend: makePrefixMap('Transition', 'TransitionEnd')
  4192. };
  4193. /**
  4194. * Event names that have already been detected and prefixed (if applicable).
  4195. */
  4196. var prefixedEventNames = {};
  4197. /**
  4198. * Element to check for prefixes on.
  4199. */
  4200. var style = {};
  4201. /**
  4202. * Bootstrap if a DOM exists.
  4203. */
  4204. if (canUseDOM) {
  4205. style = document.createElement('div').style; // On some platforms, in particular some releases of Android 4.x,
  4206. // the un-prefixed "animation" and "transition" properties are defined on the
  4207. // style object but the events that fire will still be prefixed, so we need
  4208. // to check if the un-prefixed events are usable, and if not remove them from the map.
  4209. if (!('AnimationEvent' in window)) {
  4210. delete vendorPrefixes.animationend.animation;
  4211. delete vendorPrefixes.animationiteration.animation;
  4212. delete vendorPrefixes.animationstart.animation;
  4213. } // Same as above
  4214. if (!('TransitionEvent' in window)) {
  4215. delete vendorPrefixes.transitionend.transition;
  4216. }
  4217. }
  4218. /**
  4219. * Attempts to determine the correct vendor prefixed event name.
  4220. *
  4221. * @param {string} eventName
  4222. * @returns {string}
  4223. */
  4224. function getVendorPrefixedEventName(eventName) {
  4225. if (prefixedEventNames[eventName]) {
  4226. return prefixedEventNames[eventName];
  4227. } else if (!vendorPrefixes[eventName]) {
  4228. return eventName;
  4229. }
  4230. var prefixMap = vendorPrefixes[eventName];
  4231. for (var styleProp in prefixMap) {
  4232. if (prefixMap.hasOwnProperty(styleProp) && styleProp in style) {
  4233. return prefixedEventNames[eventName] = prefixMap[styleProp];
  4234. }
  4235. }
  4236. return eventName;
  4237. }
  4238. var ANIMATION_END = getVendorPrefixedEventName('animationend');
  4239. var ANIMATION_ITERATION = getVendorPrefixedEventName('animationiteration');
  4240. var ANIMATION_START = getVendorPrefixedEventName('animationstart');
  4241. var TRANSITION_END = getVendorPrefixedEventName('transitionend');
  4242. var topLevelEventsToReactNames = new Map();
  4243. var eventPriorities = new Map(); // We store most of the events in this module in pairs of two strings so we can re-use
  4244. // the code required to apply the same logic for event prioritization and that of the
  4245. // SimpleEventPlugin. This complicates things slightly, but the aim is to reduce code
  4246. // duplication (for which there would be quite a bit). For the events that are not needed
  4247. // for the SimpleEventPlugin (otherDiscreteEvents) we process them separately as an
  4248. // array of top level events.
  4249. // Lastly, we ignore prettier so we can keep the formatting sane.
  4250. // prettier-ignore
  4251. var discreteEventPairsForSimpleEventPlugin = ['cancel', 'cancel', 'click', 'click', 'close', 'close', 'contextmenu', 'contextMenu', 'copy', 'copy', 'cut', 'cut', 'auxclick', 'auxClick', 'dblclick', 'doubleClick', // Careful!
  4252. 'dragend', 'dragEnd', 'dragstart', 'dragStart', 'drop', 'drop', 'focusin', 'focus', // Careful!
  4253. 'focusout', 'blur', // Careful!
  4254. 'input', 'input', 'invalid', 'invalid', 'keydown', 'keyDown', 'keypress', 'keyPress', 'keyup', 'keyUp', 'mousedown', 'mouseDown', 'mouseup', 'mouseUp', 'paste', 'paste', 'pause', 'pause', 'play', 'play', 'pointercancel', 'pointerCancel', 'pointerdown', 'pointerDown', 'pointerup', 'pointerUp', 'ratechange', 'rateChange', 'reset', 'reset', 'seeked', 'seeked', 'submit', 'submit', 'touchcancel', 'touchCancel', 'touchend', 'touchEnd', 'touchstart', 'touchStart', 'volumechange', 'volumeChange'];
  4255. var otherDiscreteEvents = ['change', 'selectionchange', 'textInput', 'compositionstart', 'compositionend', 'compositionupdate'];
  4256. var userBlockingPairsForSimpleEventPlugin = ['drag', 'drag', 'dragenter', 'dragEnter', 'dragexit', 'dragExit', 'dragleave', 'dragLeave', 'dragover', 'dragOver', 'mousemove', 'mouseMove', 'mouseout', 'mouseOut', 'mouseover', 'mouseOver', 'pointermove', 'pointerMove', 'pointerout', 'pointerOut', 'pointerover', 'pointerOver', 'scroll', 'scroll', 'toggle', 'toggle', 'touchmove', 'touchMove', 'wheel', 'wheel']; // prettier-ignore
  4257. var continuousPairsForSimpleEventPlugin = ['abort', 'abort', ANIMATION_END, 'animationEnd', ANIMATION_ITERATION, 'animationIteration', ANIMATION_START, 'animationStart', 'canplay', 'canPlay', 'canplaythrough', 'canPlayThrough', 'durationchange', 'durationChange', 'emptied', 'emptied', 'encrypted', 'encrypted', 'ended', 'ended', 'error', 'error', 'gotpointercapture', 'gotPointerCapture', 'load', 'load', 'loadeddata', 'loadedData', 'loadedmetadata', 'loadedMetadata', 'loadstart', 'loadStart', 'lostpointercapture', 'lostPointerCapture', 'playing', 'playing', 'progress', 'progress', 'seeking', 'seeking', 'stalled', 'stalled', 'suspend', 'suspend', 'timeupdate', 'timeUpdate', TRANSITION_END, 'transitionEnd', 'waiting', 'waiting'];
  4258. /**
  4259. * Turns
  4260. * ['abort', ...]
  4261. *
  4262. * into
  4263. *
  4264. * topLevelEventsToReactNames = new Map([
  4265. * ['abort', 'onAbort'],
  4266. * ]);
  4267. *
  4268. * and registers them.
  4269. */
  4270. function registerSimplePluginEventsAndSetTheirPriorities(eventTypes, priority) {
  4271. // As the event types are in pairs of two, we need to iterate
  4272. // through in twos. The events are in pairs of two to save code
  4273. // and improve init perf of processing this array, as it will
  4274. // result in far fewer object allocations and property accesses
  4275. // if we only use three arrays to process all the categories of
  4276. // instead of tuples.
  4277. for (var i = 0; i < eventTypes.length; i += 2) {
  4278. var topEvent = eventTypes[i];
  4279. var event = eventTypes[i + 1];
  4280. var capitalizedEvent = event[0].toUpperCase() + event.slice(1);
  4281. var reactName = 'on' + capitalizedEvent;
  4282. eventPriorities.set(topEvent, priority);
  4283. topLevelEventsToReactNames.set(topEvent, reactName);
  4284. registerTwoPhaseEvent(reactName, [topEvent]);
  4285. }
  4286. }
  4287. function setEventPriorities(eventTypes, priority) {
  4288. for (var i = 0; i < eventTypes.length; i++) {
  4289. eventPriorities.set(eventTypes[i], priority);
  4290. }
  4291. }
  4292. function getEventPriorityForPluginSystem(domEventName) {
  4293. var priority = eventPriorities.get(domEventName); // Default to a ContinuousEvent. Note: we might
  4294. // want to warn if we can't detect the priority
  4295. // for the event.
  4296. return priority === undefined ? ContinuousEvent : priority;
  4297. }
  4298. function registerSimpleEvents() {
  4299. registerSimplePluginEventsAndSetTheirPriorities(discreteEventPairsForSimpleEventPlugin, DiscreteEvent);
  4300. registerSimplePluginEventsAndSetTheirPriorities(userBlockingPairsForSimpleEventPlugin, UserBlockingEvent);
  4301. registerSimplePluginEventsAndSetTheirPriorities(continuousPairsForSimpleEventPlugin, ContinuousEvent);
  4302. setEventPriorities(otherDiscreteEvents, DiscreteEvent);
  4303. }
  4304. var ReactInternals$2 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
  4305. var _ReactInternals$Sched$1 = ReactInternals$2.SchedulerTracing,
  4306. __interactionsRef = _ReactInternals$Sched$1.__interactionsRef,
  4307. __subscriberRef = _ReactInternals$Sched$1.__subscriberRef,
  4308. unstable_clear = _ReactInternals$Sched$1.unstable_clear,
  4309. unstable_getCurrent = _ReactInternals$Sched$1.unstable_getCurrent,
  4310. unstable_getThreadID = _ReactInternals$Sched$1.unstable_getThreadID,
  4311. unstable_subscribe = _ReactInternals$Sched$1.unstable_subscribe,
  4312. unstable_trace = _ReactInternals$Sched$1.unstable_trace,
  4313. unstable_unsubscribe = _ReactInternals$Sched$1.unstable_unsubscribe,
  4314. unstable_wrap = _ReactInternals$Sched$1.unstable_wrap;
  4315. var Scheduler_now = unstable_now;
  4316. {
  4317. // Provide explicit error message when production+profiling bundle of e.g.
  4318. // react-dom is used with production (non-profiling) bundle of
  4319. // scheduler/tracing
  4320. if (!(__interactionsRef != null && __interactionsRef.current != null)) {
  4321. {
  4322. throw Error( "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 https://reactjs.org/link/profiling" );
  4323. }
  4324. }
  4325. }
  4326. // ascending numbers so we can compare them like numbers. They start at 90 to
  4327. // avoid clashing with Scheduler's priorities.
  4328. var ImmediatePriority = 99;
  4329. var UserBlockingPriority = 98;
  4330. var NormalPriority = 97;
  4331. var LowPriority = 96;
  4332. var IdlePriority = 95; // NoPriority is the absence of priority. Also React-only.
  4333. var NoPriority = 90;
  4334. var initialTimeMs = Scheduler_now(); // If the initial timestamp is reasonably small, use Scheduler's `now` directly.
  4335. var SyncLanePriority = 15;
  4336. var SyncBatchedLanePriority = 14;
  4337. var InputDiscreteHydrationLanePriority = 13;
  4338. var InputDiscreteLanePriority = 12;
  4339. var InputContinuousHydrationLanePriority = 11;
  4340. var InputContinuousLanePriority = 10;
  4341. var DefaultHydrationLanePriority = 9;
  4342. var DefaultLanePriority = 8;
  4343. var TransitionHydrationPriority = 7;
  4344. var TransitionPriority = 6;
  4345. var RetryLanePriority = 5;
  4346. var SelectiveHydrationLanePriority = 4;
  4347. var IdleHydrationLanePriority = 3;
  4348. var IdleLanePriority = 2;
  4349. var OffscreenLanePriority = 1;
  4350. var NoLanePriority = 0;
  4351. var TotalLanes = 31;
  4352. var NoLanes =
  4353. /* */
  4354. 0;
  4355. var NoLane =
  4356. /* */
  4357. 0;
  4358. var SyncLane =
  4359. /* */
  4360. 1;
  4361. var SyncBatchedLane =
  4362. /* */
  4363. 2;
  4364. var InputDiscreteHydrationLane =
  4365. /* */
  4366. 4;
  4367. var InputDiscreteLanes =
  4368. /* */
  4369. 24;
  4370. var InputContinuousHydrationLane =
  4371. /* */
  4372. 32;
  4373. var InputContinuousLanes =
  4374. /* */
  4375. 192;
  4376. var DefaultHydrationLane =
  4377. /* */
  4378. 256;
  4379. var DefaultLanes =
  4380. /* */
  4381. 3584;
  4382. var TransitionHydrationLane =
  4383. /* */
  4384. 4096;
  4385. var TransitionLanes =
  4386. /* */
  4387. 4186112;
  4388. var RetryLanes =
  4389. /* */
  4390. 62914560;
  4391. var SomeRetryLane =
  4392. /* */
  4393. 33554432;
  4394. var SelectiveHydrationLane =
  4395. /* */
  4396. 67108864;
  4397. var NonIdleLanes =
  4398. /* */
  4399. 134217727;
  4400. var IdleHydrationLane =
  4401. /* */
  4402. 134217728;
  4403. var IdleLanes =
  4404. /* */
  4405. 805306368;
  4406. var OffscreenLane =
  4407. /* */
  4408. 1073741824;
  4409. var NoTimestamp = -1;
  4410. function setCurrentUpdateLanePriority(newLanePriority) {
  4411. } // "Registers" used to "return" multiple values
  4412. // Used by getHighestPriorityLanes and getNextLanes:
  4413. var return_highestLanePriority = DefaultLanePriority;
  4414. function getHighestPriorityLanes(lanes) {
  4415. if ((SyncLane & lanes) !== NoLanes) {
  4416. return_highestLanePriority = SyncLanePriority;
  4417. return SyncLane;
  4418. }
  4419. if ((SyncBatchedLane & lanes) !== NoLanes) {
  4420. return_highestLanePriority = SyncBatchedLanePriority;
  4421. return SyncBatchedLane;
  4422. }
  4423. if ((InputDiscreteHydrationLane & lanes) !== NoLanes) {
  4424. return_highestLanePriority = InputDiscreteHydrationLanePriority;
  4425. return InputDiscreteHydrationLane;
  4426. }
  4427. var inputDiscreteLanes = InputDiscreteLanes & lanes;
  4428. if (inputDiscreteLanes !== NoLanes) {
  4429. return_highestLanePriority = InputDiscreteLanePriority;
  4430. return inputDiscreteLanes;
  4431. }
  4432. if ((lanes & InputContinuousHydrationLane) !== NoLanes) {
  4433. return_highestLanePriority = InputContinuousHydrationLanePriority;
  4434. return InputContinuousHydrationLane;
  4435. }
  4436. var inputContinuousLanes = InputContinuousLanes & lanes;
  4437. if (inputContinuousLanes !== NoLanes) {
  4438. return_highestLanePriority = InputContinuousLanePriority;
  4439. return inputContinuousLanes;
  4440. }
  4441. if ((lanes & DefaultHydrationLane) !== NoLanes) {
  4442. return_highestLanePriority = DefaultHydrationLanePriority;
  4443. return DefaultHydrationLane;
  4444. }
  4445. var defaultLanes = DefaultLanes & lanes;
  4446. if (defaultLanes !== NoLanes) {
  4447. return_highestLanePriority = DefaultLanePriority;
  4448. return defaultLanes;
  4449. }
  4450. if ((lanes & TransitionHydrationLane) !== NoLanes) {
  4451. return_highestLanePriority = TransitionHydrationPriority;
  4452. return TransitionHydrationLane;
  4453. }
  4454. var transitionLanes = TransitionLanes & lanes;
  4455. if (transitionLanes !== NoLanes) {
  4456. return_highestLanePriority = TransitionPriority;
  4457. return transitionLanes;
  4458. }
  4459. var retryLanes = RetryLanes & lanes;
  4460. if (retryLanes !== NoLanes) {
  4461. return_highestLanePriority = RetryLanePriority;
  4462. return retryLanes;
  4463. }
  4464. if (lanes & SelectiveHydrationLane) {
  4465. return_highestLanePriority = SelectiveHydrationLanePriority;
  4466. return SelectiveHydrationLane;
  4467. }
  4468. if ((lanes & IdleHydrationLane) !== NoLanes) {
  4469. return_highestLanePriority = IdleHydrationLanePriority;
  4470. return IdleHydrationLane;
  4471. }
  4472. var idleLanes = IdleLanes & lanes;
  4473. if (idleLanes !== NoLanes) {
  4474. return_highestLanePriority = IdleLanePriority;
  4475. return idleLanes;
  4476. }
  4477. if ((OffscreenLane & lanes) !== NoLanes) {
  4478. return_highestLanePriority = OffscreenLanePriority;
  4479. return OffscreenLane;
  4480. }
  4481. {
  4482. error('Should have found matching lanes. This is a bug in React.');
  4483. } // This shouldn't be reachable, but as a fallback, return the entire bitmask.
  4484. return_highestLanePriority = DefaultLanePriority;
  4485. return lanes;
  4486. }
  4487. function schedulerPriorityToLanePriority(schedulerPriorityLevel) {
  4488. switch (schedulerPriorityLevel) {
  4489. case ImmediatePriority:
  4490. return SyncLanePriority;
  4491. case UserBlockingPriority:
  4492. return InputContinuousLanePriority;
  4493. case NormalPriority:
  4494. case LowPriority:
  4495. // TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration.
  4496. return DefaultLanePriority;
  4497. case IdlePriority:
  4498. return IdleLanePriority;
  4499. default:
  4500. return NoLanePriority;
  4501. }
  4502. }
  4503. function lanePriorityToSchedulerPriority(lanePriority) {
  4504. switch (lanePriority) {
  4505. case SyncLanePriority:
  4506. case SyncBatchedLanePriority:
  4507. return ImmediatePriority;
  4508. case InputDiscreteHydrationLanePriority:
  4509. case InputDiscreteLanePriority:
  4510. case InputContinuousHydrationLanePriority:
  4511. case InputContinuousLanePriority:
  4512. return UserBlockingPriority;
  4513. case DefaultHydrationLanePriority:
  4514. case DefaultLanePriority:
  4515. case TransitionHydrationPriority:
  4516. case TransitionPriority:
  4517. case SelectiveHydrationLanePriority:
  4518. case RetryLanePriority:
  4519. return NormalPriority;
  4520. case IdleHydrationLanePriority:
  4521. case IdleLanePriority:
  4522. case OffscreenLanePriority:
  4523. return IdlePriority;
  4524. case NoLanePriority:
  4525. return NoPriority;
  4526. default:
  4527. {
  4528. {
  4529. throw Error( "Invalid update priority: " + lanePriority + ". This is a bug in React." );
  4530. }
  4531. }
  4532. }
  4533. }
  4534. function getNextLanes(root, wipLanes) {
  4535. // Early bailout if there's no pending work left.
  4536. var pendingLanes = root.pendingLanes;
  4537. if (pendingLanes === NoLanes) {
  4538. return_highestLanePriority = NoLanePriority;
  4539. return NoLanes;
  4540. }
  4541. var nextLanes = NoLanes;
  4542. var nextLanePriority = NoLanePriority;
  4543. var expiredLanes = root.expiredLanes;
  4544. var suspendedLanes = root.suspendedLanes;
  4545. var pingedLanes = root.pingedLanes; // Check if any work has expired.
  4546. if (expiredLanes !== NoLanes) {
  4547. nextLanes = expiredLanes;
  4548. nextLanePriority = return_highestLanePriority = SyncLanePriority;
  4549. } else {
  4550. // Do not work on any idle work until all the non-idle work has finished,
  4551. // even if the work is suspended.
  4552. var nonIdlePendingLanes = pendingLanes & NonIdleLanes;
  4553. if (nonIdlePendingLanes !== NoLanes) {
  4554. var nonIdleUnblockedLanes = nonIdlePendingLanes & ~suspendedLanes;
  4555. if (nonIdleUnblockedLanes !== NoLanes) {
  4556. nextLanes = getHighestPriorityLanes(nonIdleUnblockedLanes);
  4557. nextLanePriority = return_highestLanePriority;
  4558. } else {
  4559. var nonIdlePingedLanes = nonIdlePendingLanes & pingedLanes;
  4560. if (nonIdlePingedLanes !== NoLanes) {
  4561. nextLanes = getHighestPriorityLanes(nonIdlePingedLanes);
  4562. nextLanePriority = return_highestLanePriority;
  4563. }
  4564. }
  4565. } else {
  4566. // The only remaining work is Idle.
  4567. var unblockedLanes = pendingLanes & ~suspendedLanes;
  4568. if (unblockedLanes !== NoLanes) {
  4569. nextLanes = getHighestPriorityLanes(unblockedLanes);
  4570. nextLanePriority = return_highestLanePriority;
  4571. } else {
  4572. if (pingedLanes !== NoLanes) {
  4573. nextLanes = getHighestPriorityLanes(pingedLanes);
  4574. nextLanePriority = return_highestLanePriority;
  4575. }
  4576. }
  4577. }
  4578. }
  4579. if (nextLanes === NoLanes) {
  4580. // This should only be reachable if we're suspended
  4581. // TODO: Consider warning in this path if a fallback timer is not scheduled.
  4582. return NoLanes;
  4583. } // If there are higher priority lanes, we'll include them even if they
  4584. // are suspended.
  4585. nextLanes = pendingLanes & getEqualOrHigherPriorityLanes(nextLanes); // If we're already in the middle of a render, switching lanes will interrupt
  4586. // it and we'll lose our progress. We should only do this if the new lanes are
  4587. // higher priority.
  4588. if (wipLanes !== NoLanes && wipLanes !== nextLanes && // If we already suspended with a delay, then interrupting is fine. Don't
  4589. // bother waiting until the root is complete.
  4590. (wipLanes & suspendedLanes) === NoLanes) {
  4591. getHighestPriorityLanes(wipLanes);
  4592. var wipLanePriority = return_highestLanePriority;
  4593. if (nextLanePriority <= wipLanePriority) {
  4594. return wipLanes;
  4595. } else {
  4596. return_highestLanePriority = nextLanePriority;
  4597. }
  4598. } // Check for entangled lanes and add them to the batch.
  4599. //
  4600. // A lane is said to be entangled with another when it's not allowed to render
  4601. // in a batch that does not also include the other lane. Typically we do this
  4602. // when multiple updates have the same source, and we only want to respond to
  4603. // the most recent event from that source.
  4604. //
  4605. // Note that we apply entanglements *after* checking for partial work above.
  4606. // This means that if a lane is entangled during an interleaved event while
  4607. // it's already rendering, we won't interrupt it. This is intentional, since
  4608. // entanglement is usually "best effort": we'll try our best to render the
  4609. // lanes in the same batch, but it's not worth throwing out partially
  4610. // completed work in order to do it.
  4611. //
  4612. // For those exceptions where entanglement is semantically important, like
  4613. // useMutableSource, we should ensure that there is no partial work at the
  4614. // time we apply the entanglement.
  4615. var entangledLanes = root.entangledLanes;
  4616. if (entangledLanes !== NoLanes) {
  4617. var entanglements = root.entanglements;
  4618. var lanes = nextLanes & entangledLanes;
  4619. while (lanes > 0) {
  4620. var index = pickArbitraryLaneIndex(lanes);
  4621. var lane = 1 << index;
  4622. nextLanes |= entanglements[index];
  4623. lanes &= ~lane;
  4624. }
  4625. }
  4626. return nextLanes;
  4627. }
  4628. function getMostRecentEventTime(root, lanes) {
  4629. var eventTimes = root.eventTimes;
  4630. var mostRecentEventTime = NoTimestamp;
  4631. while (lanes > 0) {
  4632. var index = pickArbitraryLaneIndex(lanes);
  4633. var lane = 1 << index;
  4634. var eventTime = eventTimes[index];
  4635. if (eventTime > mostRecentEventTime) {
  4636. mostRecentEventTime = eventTime;
  4637. }
  4638. lanes &= ~lane;
  4639. }
  4640. return mostRecentEventTime;
  4641. }
  4642. function computeExpirationTime(lane, currentTime) {
  4643. // TODO: Expiration heuristic is constant per lane, so could use a map.
  4644. getHighestPriorityLanes(lane);
  4645. var priority = return_highestLanePriority;
  4646. if (priority >= InputContinuousLanePriority) {
  4647. // User interactions should expire slightly more quickly.
  4648. //
  4649. // NOTE: This is set to the corresponding constant as in Scheduler.js. When
  4650. // we made it larger, a product metric in www regressed, suggesting there's
  4651. // a user interaction that's being starved by a series of synchronous
  4652. // updates. If that theory is correct, the proper solution is to fix the
  4653. // starvation. However, this scenario supports the idea that expiration
  4654. // times are an important safeguard when starvation does happen.
  4655. //
  4656. // Also note that, in the case of user input specifically, this will soon no
  4657. // longer be an issue because we plan to make user input synchronous by
  4658. // default (until you enter `startTransition`, of course.)
  4659. //
  4660. // If weren't planning to make these updates synchronous soon anyway, I
  4661. // would probably make this number a configurable parameter.
  4662. return currentTime + 250;
  4663. } else if (priority >= TransitionPriority) {
  4664. return currentTime + 5000;
  4665. } else {
  4666. // Anything idle priority or lower should never expire.
  4667. return NoTimestamp;
  4668. }
  4669. }
  4670. function markStarvedLanesAsExpired(root, currentTime) {
  4671. // TODO: This gets called every time we yield. We can optimize by storing
  4672. // the earliest expiration time on the root. Then use that to quickly bail out
  4673. // of this function.
  4674. var pendingLanes = root.pendingLanes;
  4675. var suspendedLanes = root.suspendedLanes;
  4676. var pingedLanes = root.pingedLanes;
  4677. var expirationTimes = root.expirationTimes; // Iterate through the pending lanes and check if we've reached their
  4678. // expiration time. If so, we'll assume the update is being starved and mark
  4679. // it as expired to force it to finish.
  4680. var lanes = pendingLanes;
  4681. while (lanes > 0) {
  4682. var index = pickArbitraryLaneIndex(lanes);
  4683. var lane = 1 << index;
  4684. var expirationTime = expirationTimes[index];
  4685. if (expirationTime === NoTimestamp) {
  4686. // Found a pending lane with no expiration time. If it's not suspended, or
  4687. // if it's pinged, assume it's CPU-bound. Compute a new expiration time
  4688. // using the current time.
  4689. if ((lane & suspendedLanes) === NoLanes || (lane & pingedLanes) !== NoLanes) {
  4690. // Assumes timestamps are monotonically increasing.
  4691. expirationTimes[index] = computeExpirationTime(lane, currentTime);
  4692. }
  4693. } else if (expirationTime <= currentTime) {
  4694. // This lane expired
  4695. root.expiredLanes |= lane;
  4696. }
  4697. lanes &= ~lane;
  4698. }
  4699. } // This returns the highest priority pending lanes regardless of whether they
  4700. function getLanesToRetrySynchronouslyOnError(root) {
  4701. var everythingButOffscreen = root.pendingLanes & ~OffscreenLane;
  4702. if (everythingButOffscreen !== NoLanes) {
  4703. return everythingButOffscreen;
  4704. }
  4705. if (everythingButOffscreen & OffscreenLane) {
  4706. return OffscreenLane;
  4707. }
  4708. return NoLanes;
  4709. }
  4710. function returnNextLanesPriority() {
  4711. return return_highestLanePriority;
  4712. }
  4713. function includesNonIdleWork(lanes) {
  4714. return (lanes & NonIdleLanes) !== NoLanes;
  4715. }
  4716. function includesOnlyRetries(lanes) {
  4717. return (lanes & RetryLanes) === lanes;
  4718. }
  4719. function includesOnlyTransitions(lanes) {
  4720. return (lanes & TransitionLanes) === lanes;
  4721. } // To ensure consistency across multiple updates in the same event, this should
  4722. // be a pure function, so that it always returns the same lane for given inputs.
  4723. function findUpdateLane(lanePriority, wipLanes) {
  4724. switch (lanePriority) {
  4725. case NoLanePriority:
  4726. break;
  4727. case SyncLanePriority:
  4728. return SyncLane;
  4729. case SyncBatchedLanePriority:
  4730. return SyncBatchedLane;
  4731. case InputDiscreteLanePriority:
  4732. {
  4733. var _lane = pickArbitraryLane(InputDiscreteLanes & ~wipLanes);
  4734. if (_lane === NoLane) {
  4735. // Shift to the next priority level
  4736. return findUpdateLane(InputContinuousLanePriority, wipLanes);
  4737. }
  4738. return _lane;
  4739. }
  4740. case InputContinuousLanePriority:
  4741. {
  4742. var _lane2 = pickArbitraryLane(InputContinuousLanes & ~wipLanes);
  4743. if (_lane2 === NoLane) {
  4744. // Shift to the next priority level
  4745. return findUpdateLane(DefaultLanePriority, wipLanes);
  4746. }
  4747. return _lane2;
  4748. }
  4749. case DefaultLanePriority:
  4750. {
  4751. var _lane3 = pickArbitraryLane(DefaultLanes & ~wipLanes);
  4752. if (_lane3 === NoLane) {
  4753. // If all the default lanes are already being worked on, look for a
  4754. // lane in the transition range.
  4755. _lane3 = pickArbitraryLane(TransitionLanes & ~wipLanes);
  4756. if (_lane3 === NoLane) {
  4757. // All the transition lanes are taken, too. This should be very
  4758. // rare, but as a last resort, pick a default lane. This will have
  4759. // the effect of interrupting the current work-in-progress render.
  4760. _lane3 = pickArbitraryLane(DefaultLanes);
  4761. }
  4762. }
  4763. return _lane3;
  4764. }
  4765. case TransitionPriority: // Should be handled by findTransitionLane instead
  4766. case RetryLanePriority:
  4767. // Should be handled by findRetryLane instead
  4768. break;
  4769. case IdleLanePriority:
  4770. var lane = pickArbitraryLane(IdleLanes & ~wipLanes);
  4771. if (lane === NoLane) {
  4772. lane = pickArbitraryLane(IdleLanes);
  4773. }
  4774. return lane;
  4775. }
  4776. {
  4777. {
  4778. throw Error( "Invalid update priority: " + lanePriority + ". This is a bug in React." );
  4779. }
  4780. }
  4781. } // To ensure consistency across multiple updates in the same event, this should
  4782. // be pure function, so that it always returns the same lane for given inputs.
  4783. function findTransitionLane(wipLanes, pendingLanes) {
  4784. // First look for lanes that are completely unclaimed, i.e. have no
  4785. // pending work.
  4786. var lane = pickArbitraryLane(TransitionLanes & ~pendingLanes);
  4787. if (lane === NoLane) {
  4788. // If all lanes have pending work, look for a lane that isn't currently
  4789. // being worked on.
  4790. lane = pickArbitraryLane(TransitionLanes & ~wipLanes);
  4791. if (lane === NoLane) {
  4792. // If everything is being worked on, pick any lane. This has the
  4793. // effect of interrupting the current work-in-progress.
  4794. lane = pickArbitraryLane(TransitionLanes);
  4795. }
  4796. }
  4797. return lane;
  4798. } // To ensure consistency across multiple updates in the same event, this should
  4799. // be pure function, so that it always returns the same lane for given inputs.
  4800. function findRetryLane(wipLanes) {
  4801. // This is a fork of `findUpdateLane` designed specifically for Suspense
  4802. // "retries" — a special update that attempts to flip a Suspense boundary
  4803. // from its placeholder state to its primary/resolved state.
  4804. var lane = pickArbitraryLane(RetryLanes & ~wipLanes);
  4805. if (lane === NoLane) {
  4806. lane = pickArbitraryLane(RetryLanes);
  4807. }
  4808. return lane;
  4809. }
  4810. function getHighestPriorityLane(lanes) {
  4811. return lanes & -lanes;
  4812. }
  4813. function getLowestPriorityLane(lanes) {
  4814. // This finds the most significant non-zero bit.
  4815. var index = 31 - clz32(lanes);
  4816. return index < 0 ? NoLanes : 1 << index;
  4817. }
  4818. function getEqualOrHigherPriorityLanes(lanes) {
  4819. return (getLowestPriorityLane(lanes) << 1) - 1;
  4820. }
  4821. function pickArbitraryLane(lanes) {
  4822. // This wrapper function gets inlined. Only exists so to communicate that it
  4823. // doesn't matter which bit is selected; you can pick any bit without
  4824. // affecting the algorithms where its used. Here I'm using
  4825. // getHighestPriorityLane because it requires the fewest operations.
  4826. return getHighestPriorityLane(lanes);
  4827. }
  4828. function pickArbitraryLaneIndex(lanes) {
  4829. return 31 - clz32(lanes);
  4830. }
  4831. function laneToIndex(lane) {
  4832. return pickArbitraryLaneIndex(lane);
  4833. }
  4834. function includesSomeLane(a, b) {
  4835. return (a & b) !== NoLanes;
  4836. }
  4837. function isSubsetOfLanes(set, subset) {
  4838. return (set & subset) === subset;
  4839. }
  4840. function mergeLanes(a, b) {
  4841. return a | b;
  4842. }
  4843. function removeLanes(set, subset) {
  4844. return set & ~subset;
  4845. } // Seems redundant, but it changes the type from a single lane (used for
  4846. // updates) to a group of lanes (used for flushing work).
  4847. function laneToLanes(lane) {
  4848. return lane;
  4849. }
  4850. function higherPriorityLane(a, b) {
  4851. // This works because the bit ranges decrease in priority as you go left.
  4852. return a !== NoLane && a < b ? a : b;
  4853. }
  4854. function createLaneMap(initial) {
  4855. // Intentionally pushing one by one.
  4856. // https://v8.dev/blog/elements-kinds#avoid-creating-holes
  4857. var laneMap = [];
  4858. for (var i = 0; i < TotalLanes; i++) {
  4859. laneMap.push(initial);
  4860. }
  4861. return laneMap;
  4862. }
  4863. function markRootUpdated(root, updateLane, eventTime) {
  4864. root.pendingLanes |= updateLane; // TODO: Theoretically, any update to any lane can unblock any other lane. But
  4865. // it's not practical to try every single possible combination. We need a
  4866. // heuristic to decide which lanes to attempt to render, and in which batches.
  4867. // For now, we use the same heuristic as in the old ExpirationTimes model:
  4868. // retry any lane at equal or lower priority, but don't try updates at higher
  4869. // priority without also including the lower priority updates. This works well
  4870. // when considering updates across different priority levels, but isn't
  4871. // sufficient for updates within the same priority, since we want to treat
  4872. // those updates as parallel.
  4873. // Unsuspend any update at equal or lower priority.
  4874. var higherPriorityLanes = updateLane - 1; // Turns 0b1000 into 0b0111
  4875. root.suspendedLanes &= higherPriorityLanes;
  4876. root.pingedLanes &= higherPriorityLanes;
  4877. var eventTimes = root.eventTimes;
  4878. var index = laneToIndex(updateLane); // We can always overwrite an existing timestamp because we prefer the most
  4879. // recent event, and we assume time is monotonically increasing.
  4880. eventTimes[index] = eventTime;
  4881. }
  4882. function markRootSuspended(root, suspendedLanes) {
  4883. root.suspendedLanes |= suspendedLanes;
  4884. root.pingedLanes &= ~suspendedLanes; // The suspended lanes are no longer CPU-bound. Clear their expiration times.
  4885. var expirationTimes = root.expirationTimes;
  4886. var lanes = suspendedLanes;
  4887. while (lanes > 0) {
  4888. var index = pickArbitraryLaneIndex(lanes);
  4889. var lane = 1 << index;
  4890. expirationTimes[index] = NoTimestamp;
  4891. lanes &= ~lane;
  4892. }
  4893. }
  4894. function markRootPinged(root, pingedLanes, eventTime) {
  4895. root.pingedLanes |= root.suspendedLanes & pingedLanes;
  4896. }
  4897. function markDiscreteUpdatesExpired(root) {
  4898. root.expiredLanes |= InputDiscreteLanes & root.pendingLanes;
  4899. }
  4900. function hasDiscreteLanes(lanes) {
  4901. return (lanes & InputDiscreteLanes) !== NoLanes;
  4902. }
  4903. function markRootMutableRead(root, updateLane) {
  4904. root.mutableReadLanes |= updateLane & root.pendingLanes;
  4905. }
  4906. function markRootFinished(root, remainingLanes) {
  4907. var noLongerPendingLanes = root.pendingLanes & ~remainingLanes;
  4908. root.pendingLanes = remainingLanes; // Let's try everything again
  4909. root.suspendedLanes = 0;
  4910. root.pingedLanes = 0;
  4911. root.expiredLanes &= remainingLanes;
  4912. root.mutableReadLanes &= remainingLanes;
  4913. root.entangledLanes &= remainingLanes;
  4914. var entanglements = root.entanglements;
  4915. var eventTimes = root.eventTimes;
  4916. var expirationTimes = root.expirationTimes; // Clear the lanes that no longer have pending work
  4917. var lanes = noLongerPendingLanes;
  4918. while (lanes > 0) {
  4919. var index = pickArbitraryLaneIndex(lanes);
  4920. var lane = 1 << index;
  4921. entanglements[index] = NoLanes;
  4922. eventTimes[index] = NoTimestamp;
  4923. expirationTimes[index] = NoTimestamp;
  4924. lanes &= ~lane;
  4925. }
  4926. }
  4927. function markRootEntangled(root, entangledLanes) {
  4928. root.entangledLanes |= entangledLanes;
  4929. var entanglements = root.entanglements;
  4930. var lanes = entangledLanes;
  4931. while (lanes > 0) {
  4932. var index = pickArbitraryLaneIndex(lanes);
  4933. var lane = 1 << index;
  4934. entanglements[index] |= entangledLanes;
  4935. lanes &= ~lane;
  4936. }
  4937. }
  4938. var clz32 = Math.clz32 ? Math.clz32 : clz32Fallback; // Count leading zeros. Only used on lanes, so assume input is an integer.
  4939. // Based on:
  4940. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
  4941. var log = Math.log;
  4942. var LN2 = Math.LN2;
  4943. function clz32Fallback(lanes) {
  4944. if (lanes === 0) {
  4945. return 32;
  4946. }
  4947. return 31 - (log(lanes) / LN2 | 0) | 0;
  4948. }
  4949. // Intentionally not named imports because Rollup would use dynamic dispatch for
  4950. var UserBlockingPriority$1 = unstable_UserBlockingPriority,
  4951. runWithPriority = unstable_runWithPriority; // TODO: can we stop exporting these?
  4952. var _enabled = true; // This is exported in FB builds for use by legacy FB layer infra.
  4953. // We'd like to remove this but it's not clear if this is safe.
  4954. function setEnabled(enabled) {
  4955. _enabled = !!enabled;
  4956. }
  4957. function isEnabled() {
  4958. return _enabled;
  4959. }
  4960. function createEventListenerWrapperWithPriority(targetContainer, domEventName, eventSystemFlags) {
  4961. var eventPriority = getEventPriorityForPluginSystem(domEventName);
  4962. var listenerWrapper;
  4963. switch (eventPriority) {
  4964. case DiscreteEvent:
  4965. listenerWrapper = dispatchDiscreteEvent;
  4966. break;
  4967. case UserBlockingEvent:
  4968. listenerWrapper = dispatchUserBlockingUpdate;
  4969. break;
  4970. case ContinuousEvent:
  4971. default:
  4972. listenerWrapper = dispatchEvent;
  4973. break;
  4974. }
  4975. return listenerWrapper.bind(null, domEventName, eventSystemFlags, targetContainer);
  4976. }
  4977. function dispatchDiscreteEvent(domEventName, eventSystemFlags, container, nativeEvent) {
  4978. {
  4979. flushDiscreteUpdatesIfNeeded(nativeEvent.timeStamp);
  4980. }
  4981. discreteUpdates(dispatchEvent, domEventName, eventSystemFlags, container, nativeEvent);
  4982. }
  4983. function dispatchUserBlockingUpdate(domEventName, eventSystemFlags, container, nativeEvent) {
  4984. {
  4985. runWithPriority(UserBlockingPriority$1, dispatchEvent.bind(null, domEventName, eventSystemFlags, container, nativeEvent));
  4986. }
  4987. }
  4988. function dispatchEvent(domEventName, eventSystemFlags, targetContainer, nativeEvent) {
  4989. if (!_enabled) {
  4990. return;
  4991. }
  4992. var allowReplay = true;
  4993. {
  4994. // TODO: replaying capture phase events is currently broken
  4995. // because we used to do it during top-level native bubble handlers
  4996. // but now we use different bubble and capture handlers.
  4997. // In eager mode, we attach capture listeners early, so we need
  4998. // to filter them out until we fix the logic to handle them correctly.
  4999. // This could've been outside the flag but I put it inside to reduce risk.
  5000. allowReplay = (eventSystemFlags & IS_CAPTURE_PHASE) === 0;
  5001. }
  5002. if (allowReplay && hasQueuedDiscreteEvents() && isReplayableDiscreteEvent(domEventName)) {
  5003. // If we already have a queue of discrete events, and this is another discrete
  5004. // event, then we can't dispatch it regardless of its target, since they
  5005. // need to dispatch in order.
  5006. queueDiscreteEvent(null, // Flags that we're not actually blocked on anything as far as we know.
  5007. domEventName, eventSystemFlags, targetContainer, nativeEvent);
  5008. return;
  5009. }
  5010. var blockedOn = attemptToDispatchEvent(domEventName, eventSystemFlags, targetContainer, nativeEvent);
  5011. if (blockedOn === null) {
  5012. // We successfully dispatched this event.
  5013. if (allowReplay) {
  5014. clearIfContinuousEvent(domEventName, nativeEvent);
  5015. }
  5016. return;
  5017. }
  5018. if (allowReplay) {
  5019. if (isReplayableDiscreteEvent(domEventName)) {
  5020. // This this to be replayed later once the target is available.
  5021. queueDiscreteEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent);
  5022. return;
  5023. }
  5024. if (queueIfContinuousEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent)) {
  5025. return;
  5026. } // We need to clear only if we didn't queue because
  5027. // queueing is accummulative.
  5028. clearIfContinuousEvent(domEventName, nativeEvent);
  5029. } // This is not replayable so we'll invoke it but without a target,
  5030. // in case the event system needs to trace it.
  5031. dispatchEventForPluginEventSystem(domEventName, eventSystemFlags, nativeEvent, null, targetContainer);
  5032. } // Attempt dispatching an event. Returns a SuspenseInstance or Container if it's blocked.
  5033. function attemptToDispatchEvent(domEventName, eventSystemFlags, targetContainer, nativeEvent) {
  5034. // TODO: Warn if _enabled is false.
  5035. var nativeEventTarget = getEventTarget(nativeEvent);
  5036. var targetInst = getClosestInstanceFromNode(nativeEventTarget);
  5037. if (targetInst !== null) {
  5038. var nearestMounted = getNearestMountedFiber(targetInst);
  5039. if (nearestMounted === null) {
  5040. // This tree has been unmounted already. Dispatch without a target.
  5041. targetInst = null;
  5042. } else {
  5043. var tag = nearestMounted.tag;
  5044. if (tag === SuspenseComponent) {
  5045. var instance = getSuspenseInstanceFromFiber(nearestMounted);
  5046. if (instance !== null) {
  5047. // Queue the event to be replayed later. Abort dispatching since we
  5048. // don't want this event dispatched twice through the event system.
  5049. // TODO: If this is the first discrete event in the queue. Schedule an increased
  5050. // priority for this boundary.
  5051. return instance;
  5052. } // This shouldn't happen, something went wrong but to avoid blocking
  5053. // the whole system, dispatch the event without a target.
  5054. // TODO: Warn.
  5055. targetInst = null;
  5056. } else if (tag === HostRoot) {
  5057. var root = nearestMounted.stateNode;
  5058. if (root.hydrate) {
  5059. // If this happens during a replay something went wrong and it might block
  5060. // the whole system.
  5061. return getContainerFromFiber(nearestMounted);
  5062. }
  5063. targetInst = null;
  5064. } else if (nearestMounted !== targetInst) {
  5065. // If we get an event (ex: img onload) before committing that
  5066. // component's mount, ignore it for now (that is, treat it as if it was an
  5067. // event on a non-React tree). We might also consider queueing events and
  5068. // dispatching them after the mount.
  5069. targetInst = null;
  5070. }
  5071. }
  5072. }
  5073. dispatchEventForPluginEventSystem(domEventName, eventSystemFlags, nativeEvent, targetInst, targetContainer); // We're not blocked on anything.
  5074. return null;
  5075. }
  5076. function addEventBubbleListener(target, eventType, listener) {
  5077. target.addEventListener(eventType, listener, false);
  5078. return listener;
  5079. }
  5080. function addEventCaptureListener(target, eventType, listener) {
  5081. target.addEventListener(eventType, listener, true);
  5082. return listener;
  5083. }
  5084. function addEventCaptureListenerWithPassiveFlag(target, eventType, listener, passive) {
  5085. target.addEventListener(eventType, listener, {
  5086. capture: true,
  5087. passive: passive
  5088. });
  5089. return listener;
  5090. }
  5091. function addEventBubbleListenerWithPassiveFlag(target, eventType, listener, passive) {
  5092. target.addEventListener(eventType, listener, {
  5093. passive: passive
  5094. });
  5095. return listener;
  5096. }
  5097. /**
  5098. * These variables store information about text content of a target node,
  5099. * allowing comparison of content before and after a given event.
  5100. *
  5101. * Identify the node where selection currently begins, then observe
  5102. * both its text content and its current position in the DOM. Since the
  5103. * browser may natively replace the target node during composition, we can
  5104. * use its position to find its replacement.
  5105. *
  5106. *
  5107. */
  5108. var root = null;
  5109. var startText = null;
  5110. var fallbackText = null;
  5111. function initialize(nativeEventTarget) {
  5112. root = nativeEventTarget;
  5113. startText = getText();
  5114. return true;
  5115. }
  5116. function reset() {
  5117. root = null;
  5118. startText = null;
  5119. fallbackText = null;
  5120. }
  5121. function getData() {
  5122. if (fallbackText) {
  5123. return fallbackText;
  5124. }
  5125. var start;
  5126. var startValue = startText;
  5127. var startLength = startValue.length;
  5128. var end;
  5129. var endValue = getText();
  5130. var endLength = endValue.length;
  5131. for (start = 0; start < startLength; start++) {
  5132. if (startValue[start] !== endValue[start]) {
  5133. break;
  5134. }
  5135. }
  5136. var minEnd = startLength - start;
  5137. for (end = 1; end <= minEnd; end++) {
  5138. if (startValue[startLength - end] !== endValue[endLength - end]) {
  5139. break;
  5140. }
  5141. }
  5142. var sliceTail = end > 1 ? 1 - end : undefined;
  5143. fallbackText = endValue.slice(start, sliceTail);
  5144. return fallbackText;
  5145. }
  5146. function getText() {
  5147. if ('value' in root) {
  5148. return root.value;
  5149. }
  5150. return root.textContent;
  5151. }
  5152. /**
  5153. * `charCode` represents the actual "character code" and is safe to use with
  5154. * `String.fromCharCode`. As such, only keys that correspond to printable
  5155. * characters produce a valid `charCode`, the only exception to this is Enter.
  5156. * The Tab-key is considered non-printable and does not have a `charCode`,
  5157. * presumably because it does not produce a tab-character in browsers.
  5158. *
  5159. * @param {object} nativeEvent Native browser event.
  5160. * @return {number} Normalized `charCode` property.
  5161. */
  5162. function getEventCharCode(nativeEvent) {
  5163. var charCode;
  5164. var keyCode = nativeEvent.keyCode;
  5165. if ('charCode' in nativeEvent) {
  5166. charCode = nativeEvent.charCode; // FF does not set `charCode` for the Enter-key, check against `keyCode`.
  5167. if (charCode === 0 && keyCode === 13) {
  5168. charCode = 13;
  5169. }
  5170. } else {
  5171. // IE8 does not implement `charCode`, but `keyCode` has the correct value.
  5172. charCode = keyCode;
  5173. } // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux)
  5174. // report Enter as charCode 10 when ctrl is pressed.
  5175. if (charCode === 10) {
  5176. charCode = 13;
  5177. } // Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
  5178. // Must not discard the (non-)printable Enter-key.
  5179. if (charCode >= 32 || charCode === 13) {
  5180. return charCode;
  5181. }
  5182. return 0;
  5183. }
  5184. function functionThatReturnsTrue() {
  5185. return true;
  5186. }
  5187. function functionThatReturnsFalse() {
  5188. return false;
  5189. } // This is intentionally a factory so that we have different returned constructors.
  5190. // If we had a single constructor, it would be megamorphic and engines would deopt.
  5191. function createSyntheticEvent(Interface) {
  5192. /**
  5193. * Synthetic events are dispatched by event plugins, typically in response to a
  5194. * top-level event delegation handler.
  5195. *
  5196. * These systems should generally use pooling to reduce the frequency of garbage
  5197. * collection. The system should check `isPersistent` to determine whether the
  5198. * event should be released into the pool after being dispatched. Users that
  5199. * need a persisted event should invoke `persist`.
  5200. *
  5201. * Synthetic events (and subclasses) implement the DOM Level 3 Events API by
  5202. * normalizing browser quirks. Subclasses do not necessarily have to implement a
  5203. * DOM interface; custom application-specific events can also subclass this.
  5204. */
  5205. function SyntheticBaseEvent(reactName, reactEventType, targetInst, nativeEvent, nativeEventTarget) {
  5206. this._reactName = reactName;
  5207. this._targetInst = targetInst;
  5208. this.type = reactEventType;
  5209. this.nativeEvent = nativeEvent;
  5210. this.target = nativeEventTarget;
  5211. this.currentTarget = null;
  5212. for (var _propName in Interface) {
  5213. if (!Interface.hasOwnProperty(_propName)) {
  5214. continue;
  5215. }
  5216. var normalize = Interface[_propName];
  5217. if (normalize) {
  5218. this[_propName] = normalize(nativeEvent);
  5219. } else {
  5220. this[_propName] = nativeEvent[_propName];
  5221. }
  5222. }
  5223. var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false;
  5224. if (defaultPrevented) {
  5225. this.isDefaultPrevented = functionThatReturnsTrue;
  5226. } else {
  5227. this.isDefaultPrevented = functionThatReturnsFalse;
  5228. }
  5229. this.isPropagationStopped = functionThatReturnsFalse;
  5230. return this;
  5231. }
  5232. _assign(SyntheticBaseEvent.prototype, {
  5233. preventDefault: function () {
  5234. this.defaultPrevented = true;
  5235. var event = this.nativeEvent;
  5236. if (!event) {
  5237. return;
  5238. }
  5239. if (event.preventDefault) {
  5240. event.preventDefault(); // $FlowFixMe - flow is not aware of `unknown` in IE
  5241. } else if (typeof event.returnValue !== 'unknown') {
  5242. event.returnValue = false;
  5243. }
  5244. this.isDefaultPrevented = functionThatReturnsTrue;
  5245. },
  5246. stopPropagation: function () {
  5247. var event = this.nativeEvent;
  5248. if (!event) {
  5249. return;
  5250. }
  5251. if (event.stopPropagation) {
  5252. event.stopPropagation(); // $FlowFixMe - flow is not aware of `unknown` in IE
  5253. } else if (typeof event.cancelBubble !== 'unknown') {
  5254. // The ChangeEventPlugin registers a "propertychange" event for
  5255. // IE. This event does not support bubbling or cancelling, and
  5256. // any references to cancelBubble throw "Member not found". A
  5257. // typeof check of "unknown" circumvents this issue (and is also
  5258. // IE specific).
  5259. event.cancelBubble = true;
  5260. }
  5261. this.isPropagationStopped = functionThatReturnsTrue;
  5262. },
  5263. /**
  5264. * We release all dispatched `SyntheticEvent`s after each event loop, adding
  5265. * them back into the pool. This allows a way to hold onto a reference that
  5266. * won't be added back into the pool.
  5267. */
  5268. persist: function () {// Modern event system doesn't use pooling.
  5269. },
  5270. /**
  5271. * Checks if this event should be released back into the pool.
  5272. *
  5273. * @return {boolean} True if this should not be released, false otherwise.
  5274. */
  5275. isPersistent: functionThatReturnsTrue
  5276. });
  5277. return SyntheticBaseEvent;
  5278. }
  5279. /**
  5280. * @interface Event
  5281. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  5282. */
  5283. var EventInterface = {
  5284. eventPhase: 0,
  5285. bubbles: 0,
  5286. cancelable: 0,
  5287. timeStamp: function (event) {
  5288. return event.timeStamp || Date.now();
  5289. },
  5290. defaultPrevented: 0,
  5291. isTrusted: 0
  5292. };
  5293. var SyntheticEvent = createSyntheticEvent(EventInterface);
  5294. var UIEventInterface = _assign({}, EventInterface, {
  5295. view: 0,
  5296. detail: 0
  5297. });
  5298. var SyntheticUIEvent = createSyntheticEvent(UIEventInterface);
  5299. var lastMovementX;
  5300. var lastMovementY;
  5301. var lastMouseEvent;
  5302. function updateMouseMovementPolyfillState(event) {
  5303. if (event !== lastMouseEvent) {
  5304. if (lastMouseEvent && event.type === 'mousemove') {
  5305. lastMovementX = event.screenX - lastMouseEvent.screenX;
  5306. lastMovementY = event.screenY - lastMouseEvent.screenY;
  5307. } else {
  5308. lastMovementX = 0;
  5309. lastMovementY = 0;
  5310. }
  5311. lastMouseEvent = event;
  5312. }
  5313. }
  5314. /**
  5315. * @interface MouseEvent
  5316. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  5317. */
  5318. var MouseEventInterface = _assign({}, UIEventInterface, {
  5319. screenX: 0,
  5320. screenY: 0,
  5321. clientX: 0,
  5322. clientY: 0,
  5323. pageX: 0,
  5324. pageY: 0,
  5325. ctrlKey: 0,
  5326. shiftKey: 0,
  5327. altKey: 0,
  5328. metaKey: 0,
  5329. getModifierState: getEventModifierState,
  5330. button: 0,
  5331. buttons: 0,
  5332. relatedTarget: function (event) {
  5333. if (event.relatedTarget === undefined) return event.fromElement === event.srcElement ? event.toElement : event.fromElement;
  5334. return event.relatedTarget;
  5335. },
  5336. movementX: function (event) {
  5337. if ('movementX' in event) {
  5338. return event.movementX;
  5339. }
  5340. updateMouseMovementPolyfillState(event);
  5341. return lastMovementX;
  5342. },
  5343. movementY: function (event) {
  5344. if ('movementY' in event) {
  5345. return event.movementY;
  5346. } // Don't need to call updateMouseMovementPolyfillState() here
  5347. // because it's guaranteed to have already run when movementX
  5348. // was copied.
  5349. return lastMovementY;
  5350. }
  5351. });
  5352. var SyntheticMouseEvent = createSyntheticEvent(MouseEventInterface);
  5353. /**
  5354. * @interface DragEvent
  5355. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  5356. */
  5357. var DragEventInterface = _assign({}, MouseEventInterface, {
  5358. dataTransfer: 0
  5359. });
  5360. var SyntheticDragEvent = createSyntheticEvent(DragEventInterface);
  5361. /**
  5362. * @interface FocusEvent
  5363. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  5364. */
  5365. var FocusEventInterface = _assign({}, UIEventInterface, {
  5366. relatedTarget: 0
  5367. });
  5368. var SyntheticFocusEvent = createSyntheticEvent(FocusEventInterface);
  5369. /**
  5370. * @interface Event
  5371. * @see http://www.w3.org/TR/css3-animations/#AnimationEvent-interface
  5372. * @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent
  5373. */
  5374. var AnimationEventInterface = _assign({}, EventInterface, {
  5375. animationName: 0,
  5376. elapsedTime: 0,
  5377. pseudoElement: 0
  5378. });
  5379. var SyntheticAnimationEvent = createSyntheticEvent(AnimationEventInterface);
  5380. /**
  5381. * @interface Event
  5382. * @see http://www.w3.org/TR/clipboard-apis/
  5383. */
  5384. var ClipboardEventInterface = _assign({}, EventInterface, {
  5385. clipboardData: function (event) {
  5386. return 'clipboardData' in event ? event.clipboardData : window.clipboardData;
  5387. }
  5388. });
  5389. var SyntheticClipboardEvent = createSyntheticEvent(ClipboardEventInterface);
  5390. /**
  5391. * @interface Event
  5392. * @see http://www.w3.org/TR/DOM-Level-3-Events/#events-compositionevents
  5393. */
  5394. var CompositionEventInterface = _assign({}, EventInterface, {
  5395. data: 0
  5396. });
  5397. var SyntheticCompositionEvent = createSyntheticEvent(CompositionEventInterface);
  5398. /**
  5399. * @interface Event
  5400. * @see http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105
  5401. * /#events-inputevents
  5402. */
  5403. // Happens to share the same list for now.
  5404. var SyntheticInputEvent = SyntheticCompositionEvent;
  5405. /**
  5406. * Normalization of deprecated HTML5 `key` values
  5407. * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
  5408. */
  5409. var normalizeKey = {
  5410. Esc: 'Escape',
  5411. Spacebar: ' ',
  5412. Left: 'ArrowLeft',
  5413. Up: 'ArrowUp',
  5414. Right: 'ArrowRight',
  5415. Down: 'ArrowDown',
  5416. Del: 'Delete',
  5417. Win: 'OS',
  5418. Menu: 'ContextMenu',
  5419. Apps: 'ContextMenu',
  5420. Scroll: 'ScrollLock',
  5421. MozPrintableKey: 'Unidentified'
  5422. };
  5423. /**
  5424. * Translation from legacy `keyCode` to HTML5 `key`
  5425. * Only special keys supported, all others depend on keyboard layout or browser
  5426. * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
  5427. */
  5428. var translateToKey = {
  5429. '8': 'Backspace',
  5430. '9': 'Tab',
  5431. '12': 'Clear',
  5432. '13': 'Enter',
  5433. '16': 'Shift',
  5434. '17': 'Control',
  5435. '18': 'Alt',
  5436. '19': 'Pause',
  5437. '20': 'CapsLock',
  5438. '27': 'Escape',
  5439. '32': ' ',
  5440. '33': 'PageUp',
  5441. '34': 'PageDown',
  5442. '35': 'End',
  5443. '36': 'Home',
  5444. '37': 'ArrowLeft',
  5445. '38': 'ArrowUp',
  5446. '39': 'ArrowRight',
  5447. '40': 'ArrowDown',
  5448. '45': 'Insert',
  5449. '46': 'Delete',
  5450. '112': 'F1',
  5451. '113': 'F2',
  5452. '114': 'F3',
  5453. '115': 'F4',
  5454. '116': 'F5',
  5455. '117': 'F6',
  5456. '118': 'F7',
  5457. '119': 'F8',
  5458. '120': 'F9',
  5459. '121': 'F10',
  5460. '122': 'F11',
  5461. '123': 'F12',
  5462. '144': 'NumLock',
  5463. '145': 'ScrollLock',
  5464. '224': 'Meta'
  5465. };
  5466. /**
  5467. * @param {object} nativeEvent Native browser event.
  5468. * @return {string} Normalized `key` property.
  5469. */
  5470. function getEventKey(nativeEvent) {
  5471. if (nativeEvent.key) {
  5472. // Normalize inconsistent values reported by browsers due to
  5473. // implementations of a working draft specification.
  5474. // FireFox implements `key` but returns `MozPrintableKey` for all
  5475. // printable characters (normalized to `Unidentified`), ignore it.
  5476. var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
  5477. if (key !== 'Unidentified') {
  5478. return key;
  5479. }
  5480. } // Browser does not implement `key`, polyfill as much of it as we can.
  5481. if (nativeEvent.type === 'keypress') {
  5482. var charCode = getEventCharCode(nativeEvent); // The enter-key is technically both printable and non-printable and can
  5483. // thus be captured by `keypress`, no other non-printable key should.
  5484. return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
  5485. }
  5486. if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
  5487. // While user keyboard layout determines the actual meaning of each
  5488. // `keyCode` value, almost all function keys have a universal value.
  5489. return translateToKey[nativeEvent.keyCode] || 'Unidentified';
  5490. }
  5491. return '';
  5492. }
  5493. /**
  5494. * Translation from modifier key to the associated property in the event.
  5495. * @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
  5496. */
  5497. var modifierKeyToProp = {
  5498. Alt: 'altKey',
  5499. Control: 'ctrlKey',
  5500. Meta: 'metaKey',
  5501. Shift: 'shiftKey'
  5502. }; // Older browsers (Safari <= 10, iOS Safari <= 10.2) do not support
  5503. // getModifierState. If getModifierState is not supported, we map it to a set of
  5504. // modifier keys exposed by the event. In this case, Lock-keys are not supported.
  5505. function modifierStateGetter(keyArg) {
  5506. var syntheticEvent = this;
  5507. var nativeEvent = syntheticEvent.nativeEvent;
  5508. if (nativeEvent.getModifierState) {
  5509. return nativeEvent.getModifierState(keyArg);
  5510. }
  5511. var keyProp = modifierKeyToProp[keyArg];
  5512. return keyProp ? !!nativeEvent[keyProp] : false;
  5513. }
  5514. function getEventModifierState(nativeEvent) {
  5515. return modifierStateGetter;
  5516. }
  5517. /**
  5518. * @interface KeyboardEvent
  5519. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  5520. */
  5521. var KeyboardEventInterface = _assign({}, UIEventInterface, {
  5522. key: getEventKey,
  5523. code: 0,
  5524. location: 0,
  5525. ctrlKey: 0,
  5526. shiftKey: 0,
  5527. altKey: 0,
  5528. metaKey: 0,
  5529. repeat: 0,
  5530. locale: 0,
  5531. getModifierState: getEventModifierState,
  5532. // Legacy Interface
  5533. charCode: function (event) {
  5534. // `charCode` is the result of a KeyPress event and represents the value of
  5535. // the actual printable character.
  5536. // KeyPress is deprecated, but its replacement is not yet final and not
  5537. // implemented in any major browser. Only KeyPress has charCode.
  5538. if (event.type === 'keypress') {
  5539. return getEventCharCode(event);
  5540. }
  5541. return 0;
  5542. },
  5543. keyCode: function (event) {
  5544. // `keyCode` is the result of a KeyDown/Up event and represents the value of
  5545. // physical keyboard key.
  5546. // The actual meaning of the value depends on the users' keyboard layout
  5547. // which cannot be detected. Assuming that it is a US keyboard layout
  5548. // provides a surprisingly accurate mapping for US and European users.
  5549. // Due to this, it is left to the user to implement at this time.
  5550. if (event.type === 'keydown' || event.type === 'keyup') {
  5551. return event.keyCode;
  5552. }
  5553. return 0;
  5554. },
  5555. which: function (event) {
  5556. // `which` is an alias for either `keyCode` or `charCode` depending on the
  5557. // type of the event.
  5558. if (event.type === 'keypress') {
  5559. return getEventCharCode(event);
  5560. }
  5561. if (event.type === 'keydown' || event.type === 'keyup') {
  5562. return event.keyCode;
  5563. }
  5564. return 0;
  5565. }
  5566. });
  5567. var SyntheticKeyboardEvent = createSyntheticEvent(KeyboardEventInterface);
  5568. /**
  5569. * @interface PointerEvent
  5570. * @see http://www.w3.org/TR/pointerevents/
  5571. */
  5572. var PointerEventInterface = _assign({}, MouseEventInterface, {
  5573. pointerId: 0,
  5574. width: 0,
  5575. height: 0,
  5576. pressure: 0,
  5577. tangentialPressure: 0,
  5578. tiltX: 0,
  5579. tiltY: 0,
  5580. twist: 0,
  5581. pointerType: 0,
  5582. isPrimary: 0
  5583. });
  5584. var SyntheticPointerEvent = createSyntheticEvent(PointerEventInterface);
  5585. /**
  5586. * @interface TouchEvent
  5587. * @see http://www.w3.org/TR/touch-events/
  5588. */
  5589. var TouchEventInterface = _assign({}, UIEventInterface, {
  5590. touches: 0,
  5591. targetTouches: 0,
  5592. changedTouches: 0,
  5593. altKey: 0,
  5594. metaKey: 0,
  5595. ctrlKey: 0,
  5596. shiftKey: 0,
  5597. getModifierState: getEventModifierState
  5598. });
  5599. var SyntheticTouchEvent = createSyntheticEvent(TouchEventInterface);
  5600. /**
  5601. * @interface Event
  5602. * @see http://www.w3.org/TR/2009/WD-css3-transitions-20090320/#transition-events-
  5603. * @see https://developer.mozilla.org/en-US/docs/Web/API/TransitionEvent
  5604. */
  5605. var TransitionEventInterface = _assign({}, EventInterface, {
  5606. propertyName: 0,
  5607. elapsedTime: 0,
  5608. pseudoElement: 0
  5609. });
  5610. var SyntheticTransitionEvent = createSyntheticEvent(TransitionEventInterface);
  5611. /**
  5612. * @interface WheelEvent
  5613. * @see http://www.w3.org/TR/DOM-Level-3-Events/
  5614. */
  5615. var WheelEventInterface = _assign({}, MouseEventInterface, {
  5616. deltaX: function (event) {
  5617. return 'deltaX' in event ? event.deltaX : // Fallback to `wheelDeltaX` for Webkit and normalize (right is positive).
  5618. 'wheelDeltaX' in event ? -event.wheelDeltaX : 0;
  5619. },
  5620. deltaY: function (event) {
  5621. return 'deltaY' in event ? event.deltaY : // Fallback to `wheelDeltaY` for Webkit and normalize (down is positive).
  5622. 'wheelDeltaY' in event ? -event.wheelDeltaY : // Fallback to `wheelDelta` for IE<9 and normalize (down is positive).
  5623. 'wheelDelta' in event ? -event.wheelDelta : 0;
  5624. },
  5625. deltaZ: 0,
  5626. // Browsers without "deltaMode" is reporting in raw wheel delta where one
  5627. // notch on the scroll is always +/- 120, roughly equivalent to pixels.
  5628. // A good approximation of DOM_DELTA_LINE (1) is 5% of viewport size or
  5629. // ~40 pixels, for DOM_DELTA_SCREEN (2) it is 87.5% of viewport size.
  5630. deltaMode: 0
  5631. });
  5632. var SyntheticWheelEvent = createSyntheticEvent(WheelEventInterface);
  5633. var END_KEYCODES = [9, 13, 27, 32]; // Tab, Return, Esc, Space
  5634. var START_KEYCODE = 229;
  5635. var canUseCompositionEvent = canUseDOM && 'CompositionEvent' in window;
  5636. var documentMode = null;
  5637. if (canUseDOM && 'documentMode' in document) {
  5638. documentMode = document.documentMode;
  5639. } // Webkit offers a very useful `textInput` event that can be used to
  5640. // directly represent `beforeInput`. The IE `textinput` event is not as
  5641. // useful, so we don't use it.
  5642. var canUseTextInputEvent = canUseDOM && 'TextEvent' in window && !documentMode; // In IE9+, we have access to composition events, but the data supplied
  5643. // by the native compositionend event may be incorrect. Japanese ideographic
  5644. // spaces, for instance (\u3000) are not recorded correctly.
  5645. var useFallbackCompositionData = canUseDOM && (!canUseCompositionEvent || documentMode && documentMode > 8 && documentMode <= 11);
  5646. var SPACEBAR_CODE = 32;
  5647. var SPACEBAR_CHAR = String.fromCharCode(SPACEBAR_CODE);
  5648. function registerEvents() {
  5649. registerTwoPhaseEvent('onBeforeInput', ['compositionend', 'keypress', 'textInput', 'paste']);
  5650. registerTwoPhaseEvent('onCompositionEnd', ['compositionend', 'focusout', 'keydown', 'keypress', 'keyup', 'mousedown']);
  5651. registerTwoPhaseEvent('onCompositionStart', ['compositionstart', 'focusout', 'keydown', 'keypress', 'keyup', 'mousedown']);
  5652. registerTwoPhaseEvent('onCompositionUpdate', ['compositionupdate', 'focusout', 'keydown', 'keypress', 'keyup', 'mousedown']);
  5653. } // Track whether we've ever handled a keypress on the space key.
  5654. var hasSpaceKeypress = false;
  5655. /**
  5656. * Return whether a native keypress event is assumed to be a command.
  5657. * This is required because Firefox fires `keypress` events for key commands
  5658. * (cut, copy, select-all, etc.) even though no character is inserted.
  5659. */
  5660. function isKeypressCommand(nativeEvent) {
  5661. return (nativeEvent.ctrlKey || nativeEvent.altKey || nativeEvent.metaKey) && // ctrlKey && altKey is equivalent to AltGr, and is not a command.
  5662. !(nativeEvent.ctrlKey && nativeEvent.altKey);
  5663. }
  5664. /**
  5665. * Translate native top level events into event types.
  5666. */
  5667. function getCompositionEventType(domEventName) {
  5668. switch (domEventName) {
  5669. case 'compositionstart':
  5670. return 'onCompositionStart';
  5671. case 'compositionend':
  5672. return 'onCompositionEnd';
  5673. case 'compositionupdate':
  5674. return 'onCompositionUpdate';
  5675. }
  5676. }
  5677. /**
  5678. * Does our fallback best-guess model think this event signifies that
  5679. * composition has begun?
  5680. */
  5681. function isFallbackCompositionStart(domEventName, nativeEvent) {
  5682. return domEventName === 'keydown' && nativeEvent.keyCode === START_KEYCODE;
  5683. }
  5684. /**
  5685. * Does our fallback mode think that this event is the end of composition?
  5686. */
  5687. function isFallbackCompositionEnd(domEventName, nativeEvent) {
  5688. switch (domEventName) {
  5689. case 'keyup':
  5690. // Command keys insert or clear IME input.
  5691. return END_KEYCODES.indexOf(nativeEvent.keyCode) !== -1;
  5692. case 'keydown':
  5693. // Expect IME keyCode on each keydown. If we get any other
  5694. // code we must have exited earlier.
  5695. return nativeEvent.keyCode !== START_KEYCODE;
  5696. case 'keypress':
  5697. case 'mousedown':
  5698. case 'focusout':
  5699. // Events are not possible without cancelling IME.
  5700. return true;
  5701. default:
  5702. return false;
  5703. }
  5704. }
  5705. /**
  5706. * Google Input Tools provides composition data via a CustomEvent,
  5707. * with the `data` property populated in the `detail` object. If this
  5708. * is available on the event object, use it. If not, this is a plain
  5709. * composition event and we have nothing special to extract.
  5710. *
  5711. * @param {object} nativeEvent
  5712. * @return {?string}
  5713. */
  5714. function getDataFromCustomEvent(nativeEvent) {
  5715. var detail = nativeEvent.detail;
  5716. if (typeof detail === 'object' && 'data' in detail) {
  5717. return detail.data;
  5718. }
  5719. return null;
  5720. }
  5721. /**
  5722. * Check if a composition event was triggered by Korean IME.
  5723. * Our fallback mode does not work well with IE's Korean IME,
  5724. * so just use native composition events when Korean IME is used.
  5725. * Although CompositionEvent.locale property is deprecated,
  5726. * it is available in IE, where our fallback mode is enabled.
  5727. *
  5728. * @param {object} nativeEvent
  5729. * @return {boolean}
  5730. */
  5731. function isUsingKoreanIME(nativeEvent) {
  5732. return nativeEvent.locale === 'ko';
  5733. } // Track the current IME composition status, if any.
  5734. var isComposing = false;
  5735. /**
  5736. * @return {?object} A SyntheticCompositionEvent.
  5737. */
  5738. function extractCompositionEvent(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget) {
  5739. var eventType;
  5740. var fallbackData;
  5741. if (canUseCompositionEvent) {
  5742. eventType = getCompositionEventType(domEventName);
  5743. } else if (!isComposing) {
  5744. if (isFallbackCompositionStart(domEventName, nativeEvent)) {
  5745. eventType = 'onCompositionStart';
  5746. }
  5747. } else if (isFallbackCompositionEnd(domEventName, nativeEvent)) {
  5748. eventType = 'onCompositionEnd';
  5749. }
  5750. if (!eventType) {
  5751. return null;
  5752. }
  5753. if (useFallbackCompositionData && !isUsingKoreanIME(nativeEvent)) {
  5754. // The current composition is stored statically and must not be
  5755. // overwritten while composition continues.
  5756. if (!isComposing && eventType === 'onCompositionStart') {
  5757. isComposing = initialize(nativeEventTarget);
  5758. } else if (eventType === 'onCompositionEnd') {
  5759. if (isComposing) {
  5760. fallbackData = getData();
  5761. }
  5762. }
  5763. }
  5764. var listeners = accumulateTwoPhaseListeners(targetInst, eventType);
  5765. if (listeners.length > 0) {
  5766. var event = new SyntheticCompositionEvent(eventType, domEventName, null, nativeEvent, nativeEventTarget);
  5767. dispatchQueue.push({
  5768. event: event,
  5769. listeners: listeners
  5770. });
  5771. if (fallbackData) {
  5772. // Inject data generated from fallback path into the synthetic event.
  5773. // This matches the property of native CompositionEventInterface.
  5774. event.data = fallbackData;
  5775. } else {
  5776. var customData = getDataFromCustomEvent(nativeEvent);
  5777. if (customData !== null) {
  5778. event.data = customData;
  5779. }
  5780. }
  5781. }
  5782. }
  5783. function getNativeBeforeInputChars(domEventName, nativeEvent) {
  5784. switch (domEventName) {
  5785. case 'compositionend':
  5786. return getDataFromCustomEvent(nativeEvent);
  5787. case 'keypress':
  5788. /**
  5789. * If native `textInput` events are available, our goal is to make
  5790. * use of them. However, there is a special case: the spacebar key.
  5791. * In Webkit, preventing default on a spacebar `textInput` event
  5792. * cancels character insertion, but it *also* causes the browser
  5793. * to fall back to its default spacebar behavior of scrolling the
  5794. * page.
  5795. *
  5796. * Tracking at:
  5797. * https://code.google.com/p/chromium/issues/detail?id=355103
  5798. *
  5799. * To avoid this issue, use the keypress event as if no `textInput`
  5800. * event is available.
  5801. */
  5802. var which = nativeEvent.which;
  5803. if (which !== SPACEBAR_CODE) {
  5804. return null;
  5805. }
  5806. hasSpaceKeypress = true;
  5807. return SPACEBAR_CHAR;
  5808. case 'textInput':
  5809. // Record the characters to be added to the DOM.
  5810. var chars = nativeEvent.data; // If it's a spacebar character, assume that we have already handled
  5811. // it at the keypress level and bail immediately. Android Chrome
  5812. // doesn't give us keycodes, so we need to ignore it.
  5813. if (chars === SPACEBAR_CHAR && hasSpaceKeypress) {
  5814. return null;
  5815. }
  5816. return chars;
  5817. default:
  5818. // For other native event types, do nothing.
  5819. return null;
  5820. }
  5821. }
  5822. /**
  5823. * For browsers that do not provide the `textInput` event, extract the
  5824. * appropriate string to use for SyntheticInputEvent.
  5825. */
  5826. function getFallbackBeforeInputChars(domEventName, nativeEvent) {
  5827. // If we are currently composing (IME) and using a fallback to do so,
  5828. // try to extract the composed characters from the fallback object.
  5829. // If composition event is available, we extract a string only at
  5830. // compositionevent, otherwise extract it at fallback events.
  5831. if (isComposing) {
  5832. if (domEventName === 'compositionend' || !canUseCompositionEvent && isFallbackCompositionEnd(domEventName, nativeEvent)) {
  5833. var chars = getData();
  5834. reset();
  5835. isComposing = false;
  5836. return chars;
  5837. }
  5838. return null;
  5839. }
  5840. switch (domEventName) {
  5841. case 'paste':
  5842. // If a paste event occurs after a keypress, throw out the input
  5843. // chars. Paste events should not lead to BeforeInput events.
  5844. return null;
  5845. case 'keypress':
  5846. /**
  5847. * As of v27, Firefox may fire keypress events even when no character
  5848. * will be inserted. A few possibilities:
  5849. *
  5850. * - `which` is `0`. Arrow keys, Esc key, etc.
  5851. *
  5852. * - `which` is the pressed key code, but no char is available.
  5853. * Ex: 'AltGr + d` in Polish. There is no modified character for
  5854. * this key combination and no character is inserted into the
  5855. * document, but FF fires the keypress for char code `100` anyway.
  5856. * No `input` event will occur.
  5857. *
  5858. * - `which` is the pressed key code, but a command combination is
  5859. * being used. Ex: `Cmd+C`. No character is inserted, and no
  5860. * `input` event will occur.
  5861. */
  5862. if (!isKeypressCommand(nativeEvent)) {
  5863. // IE fires the `keypress` event when a user types an emoji via
  5864. // Touch keyboard of Windows. In such a case, the `char` property
  5865. // holds an emoji character like `\uD83D\uDE0A`. Because its length
  5866. // is 2, the property `which` does not represent an emoji correctly.
  5867. // In such a case, we directly return the `char` property instead of
  5868. // using `which`.
  5869. if (nativeEvent.char && nativeEvent.char.length > 1) {
  5870. return nativeEvent.char;
  5871. } else if (nativeEvent.which) {
  5872. return String.fromCharCode(nativeEvent.which);
  5873. }
  5874. }
  5875. return null;
  5876. case 'compositionend':
  5877. return useFallbackCompositionData && !isUsingKoreanIME(nativeEvent) ? null : nativeEvent.data;
  5878. default:
  5879. return null;
  5880. }
  5881. }
  5882. /**
  5883. * Extract a SyntheticInputEvent for `beforeInput`, based on either native
  5884. * `textInput` or fallback behavior.
  5885. *
  5886. * @return {?object} A SyntheticInputEvent.
  5887. */
  5888. function extractBeforeInputEvent(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget) {
  5889. var chars;
  5890. if (canUseTextInputEvent) {
  5891. chars = getNativeBeforeInputChars(domEventName, nativeEvent);
  5892. } else {
  5893. chars = getFallbackBeforeInputChars(domEventName, nativeEvent);
  5894. } // If no characters are being inserted, no BeforeInput event should
  5895. // be fired.
  5896. if (!chars) {
  5897. return null;
  5898. }
  5899. var listeners = accumulateTwoPhaseListeners(targetInst, 'onBeforeInput');
  5900. if (listeners.length > 0) {
  5901. var event = new SyntheticInputEvent('onBeforeInput', 'beforeinput', null, nativeEvent, nativeEventTarget);
  5902. dispatchQueue.push({
  5903. event: event,
  5904. listeners: listeners
  5905. });
  5906. event.data = chars;
  5907. }
  5908. }
  5909. /**
  5910. * Create an `onBeforeInput` event to match
  5911. * http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105/#events-inputevents.
  5912. *
  5913. * This event plugin is based on the native `textInput` event
  5914. * available in Chrome, Safari, Opera, and IE. This event fires after
  5915. * `onKeyPress` and `onCompositionEnd`, but before `onInput`.
  5916. *
  5917. * `beforeInput` is spec'd but not implemented in any browsers, and
  5918. * the `input` event does not provide any useful information about what has
  5919. * actually been added, contrary to the spec. Thus, `textInput` is the best
  5920. * available event to identify the characters that have actually been inserted
  5921. * into the target node.
  5922. *
  5923. * This plugin is also responsible for emitting `composition` events, thus
  5924. * allowing us to share composition fallback code for both `beforeInput` and
  5925. * `composition` event types.
  5926. */
  5927. function extractEvents(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) {
  5928. extractCompositionEvent(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget);
  5929. extractBeforeInputEvent(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget);
  5930. }
  5931. /**
  5932. * @see http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary
  5933. */
  5934. var supportedInputTypes = {
  5935. color: true,
  5936. date: true,
  5937. datetime: true,
  5938. 'datetime-local': true,
  5939. email: true,
  5940. month: true,
  5941. number: true,
  5942. password: true,
  5943. range: true,
  5944. search: true,
  5945. tel: true,
  5946. text: true,
  5947. time: true,
  5948. url: true,
  5949. week: true
  5950. };
  5951. function isTextInputElement(elem) {
  5952. var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
  5953. if (nodeName === 'input') {
  5954. return !!supportedInputTypes[elem.type];
  5955. }
  5956. if (nodeName === 'textarea') {
  5957. return true;
  5958. }
  5959. return false;
  5960. }
  5961. /**
  5962. * Checks if an event is supported in the current execution environment.
  5963. *
  5964. * NOTE: This will not work correctly for non-generic events such as `change`,
  5965. * `reset`, `load`, `error`, and `select`.
  5966. *
  5967. * Borrows from Modernizr.
  5968. *
  5969. * @param {string} eventNameSuffix Event name, e.g. "click".
  5970. * @return {boolean} True if the event is supported.
  5971. * @internal
  5972. * @license Modernizr 3.0.0pre (Custom Build) | MIT
  5973. */
  5974. function isEventSupported(eventNameSuffix) {
  5975. if (!canUseDOM) {
  5976. return false;
  5977. }
  5978. var eventName = 'on' + eventNameSuffix;
  5979. var isSupported = (eventName in document);
  5980. if (!isSupported) {
  5981. var element = document.createElement('div');
  5982. element.setAttribute(eventName, 'return;');
  5983. isSupported = typeof element[eventName] === 'function';
  5984. }
  5985. return isSupported;
  5986. }
  5987. function registerEvents$1() {
  5988. registerTwoPhaseEvent('onChange', ['change', 'click', 'focusin', 'focusout', 'input', 'keydown', 'keyup', 'selectionchange']);
  5989. }
  5990. function createAndAccumulateChangeEvent(dispatchQueue, inst, nativeEvent, target) {
  5991. // Flag this event loop as needing state restore.
  5992. enqueueStateRestore(target);
  5993. var listeners = accumulateTwoPhaseListeners(inst, 'onChange');
  5994. if (listeners.length > 0) {
  5995. var event = new SyntheticEvent('onChange', 'change', null, nativeEvent, target);
  5996. dispatchQueue.push({
  5997. event: event,
  5998. listeners: listeners
  5999. });
  6000. }
  6001. }
  6002. /**
  6003. * For IE shims
  6004. */
  6005. var activeElement = null;
  6006. var activeElementInst = null;
  6007. /**
  6008. * SECTION: handle `change` event
  6009. */
  6010. function shouldUseChangeEvent(elem) {
  6011. var nodeName = elem.nodeName && elem.nodeName.toLowerCase();
  6012. return nodeName === 'select' || nodeName === 'input' && elem.type === 'file';
  6013. }
  6014. function manualDispatchChangeEvent(nativeEvent) {
  6015. var dispatchQueue = [];
  6016. createAndAccumulateChangeEvent(dispatchQueue, activeElementInst, nativeEvent, getEventTarget(nativeEvent)); // If change and propertychange bubbled, we'd just bind to it like all the
  6017. // other events and have it go through ReactBrowserEventEmitter. Since it
  6018. // doesn't, we manually listen for the events and so we have to enqueue and
  6019. // process the abstract event manually.
  6020. //
  6021. // Batching is necessary here in order to ensure that all event handlers run
  6022. // before the next rerender (including event handlers attached to ancestor
  6023. // elements instead of directly on the input). Without this, controlled
  6024. // components don't work properly in conjunction with event bubbling because
  6025. // the component is rerendered and the value reverted before all the event
  6026. // handlers can run. See https://github.com/facebook/react/issues/708.
  6027. batchedUpdates(runEventInBatch, dispatchQueue);
  6028. }
  6029. function runEventInBatch(dispatchQueue) {
  6030. processDispatchQueue(dispatchQueue, 0);
  6031. }
  6032. function getInstIfValueChanged(targetInst) {
  6033. var targetNode = getNodeFromInstance(targetInst);
  6034. if (updateValueIfChanged(targetNode)) {
  6035. return targetInst;
  6036. }
  6037. }
  6038. function getTargetInstForChangeEvent(domEventName, targetInst) {
  6039. if (domEventName === 'change') {
  6040. return targetInst;
  6041. }
  6042. }
  6043. /**
  6044. * SECTION: handle `input` event
  6045. */
  6046. var isInputEventSupported = false;
  6047. if (canUseDOM) {
  6048. // IE9 claims to support the input event but fails to trigger it when
  6049. // deleting text, so we ignore its input events.
  6050. isInputEventSupported = isEventSupported('input') && (!document.documentMode || document.documentMode > 9);
  6051. }
  6052. /**
  6053. * (For IE <=9) Starts tracking propertychange events on the passed-in element
  6054. * and override the value property so that we can distinguish user events from
  6055. * value changes in JS.
  6056. */
  6057. function startWatchingForValueChange(target, targetInst) {
  6058. activeElement = target;
  6059. activeElementInst = targetInst;
  6060. activeElement.attachEvent('onpropertychange', handlePropertyChange);
  6061. }
  6062. /**
  6063. * (For IE <=9) Removes the event listeners from the currently-tracked element,
  6064. * if any exists.
  6065. */
  6066. function stopWatchingForValueChange() {
  6067. if (!activeElement) {
  6068. return;
  6069. }
  6070. activeElement.detachEvent('onpropertychange', handlePropertyChange);
  6071. activeElement = null;
  6072. activeElementInst = null;
  6073. }
  6074. /**
  6075. * (For IE <=9) Handles a propertychange event, sending a `change` event if
  6076. * the value of the active element has changed.
  6077. */
  6078. function handlePropertyChange(nativeEvent) {
  6079. if (nativeEvent.propertyName !== 'value') {
  6080. return;
  6081. }
  6082. if (getInstIfValueChanged(activeElementInst)) {
  6083. manualDispatchChangeEvent(nativeEvent);
  6084. }
  6085. }
  6086. function handleEventsForInputEventPolyfill(domEventName, target, targetInst) {
  6087. if (domEventName === 'focusin') {
  6088. // In IE9, propertychange fires for most input events but is buggy and
  6089. // doesn't fire when text is deleted, but conveniently, selectionchange
  6090. // appears to fire in all of the remaining cases so we catch those and
  6091. // forward the event if the value has changed
  6092. // In either case, we don't want to call the event handler if the value
  6093. // is changed from JS so we redefine a setter for `.value` that updates
  6094. // our activeElementValue variable, allowing us to ignore those changes
  6095. //
  6096. // stopWatching() should be a noop here but we call it just in case we
  6097. // missed a blur event somehow.
  6098. stopWatchingForValueChange();
  6099. startWatchingForValueChange(target, targetInst);
  6100. } else if (domEventName === 'focusout') {
  6101. stopWatchingForValueChange();
  6102. }
  6103. } // For IE8 and IE9.
  6104. function getTargetInstForInputEventPolyfill(domEventName, targetInst) {
  6105. if (domEventName === 'selectionchange' || domEventName === 'keyup' || domEventName === 'keydown') {
  6106. // On the selectionchange event, the target is just document which isn't
  6107. // helpful for us so just check activeElement instead.
  6108. //
  6109. // 99% of the time, keydown and keyup aren't necessary. IE8 fails to fire
  6110. // propertychange on the first input event after setting `value` from a
  6111. // script and fires only keydown, keypress, keyup. Catching keyup usually
  6112. // gets it and catching keydown lets us fire an event for the first
  6113. // keystroke if user does a key repeat (it'll be a little delayed: right
  6114. // before the second keystroke). Other input methods (e.g., paste) seem to
  6115. // fire selectionchange normally.
  6116. return getInstIfValueChanged(activeElementInst);
  6117. }
  6118. }
  6119. /**
  6120. * SECTION: handle `click` event
  6121. */
  6122. function shouldUseClickEvent(elem) {
  6123. // Use the `click` event to detect changes to checkbox and radio inputs.
  6124. // This approach works across all browsers, whereas `change` does not fire
  6125. // until `blur` in IE8.
  6126. var nodeName = elem.nodeName;
  6127. return nodeName && nodeName.toLowerCase() === 'input' && (elem.type === 'checkbox' || elem.type === 'radio');
  6128. }
  6129. function getTargetInstForClickEvent(domEventName, targetInst) {
  6130. if (domEventName === 'click') {
  6131. return getInstIfValueChanged(targetInst);
  6132. }
  6133. }
  6134. function getTargetInstForInputOrChangeEvent(domEventName, targetInst) {
  6135. if (domEventName === 'input' || domEventName === 'change') {
  6136. return getInstIfValueChanged(targetInst);
  6137. }
  6138. }
  6139. function handleControlledInputBlur(node) {
  6140. var state = node._wrapperState;
  6141. if (!state || !state.controlled || node.type !== 'number') {
  6142. return;
  6143. }
  6144. {
  6145. // If controlled, assign the value attribute to the current value on blur
  6146. setDefaultValue(node, 'number', node.value);
  6147. }
  6148. }
  6149. /**
  6150. * This plugin creates an `onChange` event that normalizes change events
  6151. * across form elements. This event fires at a time when it's possible to
  6152. * change the element's value without seeing a flicker.
  6153. *
  6154. * Supported elements are:
  6155. * - input (see `isTextInputElement`)
  6156. * - textarea
  6157. * - select
  6158. */
  6159. function extractEvents$1(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) {
  6160. var targetNode = targetInst ? getNodeFromInstance(targetInst) : window;
  6161. var getTargetInstFunc, handleEventFunc;
  6162. if (shouldUseChangeEvent(targetNode)) {
  6163. getTargetInstFunc = getTargetInstForChangeEvent;
  6164. } else if (isTextInputElement(targetNode)) {
  6165. if (isInputEventSupported) {
  6166. getTargetInstFunc = getTargetInstForInputOrChangeEvent;
  6167. } else {
  6168. getTargetInstFunc = getTargetInstForInputEventPolyfill;
  6169. handleEventFunc = handleEventsForInputEventPolyfill;
  6170. }
  6171. } else if (shouldUseClickEvent(targetNode)) {
  6172. getTargetInstFunc = getTargetInstForClickEvent;
  6173. }
  6174. if (getTargetInstFunc) {
  6175. var inst = getTargetInstFunc(domEventName, targetInst);
  6176. if (inst) {
  6177. createAndAccumulateChangeEvent(dispatchQueue, inst, nativeEvent, nativeEventTarget);
  6178. return;
  6179. }
  6180. }
  6181. if (handleEventFunc) {
  6182. handleEventFunc(domEventName, targetNode, targetInst);
  6183. } // When blurring, set the value attribute for number inputs
  6184. if (domEventName === 'focusout') {
  6185. handleControlledInputBlur(targetNode);
  6186. }
  6187. }
  6188. function registerEvents$2() {
  6189. registerDirectEvent('onMouseEnter', ['mouseout', 'mouseover']);
  6190. registerDirectEvent('onMouseLeave', ['mouseout', 'mouseover']);
  6191. registerDirectEvent('onPointerEnter', ['pointerout', 'pointerover']);
  6192. registerDirectEvent('onPointerLeave', ['pointerout', 'pointerover']);
  6193. }
  6194. /**
  6195. * For almost every interaction we care about, there will be both a top-level
  6196. * `mouseover` and `mouseout` event that occurs. Only use `mouseout` so that
  6197. * we do not extract duplicate events. However, moving the mouse into the
  6198. * browser from outside will not fire a `mouseout` event. In this case, we use
  6199. * the `mouseover` top-level event.
  6200. */
  6201. function extractEvents$2(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) {
  6202. var isOverEvent = domEventName === 'mouseover' || domEventName === 'pointerover';
  6203. var isOutEvent = domEventName === 'mouseout' || domEventName === 'pointerout';
  6204. if (isOverEvent && (eventSystemFlags & IS_REPLAYED) === 0) {
  6205. // If this is an over event with a target, we might have already dispatched
  6206. // the event in the out event of the other target. If this is replayed,
  6207. // then it's because we couldn't dispatch against this target previously
  6208. // so we have to do it now instead.
  6209. var related = nativeEvent.relatedTarget || nativeEvent.fromElement;
  6210. if (related) {
  6211. // If the related node is managed by React, we can assume that we have
  6212. // already dispatched the corresponding events during its mouseout.
  6213. if (getClosestInstanceFromNode(related) || isContainerMarkedAsRoot(related)) {
  6214. return;
  6215. }
  6216. }
  6217. }
  6218. if (!isOutEvent && !isOverEvent) {
  6219. // Must not be a mouse or pointer in or out - ignoring.
  6220. return;
  6221. }
  6222. var win; // TODO: why is this nullable in the types but we read from it?
  6223. if (nativeEventTarget.window === nativeEventTarget) {
  6224. // `nativeEventTarget` is probably a window object.
  6225. win = nativeEventTarget;
  6226. } else {
  6227. // TODO: Figure out why `ownerDocument` is sometimes undefined in IE8.
  6228. var doc = nativeEventTarget.ownerDocument;
  6229. if (doc) {
  6230. win = doc.defaultView || doc.parentWindow;
  6231. } else {
  6232. win = window;
  6233. }
  6234. }
  6235. var from;
  6236. var to;
  6237. if (isOutEvent) {
  6238. var _related = nativeEvent.relatedTarget || nativeEvent.toElement;
  6239. from = targetInst;
  6240. to = _related ? getClosestInstanceFromNode(_related) : null;
  6241. if (to !== null) {
  6242. var nearestMounted = getNearestMountedFiber(to);
  6243. if (to !== nearestMounted || to.tag !== HostComponent && to.tag !== HostText) {
  6244. to = null;
  6245. }
  6246. }
  6247. } else {
  6248. // Moving to a node from outside the window.
  6249. from = null;
  6250. to = targetInst;
  6251. }
  6252. if (from === to) {
  6253. // Nothing pertains to our managed components.
  6254. return;
  6255. }
  6256. var SyntheticEventCtor = SyntheticMouseEvent;
  6257. var leaveEventType = 'onMouseLeave';
  6258. var enterEventType = 'onMouseEnter';
  6259. var eventTypePrefix = 'mouse';
  6260. if (domEventName === 'pointerout' || domEventName === 'pointerover') {
  6261. SyntheticEventCtor = SyntheticPointerEvent;
  6262. leaveEventType = 'onPointerLeave';
  6263. enterEventType = 'onPointerEnter';
  6264. eventTypePrefix = 'pointer';
  6265. }
  6266. var fromNode = from == null ? win : getNodeFromInstance(from);
  6267. var toNode = to == null ? win : getNodeFromInstance(to);
  6268. var leave = new SyntheticEventCtor(leaveEventType, eventTypePrefix + 'leave', from, nativeEvent, nativeEventTarget);
  6269. leave.target = fromNode;
  6270. leave.relatedTarget = toNode;
  6271. var enter = null; // We should only process this nativeEvent if we are processing
  6272. // the first ancestor. Next time, we will ignore the event.
  6273. var nativeTargetInst = getClosestInstanceFromNode(nativeEventTarget);
  6274. if (nativeTargetInst === targetInst) {
  6275. var enterEvent = new SyntheticEventCtor(enterEventType, eventTypePrefix + 'enter', to, nativeEvent, nativeEventTarget);
  6276. enterEvent.target = toNode;
  6277. enterEvent.relatedTarget = fromNode;
  6278. enter = enterEvent;
  6279. }
  6280. accumulateEnterLeaveTwoPhaseListeners(dispatchQueue, leave, enter, from, to);
  6281. }
  6282. /**
  6283. * inlined Object.is polyfill to avoid requiring consumers ship their own
  6284. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  6285. */
  6286. function is(x, y) {
  6287. return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
  6288. ;
  6289. }
  6290. var objectIs = typeof Object.is === 'function' ? Object.is : is;
  6291. var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
  6292. /**
  6293. * Performs equality by iterating through keys on an object and returning false
  6294. * when any key has values which are not strictly equal between the arguments.
  6295. * Returns true when the values of all keys are strictly equal.
  6296. */
  6297. function shallowEqual(objA, objB) {
  6298. if (objectIs(objA, objB)) {
  6299. return true;
  6300. }
  6301. if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
  6302. return false;
  6303. }
  6304. var keysA = Object.keys(objA);
  6305. var keysB = Object.keys(objB);
  6306. if (keysA.length !== keysB.length) {
  6307. return false;
  6308. } // Test for A's keys different from B.
  6309. for (var i = 0; i < keysA.length; i++) {
  6310. if (!hasOwnProperty$2.call(objB, keysA[i]) || !objectIs(objA[keysA[i]], objB[keysA[i]])) {
  6311. return false;
  6312. }
  6313. }
  6314. return true;
  6315. }
  6316. /**
  6317. * Given any node return the first leaf node without children.
  6318. *
  6319. * @param {DOMElement|DOMTextNode} node
  6320. * @return {DOMElement|DOMTextNode}
  6321. */
  6322. function getLeafNode(node) {
  6323. while (node && node.firstChild) {
  6324. node = node.firstChild;
  6325. }
  6326. return node;
  6327. }
  6328. /**
  6329. * Get the next sibling within a container. This will walk up the
  6330. * DOM if a node's siblings have been exhausted.
  6331. *
  6332. * @param {DOMElement|DOMTextNode} node
  6333. * @return {?DOMElement|DOMTextNode}
  6334. */
  6335. function getSiblingNode(node) {
  6336. while (node) {
  6337. if (node.nextSibling) {
  6338. return node.nextSibling;
  6339. }
  6340. node = node.parentNode;
  6341. }
  6342. }
  6343. /**
  6344. * Get object describing the nodes which contain characters at offset.
  6345. *
  6346. * @param {DOMElement|DOMTextNode} root
  6347. * @param {number} offset
  6348. * @return {?object}
  6349. */
  6350. function getNodeForCharacterOffset(root, offset) {
  6351. var node = getLeafNode(root);
  6352. var nodeStart = 0;
  6353. var nodeEnd = 0;
  6354. while (node) {
  6355. if (node.nodeType === TEXT_NODE) {
  6356. nodeEnd = nodeStart + node.textContent.length;
  6357. if (nodeStart <= offset && nodeEnd >= offset) {
  6358. return {
  6359. node: node,
  6360. offset: offset - nodeStart
  6361. };
  6362. }
  6363. nodeStart = nodeEnd;
  6364. }
  6365. node = getLeafNode(getSiblingNode(node));
  6366. }
  6367. }
  6368. /**
  6369. * @param {DOMElement} outerNode
  6370. * @return {?object}
  6371. */
  6372. function getOffsets(outerNode) {
  6373. var ownerDocument = outerNode.ownerDocument;
  6374. var win = ownerDocument && ownerDocument.defaultView || window;
  6375. var selection = win.getSelection && win.getSelection();
  6376. if (!selection || selection.rangeCount === 0) {
  6377. return null;
  6378. }
  6379. var anchorNode = selection.anchorNode,
  6380. anchorOffset = selection.anchorOffset,
  6381. focusNode = selection.focusNode,
  6382. focusOffset = selection.focusOffset; // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the
  6383. // up/down buttons on an <input type="number">. Anonymous divs do not seem to
  6384. // expose properties, triggering a "Permission denied error" if any of its
  6385. // properties are accessed. The only seemingly possible way to avoid erroring
  6386. // is to access a property that typically works for non-anonymous divs and
  6387. // catch any error that may otherwise arise. See
  6388. // https://bugzilla.mozilla.org/show_bug.cgi?id=208427
  6389. try {
  6390. /* eslint-disable no-unused-expressions */
  6391. anchorNode.nodeType;
  6392. focusNode.nodeType;
  6393. /* eslint-enable no-unused-expressions */
  6394. } catch (e) {
  6395. return null;
  6396. }
  6397. return getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset);
  6398. }
  6399. /**
  6400. * Returns {start, end} where `start` is the character/codepoint index of
  6401. * (anchorNode, anchorOffset) within the textContent of `outerNode`, and
  6402. * `end` is the index of (focusNode, focusOffset).
  6403. *
  6404. * Returns null if you pass in garbage input but we should probably just crash.
  6405. *
  6406. * Exported only for testing.
  6407. */
  6408. function getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset) {
  6409. var length = 0;
  6410. var start = -1;
  6411. var end = -1;
  6412. var indexWithinAnchor = 0;
  6413. var indexWithinFocus = 0;
  6414. var node = outerNode;
  6415. var parentNode = null;
  6416. outer: while (true) {
  6417. var next = null;
  6418. while (true) {
  6419. if (node === anchorNode && (anchorOffset === 0 || node.nodeType === TEXT_NODE)) {
  6420. start = length + anchorOffset;
  6421. }
  6422. if (node === focusNode && (focusOffset === 0 || node.nodeType === TEXT_NODE)) {
  6423. end = length + focusOffset;
  6424. }
  6425. if (node.nodeType === TEXT_NODE) {
  6426. length += node.nodeValue.length;
  6427. }
  6428. if ((next = node.firstChild) === null) {
  6429. break;
  6430. } // Moving from `node` to its first child `next`.
  6431. parentNode = node;
  6432. node = next;
  6433. }
  6434. while (true) {
  6435. if (node === outerNode) {
  6436. // If `outerNode` has children, this is always the second time visiting
  6437. // it. If it has no children, this is still the first loop, and the only
  6438. // valid selection is anchorNode and focusNode both equal to this node
  6439. // and both offsets 0, in which case we will have handled above.
  6440. break outer;
  6441. }
  6442. if (parentNode === anchorNode && ++indexWithinAnchor === anchorOffset) {
  6443. start = length;
  6444. }
  6445. if (parentNode === focusNode && ++indexWithinFocus === focusOffset) {
  6446. end = length;
  6447. }
  6448. if ((next = node.nextSibling) !== null) {
  6449. break;
  6450. }
  6451. node = parentNode;
  6452. parentNode = node.parentNode;
  6453. } // Moving from `node` to its next sibling `next`.
  6454. node = next;
  6455. }
  6456. if (start === -1 || end === -1) {
  6457. // This should never happen. (Would happen if the anchor/focus nodes aren't
  6458. // actually inside the passed-in node.)
  6459. return null;
  6460. }
  6461. return {
  6462. start: start,
  6463. end: end
  6464. };
  6465. }
  6466. /**
  6467. * In modern non-IE browsers, we can support both forward and backward
  6468. * selections.
  6469. *
  6470. * Note: IE10+ supports the Selection object, but it does not support
  6471. * the `extend` method, which means that even in modern IE, it's not possible
  6472. * to programmatically create a backward selection. Thus, for all IE
  6473. * versions, we use the old IE API to create our selections.
  6474. *
  6475. * @param {DOMElement|DOMTextNode} node
  6476. * @param {object} offsets
  6477. */
  6478. function setOffsets(node, offsets) {
  6479. var doc = node.ownerDocument || document;
  6480. var win = doc && doc.defaultView || window; // Edge fails with "Object expected" in some scenarios.
  6481. // (For instance: TinyMCE editor used in a list component that supports pasting to add more,
  6482. // fails when pasting 100+ items)
  6483. if (!win.getSelection) {
  6484. return;
  6485. }
  6486. var selection = win.getSelection();
  6487. var length = node.textContent.length;
  6488. var start = Math.min(offsets.start, length);
  6489. var end = offsets.end === undefined ? start : Math.min(offsets.end, length); // IE 11 uses modern selection, but doesn't support the extend method.
  6490. // Flip backward selections, so we can set with a single range.
  6491. if (!selection.extend && start > end) {
  6492. var temp = end;
  6493. end = start;
  6494. start = temp;
  6495. }
  6496. var startMarker = getNodeForCharacterOffset(node, start);
  6497. var endMarker = getNodeForCharacterOffset(node, end);
  6498. if (startMarker && endMarker) {
  6499. if (selection.rangeCount === 1 && selection.anchorNode === startMarker.node && selection.anchorOffset === startMarker.offset && selection.focusNode === endMarker.node && selection.focusOffset === endMarker.offset) {
  6500. return;
  6501. }
  6502. var range = doc.createRange();
  6503. range.setStart(startMarker.node, startMarker.offset);
  6504. selection.removeAllRanges();
  6505. if (start > end) {
  6506. selection.addRange(range);
  6507. selection.extend(endMarker.node, endMarker.offset);
  6508. } else {
  6509. range.setEnd(endMarker.node, endMarker.offset);
  6510. selection.addRange(range);
  6511. }
  6512. }
  6513. }
  6514. function isTextNode(node) {
  6515. return node && node.nodeType === TEXT_NODE;
  6516. }
  6517. function containsNode(outerNode, innerNode) {
  6518. if (!outerNode || !innerNode) {
  6519. return false;
  6520. } else if (outerNode === innerNode) {
  6521. return true;
  6522. } else if (isTextNode(outerNode)) {
  6523. return false;
  6524. } else if (isTextNode(innerNode)) {
  6525. return containsNode(outerNode, innerNode.parentNode);
  6526. } else if ('contains' in outerNode) {
  6527. return outerNode.contains(innerNode);
  6528. } else if (outerNode.compareDocumentPosition) {
  6529. return !!(outerNode.compareDocumentPosition(innerNode) & 16);
  6530. } else {
  6531. return false;
  6532. }
  6533. }
  6534. function isInDocument(node) {
  6535. return node && node.ownerDocument && containsNode(node.ownerDocument.documentElement, node);
  6536. }
  6537. function isSameOriginFrame(iframe) {
  6538. try {
  6539. // Accessing the contentDocument of a HTMLIframeElement can cause the browser
  6540. // to throw, e.g. if it has a cross-origin src attribute.
  6541. // Safari will show an error in the console when the access results in "Blocked a frame with origin". e.g:
  6542. // iframe.contentDocument.defaultView;
  6543. // A safety way is to access one of the cross origin properties: Window or Location
  6544. // Which might result in "SecurityError" DOM Exception and it is compatible to Safari.
  6545. // https://html.spec.whatwg.org/multipage/browsers.html#integration-with-idl
  6546. return typeof iframe.contentWindow.location.href === 'string';
  6547. } catch (err) {
  6548. return false;
  6549. }
  6550. }
  6551. function getActiveElementDeep() {
  6552. var win = window;
  6553. var element = getActiveElement();
  6554. while (element instanceof win.HTMLIFrameElement) {
  6555. if (isSameOriginFrame(element)) {
  6556. win = element.contentWindow;
  6557. } else {
  6558. return element;
  6559. }
  6560. element = getActiveElement(win.document);
  6561. }
  6562. return element;
  6563. }
  6564. /**
  6565. * @ReactInputSelection: React input selection module. Based on Selection.js,
  6566. * but modified to be suitable for react and has a couple of bug fixes (doesn't
  6567. * assume buttons have range selections allowed).
  6568. * Input selection module for React.
  6569. */
  6570. /**
  6571. * @hasSelectionCapabilities: we get the element types that support selection
  6572. * from https://html.spec.whatwg.org/#do-not-apply, looking at `selectionStart`
  6573. * and `selectionEnd` rows.
  6574. */
  6575. function hasSelectionCapabilities(elem) {
  6576. var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
  6577. return nodeName && (nodeName === 'input' && (elem.type === 'text' || elem.type === 'search' || elem.type === 'tel' || elem.type === 'url' || elem.type === 'password') || nodeName === 'textarea' || elem.contentEditable === 'true');
  6578. }
  6579. function getSelectionInformation() {
  6580. var focusedElem = getActiveElementDeep();
  6581. return {
  6582. focusedElem: focusedElem,
  6583. selectionRange: hasSelectionCapabilities(focusedElem) ? getSelection(focusedElem) : null
  6584. };
  6585. }
  6586. /**
  6587. * @restoreSelection: If any selection information was potentially lost,
  6588. * restore it. This is useful when performing operations that could remove dom
  6589. * nodes and place them back in, resulting in focus being lost.
  6590. */
  6591. function restoreSelection(priorSelectionInformation) {
  6592. var curFocusedElem = getActiveElementDeep();
  6593. var priorFocusedElem = priorSelectionInformation.focusedElem;
  6594. var priorSelectionRange = priorSelectionInformation.selectionRange;
  6595. if (curFocusedElem !== priorFocusedElem && isInDocument(priorFocusedElem)) {
  6596. if (priorSelectionRange !== null && hasSelectionCapabilities(priorFocusedElem)) {
  6597. setSelection(priorFocusedElem, priorSelectionRange);
  6598. } // Focusing a node can change the scroll position, which is undesirable
  6599. var ancestors = [];
  6600. var ancestor = priorFocusedElem;
  6601. while (ancestor = ancestor.parentNode) {
  6602. if (ancestor.nodeType === ELEMENT_NODE) {
  6603. ancestors.push({
  6604. element: ancestor,
  6605. left: ancestor.scrollLeft,
  6606. top: ancestor.scrollTop
  6607. });
  6608. }
  6609. }
  6610. if (typeof priorFocusedElem.focus === 'function') {
  6611. priorFocusedElem.focus();
  6612. }
  6613. for (var i = 0; i < ancestors.length; i++) {
  6614. var info = ancestors[i];
  6615. info.element.scrollLeft = info.left;
  6616. info.element.scrollTop = info.top;
  6617. }
  6618. }
  6619. }
  6620. /**
  6621. * @getSelection: Gets the selection bounds of a focused textarea, input or
  6622. * contentEditable node.
  6623. * -@input: Look up selection bounds of this input
  6624. * -@return {start: selectionStart, end: selectionEnd}
  6625. */
  6626. function getSelection(input) {
  6627. var selection;
  6628. if ('selectionStart' in input) {
  6629. // Modern browser with input or textarea.
  6630. selection = {
  6631. start: input.selectionStart,
  6632. end: input.selectionEnd
  6633. };
  6634. } else {
  6635. // Content editable or old IE textarea.
  6636. selection = getOffsets(input);
  6637. }
  6638. return selection || {
  6639. start: 0,
  6640. end: 0
  6641. };
  6642. }
  6643. /**
  6644. * @setSelection: Sets the selection bounds of a textarea or input and focuses
  6645. * the input.
  6646. * -@input Set selection bounds of this input or textarea
  6647. * -@offsets Object of same form that is returned from get*
  6648. */
  6649. function setSelection(input, offsets) {
  6650. var start = offsets.start;
  6651. var end = offsets.end;
  6652. if (end === undefined) {
  6653. end = start;
  6654. }
  6655. if ('selectionStart' in input) {
  6656. input.selectionStart = start;
  6657. input.selectionEnd = Math.min(end, input.value.length);
  6658. } else {
  6659. setOffsets(input, offsets);
  6660. }
  6661. }
  6662. var skipSelectionChangeEvent = canUseDOM && 'documentMode' in document && document.documentMode <= 11;
  6663. function registerEvents$3() {
  6664. registerTwoPhaseEvent('onSelect', ['focusout', 'contextmenu', 'dragend', 'focusin', 'keydown', 'keyup', 'mousedown', 'mouseup', 'selectionchange']);
  6665. }
  6666. var activeElement$1 = null;
  6667. var activeElementInst$1 = null;
  6668. var lastSelection = null;
  6669. var mouseDown = false;
  6670. /**
  6671. * Get an object which is a unique representation of the current selection.
  6672. *
  6673. * The return value will not be consistent across nodes or browsers, but
  6674. * two identical selections on the same node will return identical objects.
  6675. */
  6676. function getSelection$1(node) {
  6677. if ('selectionStart' in node && hasSelectionCapabilities(node)) {
  6678. return {
  6679. start: node.selectionStart,
  6680. end: node.selectionEnd
  6681. };
  6682. } else {
  6683. var win = node.ownerDocument && node.ownerDocument.defaultView || window;
  6684. var selection = win.getSelection();
  6685. return {
  6686. anchorNode: selection.anchorNode,
  6687. anchorOffset: selection.anchorOffset,
  6688. focusNode: selection.focusNode,
  6689. focusOffset: selection.focusOffset
  6690. };
  6691. }
  6692. }
  6693. /**
  6694. * Get document associated with the event target.
  6695. */
  6696. function getEventTargetDocument(eventTarget) {
  6697. return eventTarget.window === eventTarget ? eventTarget.document : eventTarget.nodeType === DOCUMENT_NODE ? eventTarget : eventTarget.ownerDocument;
  6698. }
  6699. /**
  6700. * Poll selection to see whether it's changed.
  6701. *
  6702. * @param {object} nativeEvent
  6703. * @param {object} nativeEventTarget
  6704. * @return {?SyntheticEvent}
  6705. */
  6706. function constructSelectEvent(dispatchQueue, nativeEvent, nativeEventTarget) {
  6707. // Ensure we have the right element, and that the user is not dragging a
  6708. // selection (this matches native `select` event behavior). In HTML5, select
  6709. // fires only on input and textarea thus if there's no focused element we
  6710. // won't dispatch.
  6711. var doc = getEventTargetDocument(nativeEventTarget);
  6712. if (mouseDown || activeElement$1 == null || activeElement$1 !== getActiveElement(doc)) {
  6713. return;
  6714. } // Only fire when selection has actually changed.
  6715. var currentSelection = getSelection$1(activeElement$1);
  6716. if (!lastSelection || !shallowEqual(lastSelection, currentSelection)) {
  6717. lastSelection = currentSelection;
  6718. var listeners = accumulateTwoPhaseListeners(activeElementInst$1, 'onSelect');
  6719. if (listeners.length > 0) {
  6720. var event = new SyntheticEvent('onSelect', 'select', null, nativeEvent, nativeEventTarget);
  6721. dispatchQueue.push({
  6722. event: event,
  6723. listeners: listeners
  6724. });
  6725. event.target = activeElement$1;
  6726. }
  6727. }
  6728. }
  6729. /**
  6730. * This plugin creates an `onSelect` event that normalizes select events
  6731. * across form elements.
  6732. *
  6733. * Supported elements are:
  6734. * - input (see `isTextInputElement`)
  6735. * - textarea
  6736. * - contentEditable
  6737. *
  6738. * This differs from native browser implementations in the following ways:
  6739. * - Fires on contentEditable fields as well as inputs.
  6740. * - Fires for collapsed selection.
  6741. * - Fires after user input.
  6742. */
  6743. function extractEvents$3(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) {
  6744. var targetNode = targetInst ? getNodeFromInstance(targetInst) : window;
  6745. switch (domEventName) {
  6746. // Track the input node that has focus.
  6747. case 'focusin':
  6748. if (isTextInputElement(targetNode) || targetNode.contentEditable === 'true') {
  6749. activeElement$1 = targetNode;
  6750. activeElementInst$1 = targetInst;
  6751. lastSelection = null;
  6752. }
  6753. break;
  6754. case 'focusout':
  6755. activeElement$1 = null;
  6756. activeElementInst$1 = null;
  6757. lastSelection = null;
  6758. break;
  6759. // Don't fire the event while the user is dragging. This matches the
  6760. // semantics of the native select event.
  6761. case 'mousedown':
  6762. mouseDown = true;
  6763. break;
  6764. case 'contextmenu':
  6765. case 'mouseup':
  6766. case 'dragend':
  6767. mouseDown = false;
  6768. constructSelectEvent(dispatchQueue, nativeEvent, nativeEventTarget);
  6769. break;
  6770. // Chrome and IE fire non-standard event when selection is changed (and
  6771. // sometimes when it hasn't). IE's event fires out of order with respect
  6772. // to key and input events on deletion, so we discard it.
  6773. //
  6774. // Firefox doesn't support selectionchange, so check selection status
  6775. // after each key entry. The selection changes after keydown and before
  6776. // keyup, but we check on keydown as well in the case of holding down a
  6777. // key, when multiple keydown events are fired but only one keyup is.
  6778. // This is also our approach for IE handling, for the reason above.
  6779. case 'selectionchange':
  6780. if (skipSelectionChangeEvent) {
  6781. break;
  6782. }
  6783. // falls through
  6784. case 'keydown':
  6785. case 'keyup':
  6786. constructSelectEvent(dispatchQueue, nativeEvent, nativeEventTarget);
  6787. }
  6788. }
  6789. function extractEvents$4(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) {
  6790. var reactName = topLevelEventsToReactNames.get(domEventName);
  6791. if (reactName === undefined) {
  6792. return;
  6793. }
  6794. var SyntheticEventCtor = SyntheticEvent;
  6795. var reactEventType = domEventName;
  6796. switch (domEventName) {
  6797. case 'keypress':
  6798. // Firefox creates a keypress event for function keys too. This removes
  6799. // the unwanted keypress events. Enter is however both printable and
  6800. // non-printable. One would expect Tab to be as well (but it isn't).
  6801. if (getEventCharCode(nativeEvent) === 0) {
  6802. return;
  6803. }
  6804. /* falls through */
  6805. case 'keydown':
  6806. case 'keyup':
  6807. SyntheticEventCtor = SyntheticKeyboardEvent;
  6808. break;
  6809. case 'focusin':
  6810. reactEventType = 'focus';
  6811. SyntheticEventCtor = SyntheticFocusEvent;
  6812. break;
  6813. case 'focusout':
  6814. reactEventType = 'blur';
  6815. SyntheticEventCtor = SyntheticFocusEvent;
  6816. break;
  6817. case 'beforeblur':
  6818. case 'afterblur':
  6819. SyntheticEventCtor = SyntheticFocusEvent;
  6820. break;
  6821. case 'click':
  6822. // Firefox creates a click event on right mouse clicks. This removes the
  6823. // unwanted click events.
  6824. if (nativeEvent.button === 2) {
  6825. return;
  6826. }
  6827. /* falls through */
  6828. case 'auxclick':
  6829. case 'dblclick':
  6830. case 'mousedown':
  6831. case 'mousemove':
  6832. case 'mouseup': // TODO: Disabled elements should not respond to mouse events
  6833. /* falls through */
  6834. case 'mouseout':
  6835. case 'mouseover':
  6836. case 'contextmenu':
  6837. SyntheticEventCtor = SyntheticMouseEvent;
  6838. break;
  6839. case 'drag':
  6840. case 'dragend':
  6841. case 'dragenter':
  6842. case 'dragexit':
  6843. case 'dragleave':
  6844. case 'dragover':
  6845. case 'dragstart':
  6846. case 'drop':
  6847. SyntheticEventCtor = SyntheticDragEvent;
  6848. break;
  6849. case 'touchcancel':
  6850. case 'touchend':
  6851. case 'touchmove':
  6852. case 'touchstart':
  6853. SyntheticEventCtor = SyntheticTouchEvent;
  6854. break;
  6855. case ANIMATION_END:
  6856. case ANIMATION_ITERATION:
  6857. case ANIMATION_START:
  6858. SyntheticEventCtor = SyntheticAnimationEvent;
  6859. break;
  6860. case TRANSITION_END:
  6861. SyntheticEventCtor = SyntheticTransitionEvent;
  6862. break;
  6863. case 'scroll':
  6864. SyntheticEventCtor = SyntheticUIEvent;
  6865. break;
  6866. case 'wheel':
  6867. SyntheticEventCtor = SyntheticWheelEvent;
  6868. break;
  6869. case 'copy':
  6870. case 'cut':
  6871. case 'paste':
  6872. SyntheticEventCtor = SyntheticClipboardEvent;
  6873. break;
  6874. case 'gotpointercapture':
  6875. case 'lostpointercapture':
  6876. case 'pointercancel':
  6877. case 'pointerdown':
  6878. case 'pointermove':
  6879. case 'pointerout':
  6880. case 'pointerover':
  6881. case 'pointerup':
  6882. SyntheticEventCtor = SyntheticPointerEvent;
  6883. break;
  6884. }
  6885. var inCapturePhase = (eventSystemFlags & IS_CAPTURE_PHASE) !== 0;
  6886. {
  6887. // Some events don't bubble in the browser.
  6888. // In the past, React has always bubbled them, but this can be surprising.
  6889. // We're going to try aligning closer to the browser behavior by not bubbling
  6890. // them in React either. We'll start by not bubbling onScroll, and then expand.
  6891. var accumulateTargetOnly = !inCapturePhase && // TODO: ideally, we'd eventually add all events from
  6892. // nonDelegatedEvents list in DOMPluginEventSystem.
  6893. // Then we can remove this special list.
  6894. // This is a breaking change that can wait until React 18.
  6895. domEventName === 'scroll';
  6896. var _listeners = accumulateSinglePhaseListeners(targetInst, reactName, nativeEvent.type, inCapturePhase, accumulateTargetOnly);
  6897. if (_listeners.length > 0) {
  6898. // Intentionally create event lazily.
  6899. var _event = new SyntheticEventCtor(reactName, reactEventType, null, nativeEvent, nativeEventTarget);
  6900. dispatchQueue.push({
  6901. event: _event,
  6902. listeners: _listeners
  6903. });
  6904. }
  6905. }
  6906. }
  6907. // TODO: remove top-level side effect.
  6908. registerSimpleEvents();
  6909. registerEvents$2();
  6910. registerEvents$1();
  6911. registerEvents$3();
  6912. registerEvents();
  6913. function extractEvents$5(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) {
  6914. // TODO: we should remove the concept of a "SimpleEventPlugin".
  6915. // This is the basic functionality of the event system. All
  6916. // the other plugins are essentially polyfills. So the plugin
  6917. // should probably be inlined somewhere and have its logic
  6918. // be core the to event system. This would potentially allow
  6919. // us to ship builds of React without the polyfilled plugins below.
  6920. extractEvents$4(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags);
  6921. var shouldProcessPolyfillPlugins = (eventSystemFlags & SHOULD_NOT_PROCESS_POLYFILL_EVENT_PLUGINS) === 0; // We don't process these events unless we are in the
  6922. // event's native "bubble" phase, which means that we're
  6923. // not in the capture phase. That's because we emulate
  6924. // the capture phase here still. This is a trade-off,
  6925. // because in an ideal world we would not emulate and use
  6926. // the phases properly, like we do with the SimpleEvent
  6927. // plugin. However, the plugins below either expect
  6928. // emulation (EnterLeave) or use state localized to that
  6929. // plugin (BeforeInput, Change, Select). The state in
  6930. // these modules complicates things, as you'll essentially
  6931. // get the case where the capture phase event might change
  6932. // state, only for the following bubble event to come in
  6933. // later and not trigger anything as the state now
  6934. // invalidates the heuristics of the event plugin. We
  6935. // could alter all these plugins to work in such ways, but
  6936. // that might cause other unknown side-effects that we
  6937. // can't forsee right now.
  6938. if (shouldProcessPolyfillPlugins) {
  6939. extractEvents$2(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags);
  6940. extractEvents$1(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget);
  6941. extractEvents$3(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget);
  6942. extractEvents(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget);
  6943. }
  6944. } // List of events that need to be individually attached to media elements.
  6945. var mediaEventTypes = ['abort', 'canplay', 'canplaythrough', 'durationchange', 'emptied', 'encrypted', 'ended', 'error', 'loadeddata', 'loadedmetadata', 'loadstart', 'pause', 'play', 'playing', 'progress', 'ratechange', 'seeked', 'seeking', 'stalled', 'suspend', 'timeupdate', 'volumechange', 'waiting']; // We should not delegate these events to the container, but rather
  6946. // set them on the actual target element itself. This is primarily
  6947. // because these events do not consistently bubble in the DOM.
  6948. var nonDelegatedEvents = new Set(['cancel', 'close', 'invalid', 'load', 'scroll', 'toggle'].concat(mediaEventTypes));
  6949. function executeDispatch(event, listener, currentTarget) {
  6950. var type = event.type || 'unknown-event';
  6951. event.currentTarget = currentTarget;
  6952. invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event);
  6953. event.currentTarget = null;
  6954. }
  6955. function processDispatchQueueItemsInOrder(event, dispatchListeners, inCapturePhase) {
  6956. var previousInstance;
  6957. if (inCapturePhase) {
  6958. for (var i = dispatchListeners.length - 1; i >= 0; i--) {
  6959. var _dispatchListeners$i = dispatchListeners[i],
  6960. instance = _dispatchListeners$i.instance,
  6961. currentTarget = _dispatchListeners$i.currentTarget,
  6962. listener = _dispatchListeners$i.listener;
  6963. if (instance !== previousInstance && event.isPropagationStopped()) {
  6964. return;
  6965. }
  6966. executeDispatch(event, listener, currentTarget);
  6967. previousInstance = instance;
  6968. }
  6969. } else {
  6970. for (var _i = 0; _i < dispatchListeners.length; _i++) {
  6971. var _dispatchListeners$_i = dispatchListeners[_i],
  6972. _instance = _dispatchListeners$_i.instance,
  6973. _currentTarget = _dispatchListeners$_i.currentTarget,
  6974. _listener = _dispatchListeners$_i.listener;
  6975. if (_instance !== previousInstance && event.isPropagationStopped()) {
  6976. return;
  6977. }
  6978. executeDispatch(event, _listener, _currentTarget);
  6979. previousInstance = _instance;
  6980. }
  6981. }
  6982. }
  6983. function processDispatchQueue(dispatchQueue, eventSystemFlags) {
  6984. var inCapturePhase = (eventSystemFlags & IS_CAPTURE_PHASE) !== 0;
  6985. for (var i = 0; i < dispatchQueue.length; i++) {
  6986. var _dispatchQueue$i = dispatchQueue[i],
  6987. event = _dispatchQueue$i.event,
  6988. listeners = _dispatchQueue$i.listeners;
  6989. processDispatchQueueItemsInOrder(event, listeners, inCapturePhase); // event system doesn't use pooling.
  6990. } // This would be a good time to rethrow if any of the event handlers threw.
  6991. rethrowCaughtError();
  6992. }
  6993. function dispatchEventsForPlugins(domEventName, eventSystemFlags, nativeEvent, targetInst, targetContainer) {
  6994. var nativeEventTarget = getEventTarget(nativeEvent);
  6995. var dispatchQueue = [];
  6996. extractEvents$5(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags);
  6997. processDispatchQueue(dispatchQueue, eventSystemFlags);
  6998. }
  6999. function listenToNonDelegatedEvent(domEventName, targetElement) {
  7000. var isCapturePhaseListener = false;
  7001. var listenerSet = getEventListenerSet(targetElement);
  7002. var listenerSetKey = getListenerSetKey(domEventName, isCapturePhaseListener);
  7003. if (!listenerSet.has(listenerSetKey)) {
  7004. addTrappedEventListener(targetElement, domEventName, IS_NON_DELEGATED, isCapturePhaseListener);
  7005. listenerSet.add(listenerSetKey);
  7006. }
  7007. }
  7008. var listeningMarker = '_reactListening' + Math.random().toString(36).slice(2);
  7009. function listenToAllSupportedEvents(rootContainerElement) {
  7010. {
  7011. if (rootContainerElement[listeningMarker]) {
  7012. // Performance optimization: don't iterate through events
  7013. // for the same portal container or root node more than once.
  7014. // TODO: once we remove the flag, we may be able to also
  7015. // remove some of the bookkeeping maps used for laziness.
  7016. return;
  7017. }
  7018. rootContainerElement[listeningMarker] = true;
  7019. allNativeEvents.forEach(function (domEventName) {
  7020. if (!nonDelegatedEvents.has(domEventName)) {
  7021. listenToNativeEvent(domEventName, false, rootContainerElement, null);
  7022. }
  7023. listenToNativeEvent(domEventName, true, rootContainerElement, null);
  7024. });
  7025. }
  7026. }
  7027. function listenToNativeEvent(domEventName, isCapturePhaseListener, rootContainerElement, targetElement) {
  7028. var eventSystemFlags = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
  7029. var target = rootContainerElement; // selectionchange needs to be attached to the document
  7030. // otherwise it won't capture incoming events that are only
  7031. // triggered on the document directly.
  7032. if (domEventName === 'selectionchange' && rootContainerElement.nodeType !== DOCUMENT_NODE) {
  7033. target = rootContainerElement.ownerDocument;
  7034. } // If the event can be delegated (or is capture phase), we can
  7035. // register it to the root container. Otherwise, we should
  7036. // register the event to the target element and mark it as
  7037. // a non-delegated event.
  7038. if (targetElement !== null && !isCapturePhaseListener && nonDelegatedEvents.has(domEventName)) {
  7039. // For all non-delegated events, apart from scroll, we attach
  7040. // their event listeners to the respective elements that their
  7041. // events fire on. That means we can skip this step, as event
  7042. // listener has already been added previously. However, we
  7043. // special case the scroll event because the reality is that any
  7044. // element can scroll.
  7045. // TODO: ideally, we'd eventually apply the same logic to all
  7046. // events from the nonDelegatedEvents list. Then we can remove
  7047. // this special case and use the same logic for all events.
  7048. if (domEventName !== 'scroll') {
  7049. return;
  7050. }
  7051. eventSystemFlags |= IS_NON_DELEGATED;
  7052. target = targetElement;
  7053. }
  7054. var listenerSet = getEventListenerSet(target);
  7055. var listenerSetKey = getListenerSetKey(domEventName, isCapturePhaseListener); // If the listener entry is empty or we should upgrade, then
  7056. // we need to trap an event listener onto the target.
  7057. if (!listenerSet.has(listenerSetKey)) {
  7058. if (isCapturePhaseListener) {
  7059. eventSystemFlags |= IS_CAPTURE_PHASE;
  7060. }
  7061. addTrappedEventListener(target, domEventName, eventSystemFlags, isCapturePhaseListener);
  7062. listenerSet.add(listenerSetKey);
  7063. }
  7064. }
  7065. function addTrappedEventListener(targetContainer, domEventName, eventSystemFlags, isCapturePhaseListener, isDeferredListenerForLegacyFBSupport) {
  7066. var listener = createEventListenerWrapperWithPriority(targetContainer, domEventName, eventSystemFlags); // If passive option is not supported, then the event will be
  7067. // active and not passive.
  7068. var isPassiveListener = undefined;
  7069. if (passiveBrowserEventsSupported) {
  7070. // Browsers introduced an intervention, making these events
  7071. // passive by default on document. React doesn't bind them
  7072. // to document anymore, but changing this now would undo
  7073. // the performance wins from the change. So we emulate
  7074. // the existing behavior manually on the roots now.
  7075. // https://github.com/facebook/react/issues/19651
  7076. if (domEventName === 'touchstart' || domEventName === 'touchmove' || domEventName === 'wheel') {
  7077. isPassiveListener = true;
  7078. }
  7079. }
  7080. targetContainer = targetContainer;
  7081. var unsubscribeListener; // When legacyFBSupport is enabled, it's for when we
  7082. if (isCapturePhaseListener) {
  7083. if (isPassiveListener !== undefined) {
  7084. unsubscribeListener = addEventCaptureListenerWithPassiveFlag(targetContainer, domEventName, listener, isPassiveListener);
  7085. } else {
  7086. unsubscribeListener = addEventCaptureListener(targetContainer, domEventName, listener);
  7087. }
  7088. } else {
  7089. if (isPassiveListener !== undefined) {
  7090. unsubscribeListener = addEventBubbleListenerWithPassiveFlag(targetContainer, domEventName, listener, isPassiveListener);
  7091. } else {
  7092. unsubscribeListener = addEventBubbleListener(targetContainer, domEventName, listener);
  7093. }
  7094. }
  7095. }
  7096. function isMatchingRootContainer(grandContainer, targetContainer) {
  7097. return grandContainer === targetContainer || grandContainer.nodeType === COMMENT_NODE && grandContainer.parentNode === targetContainer;
  7098. }
  7099. function dispatchEventForPluginEventSystem(domEventName, eventSystemFlags, nativeEvent, targetInst, targetContainer) {
  7100. var ancestorInst = targetInst;
  7101. if ((eventSystemFlags & IS_EVENT_HANDLE_NON_MANAGED_NODE) === 0 && (eventSystemFlags & IS_NON_DELEGATED) === 0) {
  7102. var targetContainerNode = targetContainer; // If we are using the legacy FB support flag, we
  7103. if (targetInst !== null) {
  7104. // The below logic attempts to work out if we need to change
  7105. // the target fiber to a different ancestor. We had similar logic
  7106. // in the legacy event system, except the big difference between
  7107. // systems is that the modern event system now has an event listener
  7108. // attached to each React Root and React Portal Root. Together,
  7109. // the DOM nodes representing these roots are the "rootContainer".
  7110. // To figure out which ancestor instance we should use, we traverse
  7111. // up the fiber tree from the target instance and attempt to find
  7112. // root boundaries that match that of our current "rootContainer".
  7113. // If we find that "rootContainer", we find the parent fiber
  7114. // sub-tree for that root and make that our ancestor instance.
  7115. var node = targetInst;
  7116. mainLoop: while (true) {
  7117. if (node === null) {
  7118. return;
  7119. }
  7120. var nodeTag = node.tag;
  7121. if (nodeTag === HostRoot || nodeTag === HostPortal) {
  7122. var container = node.stateNode.containerInfo;
  7123. if (isMatchingRootContainer(container, targetContainerNode)) {
  7124. break;
  7125. }
  7126. if (nodeTag === HostPortal) {
  7127. // The target is a portal, but it's not the rootContainer we're looking for.
  7128. // Normally portals handle their own events all the way down to the root.
  7129. // So we should be able to stop now. However, we don't know if this portal
  7130. // was part of *our* root.
  7131. var grandNode = node.return;
  7132. while (grandNode !== null) {
  7133. var grandTag = grandNode.tag;
  7134. if (grandTag === HostRoot || grandTag === HostPortal) {
  7135. var grandContainer = grandNode.stateNode.containerInfo;
  7136. if (isMatchingRootContainer(grandContainer, targetContainerNode)) {
  7137. // This is the rootContainer we're looking for and we found it as
  7138. // a parent of the Portal. That means we can ignore it because the
  7139. // Portal will bubble through to us.
  7140. return;
  7141. }
  7142. }
  7143. grandNode = grandNode.return;
  7144. }
  7145. } // Now we need to find it's corresponding host fiber in the other
  7146. // tree. To do this we can use getClosestInstanceFromNode, but we
  7147. // need to validate that the fiber is a host instance, otherwise
  7148. // we need to traverse up through the DOM till we find the correct
  7149. // node that is from the other tree.
  7150. while (container !== null) {
  7151. var parentNode = getClosestInstanceFromNode(container);
  7152. if (parentNode === null) {
  7153. return;
  7154. }
  7155. var parentTag = parentNode.tag;
  7156. if (parentTag === HostComponent || parentTag === HostText) {
  7157. node = ancestorInst = parentNode;
  7158. continue mainLoop;
  7159. }
  7160. container = container.parentNode;
  7161. }
  7162. }
  7163. node = node.return;
  7164. }
  7165. }
  7166. }
  7167. batchedEventUpdates(function () {
  7168. return dispatchEventsForPlugins(domEventName, eventSystemFlags, nativeEvent, ancestorInst);
  7169. });
  7170. }
  7171. function createDispatchListener(instance, listener, currentTarget) {
  7172. return {
  7173. instance: instance,
  7174. listener: listener,
  7175. currentTarget: currentTarget
  7176. };
  7177. }
  7178. function accumulateSinglePhaseListeners(targetFiber, reactName, nativeEventType, inCapturePhase, accumulateTargetOnly) {
  7179. var captureName = reactName !== null ? reactName + 'Capture' : null;
  7180. var reactEventName = inCapturePhase ? captureName : reactName;
  7181. var listeners = [];
  7182. var instance = targetFiber;
  7183. var lastHostComponent = null; // Accumulate all instances and listeners via the target -> root path.
  7184. while (instance !== null) {
  7185. var _instance2 = instance,
  7186. stateNode = _instance2.stateNode,
  7187. tag = _instance2.tag; // Handle listeners that are on HostComponents (i.e. <div>)
  7188. if (tag === HostComponent && stateNode !== null) {
  7189. lastHostComponent = stateNode; // createEventHandle listeners
  7190. if (reactEventName !== null) {
  7191. var listener = getListener(instance, reactEventName);
  7192. if (listener != null) {
  7193. listeners.push(createDispatchListener(instance, listener, lastHostComponent));
  7194. }
  7195. }
  7196. } // If we are only accumulating events for the target, then we don't
  7197. // continue to propagate through the React fiber tree to find other
  7198. // listeners.
  7199. if (accumulateTargetOnly) {
  7200. break;
  7201. }
  7202. instance = instance.return;
  7203. }
  7204. return listeners;
  7205. } // We should only use this function for:
  7206. // - BeforeInputEventPlugin
  7207. // - ChangeEventPlugin
  7208. // - SelectEventPlugin
  7209. // This is because we only process these plugins
  7210. // in the bubble phase, so we need to accumulate two
  7211. // phase event listeners (via emulation).
  7212. function accumulateTwoPhaseListeners(targetFiber, reactName) {
  7213. var captureName = reactName + 'Capture';
  7214. var listeners = [];
  7215. var instance = targetFiber; // Accumulate all instances and listeners via the target -> root path.
  7216. while (instance !== null) {
  7217. var _instance3 = instance,
  7218. stateNode = _instance3.stateNode,
  7219. tag = _instance3.tag; // Handle listeners that are on HostComponents (i.e. <div>)
  7220. if (tag === HostComponent && stateNode !== null) {
  7221. var currentTarget = stateNode;
  7222. var captureListener = getListener(instance, captureName);
  7223. if (captureListener != null) {
  7224. listeners.unshift(createDispatchListener(instance, captureListener, currentTarget));
  7225. }
  7226. var bubbleListener = getListener(instance, reactName);
  7227. if (bubbleListener != null) {
  7228. listeners.push(createDispatchListener(instance, bubbleListener, currentTarget));
  7229. }
  7230. }
  7231. instance = instance.return;
  7232. }
  7233. return listeners;
  7234. }
  7235. function getParent(inst) {
  7236. if (inst === null) {
  7237. return null;
  7238. }
  7239. do {
  7240. inst = inst.return; // TODO: If this is a HostRoot we might want to bail out.
  7241. // That is depending on if we want nested subtrees (layers) to bubble
  7242. // events to their parent. We could also go through parentNode on the
  7243. // host node but that wouldn't work for React Native and doesn't let us
  7244. // do the portal feature.
  7245. } while (inst && inst.tag !== HostComponent);
  7246. if (inst) {
  7247. return inst;
  7248. }
  7249. return null;
  7250. }
  7251. /**
  7252. * Return the lowest common ancestor of A and B, or null if they are in
  7253. * different trees.
  7254. */
  7255. function getLowestCommonAncestor(instA, instB) {
  7256. var nodeA = instA;
  7257. var nodeB = instB;
  7258. var depthA = 0;
  7259. for (var tempA = nodeA; tempA; tempA = getParent(tempA)) {
  7260. depthA++;
  7261. }
  7262. var depthB = 0;
  7263. for (var tempB = nodeB; tempB; tempB = getParent(tempB)) {
  7264. depthB++;
  7265. } // If A is deeper, crawl up.
  7266. while (depthA - depthB > 0) {
  7267. nodeA = getParent(nodeA);
  7268. depthA--;
  7269. } // If B is deeper, crawl up.
  7270. while (depthB - depthA > 0) {
  7271. nodeB = getParent(nodeB);
  7272. depthB--;
  7273. } // Walk in lockstep until we find a match.
  7274. var depth = depthA;
  7275. while (depth--) {
  7276. if (nodeA === nodeB || nodeB !== null && nodeA === nodeB.alternate) {
  7277. return nodeA;
  7278. }
  7279. nodeA = getParent(nodeA);
  7280. nodeB = getParent(nodeB);
  7281. }
  7282. return null;
  7283. }
  7284. function accumulateEnterLeaveListenersForEvent(dispatchQueue, event, target, common, inCapturePhase) {
  7285. var registrationName = event._reactName;
  7286. var listeners = [];
  7287. var instance = target;
  7288. while (instance !== null) {
  7289. if (instance === common) {
  7290. break;
  7291. }
  7292. var _instance4 = instance,
  7293. alternate = _instance4.alternate,
  7294. stateNode = _instance4.stateNode,
  7295. tag = _instance4.tag;
  7296. if (alternate !== null && alternate === common) {
  7297. break;
  7298. }
  7299. if (tag === HostComponent && stateNode !== null) {
  7300. var currentTarget = stateNode;
  7301. if (inCapturePhase) {
  7302. var captureListener = getListener(instance, registrationName);
  7303. if (captureListener != null) {
  7304. listeners.unshift(createDispatchListener(instance, captureListener, currentTarget));
  7305. }
  7306. } else if (!inCapturePhase) {
  7307. var bubbleListener = getListener(instance, registrationName);
  7308. if (bubbleListener != null) {
  7309. listeners.push(createDispatchListener(instance, bubbleListener, currentTarget));
  7310. }
  7311. }
  7312. }
  7313. instance = instance.return;
  7314. }
  7315. if (listeners.length !== 0) {
  7316. dispatchQueue.push({
  7317. event: event,
  7318. listeners: listeners
  7319. });
  7320. }
  7321. } // We should only use this function for:
  7322. // - EnterLeaveEventPlugin
  7323. // This is because we only process this plugin
  7324. // in the bubble phase, so we need to accumulate two
  7325. // phase event listeners.
  7326. function accumulateEnterLeaveTwoPhaseListeners(dispatchQueue, leaveEvent, enterEvent, from, to) {
  7327. var common = from && to ? getLowestCommonAncestor(from, to) : null;
  7328. if (from !== null) {
  7329. accumulateEnterLeaveListenersForEvent(dispatchQueue, leaveEvent, from, common, false);
  7330. }
  7331. if (to !== null && enterEvent !== null) {
  7332. accumulateEnterLeaveListenersForEvent(dispatchQueue, enterEvent, to, common, true);
  7333. }
  7334. }
  7335. function getListenerSetKey(domEventName, capture) {
  7336. return domEventName + "__" + (capture ? 'capture' : 'bubble');
  7337. }
  7338. var didWarnInvalidHydration = false;
  7339. var DANGEROUSLY_SET_INNER_HTML = 'dangerouslySetInnerHTML';
  7340. var SUPPRESS_CONTENT_EDITABLE_WARNING = 'suppressContentEditableWarning';
  7341. var SUPPRESS_HYDRATION_WARNING = 'suppressHydrationWarning';
  7342. var AUTOFOCUS = 'autoFocus';
  7343. var CHILDREN = 'children';
  7344. var STYLE = 'style';
  7345. var HTML$1 = '__html';
  7346. var HTML_NAMESPACE$1 = Namespaces.html;
  7347. var warnedUnknownTags;
  7348. var suppressHydrationWarning;
  7349. var validatePropertiesInDevelopment;
  7350. var warnForTextDifference;
  7351. var warnForPropDifference;
  7352. var warnForExtraAttributes;
  7353. var warnForInvalidEventListener;
  7354. var canDiffStyleForHydrationWarning;
  7355. var normalizeMarkupForTextOrAttribute;
  7356. var normalizeHTML;
  7357. {
  7358. warnedUnknownTags = {
  7359. // There are working polyfills for <dialog>. Let people use it.
  7360. dialog: true,
  7361. // Electron ships a custom <webview> tag to display external web content in
  7362. // an isolated frame and process.
  7363. // This tag is not present in non Electron environments such as JSDom which
  7364. // is often used for testing purposes.
  7365. // @see https://electronjs.org/docs/api/webview-tag
  7366. webview: true
  7367. };
  7368. validatePropertiesInDevelopment = function (type, props) {
  7369. validateProperties(type, props);
  7370. validateProperties$1(type, props);
  7371. validateProperties$2(type, props, {
  7372. registrationNameDependencies: registrationNameDependencies,
  7373. possibleRegistrationNames: possibleRegistrationNames
  7374. });
  7375. }; // IE 11 parses & normalizes the style attribute as opposed to other
  7376. // browsers. It adds spaces and sorts the properties in some
  7377. // non-alphabetical order. Handling that would require sorting CSS
  7378. // properties in the client & server versions or applying
  7379. // `expectedStyle` to a temporary DOM node to read its `style` attribute
  7380. // normalized. Since it only affects IE, we're skipping style warnings
  7381. // in that browser completely in favor of doing all that work.
  7382. // See https://github.com/facebook/react/issues/11807
  7383. canDiffStyleForHydrationWarning = canUseDOM && !document.documentMode; // HTML parsing normalizes CR and CRLF to LF.
  7384. // It also can turn \u0000 into \uFFFD inside attributes.
  7385. // https://www.w3.org/TR/html5/single-page.html#preprocessing-the-input-stream
  7386. // If we have a mismatch, it might be caused by that.
  7387. // We will still patch up in this case but not fire the warning.
  7388. var NORMALIZE_NEWLINES_REGEX = /\r\n?/g;
  7389. var NORMALIZE_NULL_AND_REPLACEMENT_REGEX = /\u0000|\uFFFD/g;
  7390. normalizeMarkupForTextOrAttribute = function (markup) {
  7391. var markupString = typeof markup === 'string' ? markup : '' + markup;
  7392. return markupString.replace(NORMALIZE_NEWLINES_REGEX, '\n').replace(NORMALIZE_NULL_AND_REPLACEMENT_REGEX, '');
  7393. };
  7394. warnForTextDifference = function (serverText, clientText) {
  7395. if (didWarnInvalidHydration) {
  7396. return;
  7397. }
  7398. var normalizedClientText = normalizeMarkupForTextOrAttribute(clientText);
  7399. var normalizedServerText = normalizeMarkupForTextOrAttribute(serverText);
  7400. if (normalizedServerText === normalizedClientText) {
  7401. return;
  7402. }
  7403. didWarnInvalidHydration = true;
  7404. error('Text content did not match. Server: "%s" Client: "%s"', normalizedServerText, normalizedClientText);
  7405. };
  7406. warnForPropDifference = function (propName, serverValue, clientValue) {
  7407. if (didWarnInvalidHydration) {
  7408. return;
  7409. }
  7410. var normalizedClientValue = normalizeMarkupForTextOrAttribute(clientValue);
  7411. var normalizedServerValue = normalizeMarkupForTextOrAttribute(serverValue);
  7412. if (normalizedServerValue === normalizedClientValue) {
  7413. return;
  7414. }
  7415. didWarnInvalidHydration = true;
  7416. error('Prop `%s` did not match. Server: %s Client: %s', propName, JSON.stringify(normalizedServerValue), JSON.stringify(normalizedClientValue));
  7417. };
  7418. warnForExtraAttributes = function (attributeNames) {
  7419. if (didWarnInvalidHydration) {
  7420. return;
  7421. }
  7422. didWarnInvalidHydration = true;
  7423. var names = [];
  7424. attributeNames.forEach(function (name) {
  7425. names.push(name);
  7426. });
  7427. error('Extra attributes from the server: %s', names);
  7428. };
  7429. warnForInvalidEventListener = function (registrationName, listener) {
  7430. if (listener === false) {
  7431. error('Expected `%s` listener to be a function, instead got `false`.\n\n' + 'If you used to conditionally omit it with %s={condition && value}, ' + 'pass %s={condition ? value : undefined} instead.', registrationName, registrationName, registrationName);
  7432. } else {
  7433. error('Expected `%s` listener to be a function, instead got a value of `%s` type.', registrationName, typeof listener);
  7434. }
  7435. }; // Parse the HTML and read it back to normalize the HTML string so that it
  7436. // can be used for comparison.
  7437. normalizeHTML = function (parent, html) {
  7438. // We could have created a separate document here to avoid
  7439. // re-initializing custom elements if they exist. But this breaks
  7440. // how <noscript> is being handled. So we use the same document.
  7441. // See the discussion in https://github.com/facebook/react/pull/11157.
  7442. var testElement = parent.namespaceURI === HTML_NAMESPACE$1 ? parent.ownerDocument.createElement(parent.tagName) : parent.ownerDocument.createElementNS(parent.namespaceURI, parent.tagName);
  7443. testElement.innerHTML = html;
  7444. return testElement.innerHTML;
  7445. };
  7446. }
  7447. function getOwnerDocumentFromRootContainer(rootContainerElement) {
  7448. return rootContainerElement.nodeType === DOCUMENT_NODE ? rootContainerElement : rootContainerElement.ownerDocument;
  7449. }
  7450. function noop() {}
  7451. function trapClickOnNonInteractiveElement(node) {
  7452. // Mobile Safari does not fire properly bubble click events on
  7453. // non-interactive elements, which means delegated click listeners do not
  7454. // fire. The workaround for this bug involves attaching an empty click
  7455. // listener on the target node.
  7456. // https://www.quirksmode.org/blog/archives/2010/09/click_event_del.html
  7457. // Just set it using the onclick property so that we don't have to manage any
  7458. // bookkeeping for it. Not sure if we need to clear it when the listener is
  7459. // removed.
  7460. // TODO: Only do this for the relevant Safaris maybe?
  7461. node.onclick = noop;
  7462. }
  7463. function setInitialDOMProperties(tag, domElement, rootContainerElement, nextProps, isCustomComponentTag) {
  7464. for (var propKey in nextProps) {
  7465. if (!nextProps.hasOwnProperty(propKey)) {
  7466. continue;
  7467. }
  7468. var nextProp = nextProps[propKey];
  7469. if (propKey === STYLE) {
  7470. {
  7471. if (nextProp) {
  7472. // Freeze the next style object so that we can assume it won't be
  7473. // mutated. We have already warned for this in the past.
  7474. Object.freeze(nextProp);
  7475. }
  7476. } // Relies on `updateStylesByID` not mutating `styleUpdates`.
  7477. setValueForStyles(domElement, nextProp);
  7478. } else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
  7479. var nextHtml = nextProp ? nextProp[HTML$1] : undefined;
  7480. if (nextHtml != null) {
  7481. setInnerHTML(domElement, nextHtml);
  7482. }
  7483. } else if (propKey === CHILDREN) {
  7484. if (typeof nextProp === 'string') {
  7485. // Avoid setting initial textContent when the text is empty. In IE11 setting
  7486. // textContent on a <textarea> will cause the placeholder to not
  7487. // show within the <textarea> until it has been focused and blurred again.
  7488. // https://github.com/facebook/react/issues/6731#issuecomment-254874553
  7489. var canSetTextContent = tag !== 'textarea' || nextProp !== '';
  7490. if (canSetTextContent) {
  7491. setTextContent(domElement, nextProp);
  7492. }
  7493. } else if (typeof nextProp === 'number') {
  7494. setTextContent(domElement, '' + nextProp);
  7495. }
  7496. } else if (propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING) ; else if (propKey === AUTOFOCUS) ; else if (registrationNameDependencies.hasOwnProperty(propKey)) {
  7497. if (nextProp != null) {
  7498. if ( typeof nextProp !== 'function') {
  7499. warnForInvalidEventListener(propKey, nextProp);
  7500. }
  7501. if (propKey === 'onScroll') {
  7502. listenToNonDelegatedEvent('scroll', domElement);
  7503. }
  7504. }
  7505. } else if (nextProp != null) {
  7506. setValueForProperty(domElement, propKey, nextProp, isCustomComponentTag);
  7507. }
  7508. }
  7509. }
  7510. function updateDOMProperties(domElement, updatePayload, wasCustomComponentTag, isCustomComponentTag) {
  7511. // TODO: Handle wasCustomComponentTag
  7512. for (var i = 0; i < updatePayload.length; i += 2) {
  7513. var propKey = updatePayload[i];
  7514. var propValue = updatePayload[i + 1];
  7515. if (propKey === STYLE) {
  7516. setValueForStyles(domElement, propValue);
  7517. } else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
  7518. setInnerHTML(domElement, propValue);
  7519. } else if (propKey === CHILDREN) {
  7520. setTextContent(domElement, propValue);
  7521. } else {
  7522. setValueForProperty(domElement, propKey, propValue, isCustomComponentTag);
  7523. }
  7524. }
  7525. }
  7526. function createElement(type, props, rootContainerElement, parentNamespace) {
  7527. var isCustomComponentTag; // We create tags in the namespace of their parent container, except HTML
  7528. // tags get no namespace.
  7529. var ownerDocument = getOwnerDocumentFromRootContainer(rootContainerElement);
  7530. var domElement;
  7531. var namespaceURI = parentNamespace;
  7532. if (namespaceURI === HTML_NAMESPACE$1) {
  7533. namespaceURI = getIntrinsicNamespace(type);
  7534. }
  7535. if (namespaceURI === HTML_NAMESPACE$1) {
  7536. {
  7537. isCustomComponentTag = isCustomComponent(type, props); // Should this check be gated by parent namespace? Not sure we want to
  7538. // allow <SVG> or <mATH>.
  7539. if (!isCustomComponentTag && type !== type.toLowerCase()) {
  7540. error('<%s /> is using incorrect casing. ' + 'Use PascalCase for React components, ' + 'or lowercase for HTML elements.', type);
  7541. }
  7542. }
  7543. if (type === 'script') {
  7544. // Create the script via .innerHTML so its "parser-inserted" flag is
  7545. // set to true and it does not execute
  7546. var div = ownerDocument.createElement('div');
  7547. div.innerHTML = '<script><' + '/script>'; // eslint-disable-line
  7548. // This is guaranteed to yield a script element.
  7549. var firstChild = div.firstChild;
  7550. domElement = div.removeChild(firstChild);
  7551. } else if (typeof props.is === 'string') {
  7552. // $FlowIssue `createElement` should be updated for Web Components
  7553. domElement = ownerDocument.createElement(type, {
  7554. is: props.is
  7555. });
  7556. } else {
  7557. // Separate else branch instead of using `props.is || undefined` above because of a Firefox bug.
  7558. // See discussion in https://github.com/facebook/react/pull/6896
  7559. // and discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1276240
  7560. domElement = ownerDocument.createElement(type); // Normally attributes are assigned in `setInitialDOMProperties`, however the `multiple` and `size`
  7561. // attributes on `select`s needs to be added before `option`s are inserted.
  7562. // This prevents:
  7563. // - a bug where the `select` does not scroll to the correct option because singular
  7564. // `select` elements automatically pick the first item #13222
  7565. // - a bug where the `select` set the first item as selected despite the `size` attribute #14239
  7566. // See https://github.com/facebook/react/issues/13222
  7567. // and https://github.com/facebook/react/issues/14239
  7568. if (type === 'select') {
  7569. var node = domElement;
  7570. if (props.multiple) {
  7571. node.multiple = true;
  7572. } else if (props.size) {
  7573. // Setting a size greater than 1 causes a select to behave like `multiple=true`, where
  7574. // it is possible that no option is selected.
  7575. //
  7576. // This is only necessary when a select in "single selection mode".
  7577. node.size = props.size;
  7578. }
  7579. }
  7580. }
  7581. } else {
  7582. domElement = ownerDocument.createElementNS(namespaceURI, type);
  7583. }
  7584. {
  7585. if (namespaceURI === HTML_NAMESPACE$1) {
  7586. if (!isCustomComponentTag && Object.prototype.toString.call(domElement) === '[object HTMLUnknownElement]' && !Object.prototype.hasOwnProperty.call(warnedUnknownTags, type)) {
  7587. warnedUnknownTags[type] = true;
  7588. error('The tag <%s> is unrecognized in this browser. ' + 'If you meant to render a React component, start its name with ' + 'an uppercase letter.', type);
  7589. }
  7590. }
  7591. }
  7592. return domElement;
  7593. }
  7594. function createTextNode(text, rootContainerElement) {
  7595. return getOwnerDocumentFromRootContainer(rootContainerElement).createTextNode(text);
  7596. }
  7597. function setInitialProperties(domElement, tag, rawProps, rootContainerElement) {
  7598. var isCustomComponentTag = isCustomComponent(tag, rawProps);
  7599. {
  7600. validatePropertiesInDevelopment(tag, rawProps);
  7601. } // TODO: Make sure that we check isMounted before firing any of these events.
  7602. var props;
  7603. switch (tag) {
  7604. case 'dialog':
  7605. listenToNonDelegatedEvent('cancel', domElement);
  7606. listenToNonDelegatedEvent('close', domElement);
  7607. props = rawProps;
  7608. break;
  7609. case 'iframe':
  7610. case 'object':
  7611. case 'embed':
  7612. // We listen to this event in case to ensure emulated bubble
  7613. // listeners still fire for the load event.
  7614. listenToNonDelegatedEvent('load', domElement);
  7615. props = rawProps;
  7616. break;
  7617. case 'video':
  7618. case 'audio':
  7619. // We listen to these events in case to ensure emulated bubble
  7620. // listeners still fire for all the media events.
  7621. for (var i = 0; i < mediaEventTypes.length; i++) {
  7622. listenToNonDelegatedEvent(mediaEventTypes[i], domElement);
  7623. }
  7624. props = rawProps;
  7625. break;
  7626. case 'source':
  7627. // We listen to this event in case to ensure emulated bubble
  7628. // listeners still fire for the error event.
  7629. listenToNonDelegatedEvent('error', domElement);
  7630. props = rawProps;
  7631. break;
  7632. case 'img':
  7633. case 'image':
  7634. case 'link':
  7635. // We listen to these events in case to ensure emulated bubble
  7636. // listeners still fire for error and load events.
  7637. listenToNonDelegatedEvent('error', domElement);
  7638. listenToNonDelegatedEvent('load', domElement);
  7639. props = rawProps;
  7640. break;
  7641. case 'details':
  7642. // We listen to this event in case to ensure emulated bubble
  7643. // listeners still fire for the toggle event.
  7644. listenToNonDelegatedEvent('toggle', domElement);
  7645. props = rawProps;
  7646. break;
  7647. case 'input':
  7648. initWrapperState(domElement, rawProps);
  7649. props = getHostProps(domElement, rawProps); // We listen to this event in case to ensure emulated bubble
  7650. // listeners still fire for the invalid event.
  7651. listenToNonDelegatedEvent('invalid', domElement);
  7652. break;
  7653. case 'option':
  7654. validateProps(domElement, rawProps);
  7655. props = getHostProps$1(domElement, rawProps);
  7656. break;
  7657. case 'select':
  7658. initWrapperState$1(domElement, rawProps);
  7659. props = getHostProps$2(domElement, rawProps); // We listen to this event in case to ensure emulated bubble
  7660. // listeners still fire for the invalid event.
  7661. listenToNonDelegatedEvent('invalid', domElement);
  7662. break;
  7663. case 'textarea':
  7664. initWrapperState$2(domElement, rawProps);
  7665. props = getHostProps$3(domElement, rawProps); // We listen to this event in case to ensure emulated bubble
  7666. // listeners still fire for the invalid event.
  7667. listenToNonDelegatedEvent('invalid', domElement);
  7668. break;
  7669. default:
  7670. props = rawProps;
  7671. }
  7672. assertValidProps(tag, props);
  7673. setInitialDOMProperties(tag, domElement, rootContainerElement, props, isCustomComponentTag);
  7674. switch (tag) {
  7675. case 'input':
  7676. // TODO: Make sure we check if this is still unmounted or do any clean
  7677. // up necessary since we never stop tracking anymore.
  7678. track(domElement);
  7679. postMountWrapper(domElement, rawProps, false);
  7680. break;
  7681. case 'textarea':
  7682. // TODO: Make sure we check if this is still unmounted or do any clean
  7683. // up necessary since we never stop tracking anymore.
  7684. track(domElement);
  7685. postMountWrapper$3(domElement);
  7686. break;
  7687. case 'option':
  7688. postMountWrapper$1(domElement, rawProps);
  7689. break;
  7690. case 'select':
  7691. postMountWrapper$2(domElement, rawProps);
  7692. break;
  7693. default:
  7694. if (typeof props.onClick === 'function') {
  7695. // TODO: This cast may not be sound for SVG, MathML or custom elements.
  7696. trapClickOnNonInteractiveElement(domElement);
  7697. }
  7698. break;
  7699. }
  7700. } // Calculate the diff between the two objects.
  7701. function diffProperties(domElement, tag, lastRawProps, nextRawProps, rootContainerElement) {
  7702. {
  7703. validatePropertiesInDevelopment(tag, nextRawProps);
  7704. }
  7705. var updatePayload = null;
  7706. var lastProps;
  7707. var nextProps;
  7708. switch (tag) {
  7709. case 'input':
  7710. lastProps = getHostProps(domElement, lastRawProps);
  7711. nextProps = getHostProps(domElement, nextRawProps);
  7712. updatePayload = [];
  7713. break;
  7714. case 'option':
  7715. lastProps = getHostProps$1(domElement, lastRawProps);
  7716. nextProps = getHostProps$1(domElement, nextRawProps);
  7717. updatePayload = [];
  7718. break;
  7719. case 'select':
  7720. lastProps = getHostProps$2(domElement, lastRawProps);
  7721. nextProps = getHostProps$2(domElement, nextRawProps);
  7722. updatePayload = [];
  7723. break;
  7724. case 'textarea':
  7725. lastProps = getHostProps$3(domElement, lastRawProps);
  7726. nextProps = getHostProps$3(domElement, nextRawProps);
  7727. updatePayload = [];
  7728. break;
  7729. default:
  7730. lastProps = lastRawProps;
  7731. nextProps = nextRawProps;
  7732. if (typeof lastProps.onClick !== 'function' && typeof nextProps.onClick === 'function') {
  7733. // TODO: This cast may not be sound for SVG, MathML or custom elements.
  7734. trapClickOnNonInteractiveElement(domElement);
  7735. }
  7736. break;
  7737. }
  7738. assertValidProps(tag, nextProps);
  7739. var propKey;
  7740. var styleName;
  7741. var styleUpdates = null;
  7742. for (propKey in lastProps) {
  7743. if (nextProps.hasOwnProperty(propKey) || !lastProps.hasOwnProperty(propKey) || lastProps[propKey] == null) {
  7744. continue;
  7745. }
  7746. if (propKey === STYLE) {
  7747. var lastStyle = lastProps[propKey];
  7748. for (styleName in lastStyle) {
  7749. if (lastStyle.hasOwnProperty(styleName)) {
  7750. if (!styleUpdates) {
  7751. styleUpdates = {};
  7752. }
  7753. styleUpdates[styleName] = '';
  7754. }
  7755. }
  7756. } else if (propKey === DANGEROUSLY_SET_INNER_HTML || propKey === CHILDREN) ; else if (propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING) ; else if (propKey === AUTOFOCUS) ; else if (registrationNameDependencies.hasOwnProperty(propKey)) {
  7757. // This is a special case. If any listener updates we need to ensure
  7758. // that the "current" fiber pointer gets updated so we need a commit
  7759. // to update this element.
  7760. if (!updatePayload) {
  7761. updatePayload = [];
  7762. }
  7763. } else {
  7764. // For all other deleted properties we add it to the queue. We use
  7765. // the allowed property list in the commit phase instead.
  7766. (updatePayload = updatePayload || []).push(propKey, null);
  7767. }
  7768. }
  7769. for (propKey in nextProps) {
  7770. var nextProp = nextProps[propKey];
  7771. var lastProp = lastProps != null ? lastProps[propKey] : undefined;
  7772. if (!nextProps.hasOwnProperty(propKey) || nextProp === lastProp || nextProp == null && lastProp == null) {
  7773. continue;
  7774. }
  7775. if (propKey === STYLE) {
  7776. {
  7777. if (nextProp) {
  7778. // Freeze the next style object so that we can assume it won't be
  7779. // mutated. We have already warned for this in the past.
  7780. Object.freeze(nextProp);
  7781. }
  7782. }
  7783. if (lastProp) {
  7784. // Unset styles on `lastProp` but not on `nextProp`.
  7785. for (styleName in lastProp) {
  7786. if (lastProp.hasOwnProperty(styleName) && (!nextProp || !nextProp.hasOwnProperty(styleName))) {
  7787. if (!styleUpdates) {
  7788. styleUpdates = {};
  7789. }
  7790. styleUpdates[styleName] = '';
  7791. }
  7792. } // Update styles that changed since `lastProp`.
  7793. for (styleName in nextProp) {
  7794. if (nextProp.hasOwnProperty(styleName) && lastProp[styleName] !== nextProp[styleName]) {
  7795. if (!styleUpdates) {
  7796. styleUpdates = {};
  7797. }
  7798. styleUpdates[styleName] = nextProp[styleName];
  7799. }
  7800. }
  7801. } else {
  7802. // Relies on `updateStylesByID` not mutating `styleUpdates`.
  7803. if (!styleUpdates) {
  7804. if (!updatePayload) {
  7805. updatePayload = [];
  7806. }
  7807. updatePayload.push(propKey, styleUpdates);
  7808. }
  7809. styleUpdates = nextProp;
  7810. }
  7811. } else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
  7812. var nextHtml = nextProp ? nextProp[HTML$1] : undefined;
  7813. var lastHtml = lastProp ? lastProp[HTML$1] : undefined;
  7814. if (nextHtml != null) {
  7815. if (lastHtml !== nextHtml) {
  7816. (updatePayload = updatePayload || []).push(propKey, nextHtml);
  7817. }
  7818. }
  7819. } else if (propKey === CHILDREN) {
  7820. if (typeof nextProp === 'string' || typeof nextProp === 'number') {
  7821. (updatePayload = updatePayload || []).push(propKey, '' + nextProp);
  7822. }
  7823. } else if (propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING) ; else if (registrationNameDependencies.hasOwnProperty(propKey)) {
  7824. if (nextProp != null) {
  7825. // We eagerly listen to this even though we haven't committed yet.
  7826. if ( typeof nextProp !== 'function') {
  7827. warnForInvalidEventListener(propKey, nextProp);
  7828. }
  7829. if (propKey === 'onScroll') {
  7830. listenToNonDelegatedEvent('scroll', domElement);
  7831. }
  7832. }
  7833. if (!updatePayload && lastProp !== nextProp) {
  7834. // This is a special case. If any listener updates we need to ensure
  7835. // that the "current" props pointer gets updated so we need a commit
  7836. // to update this element.
  7837. updatePayload = [];
  7838. }
  7839. } else if (typeof nextProp === 'object' && nextProp !== null && nextProp.$$typeof === REACT_OPAQUE_ID_TYPE) {
  7840. // If we encounter useOpaqueReference's opaque object, this means we are hydrating.
  7841. // In this case, call the opaque object's toString function which generates a new client
  7842. // ID so client and server IDs match and throws to rerender.
  7843. nextProp.toString();
  7844. } else {
  7845. // For any other property we always add it to the queue and then we
  7846. // filter it out using the allowed property list during the commit.
  7847. (updatePayload = updatePayload || []).push(propKey, nextProp);
  7848. }
  7849. }
  7850. if (styleUpdates) {
  7851. {
  7852. validateShorthandPropertyCollisionInDev(styleUpdates, nextProps[STYLE]);
  7853. }
  7854. (updatePayload = updatePayload || []).push(STYLE, styleUpdates);
  7855. }
  7856. return updatePayload;
  7857. } // Apply the diff.
  7858. function updateProperties(domElement, updatePayload, tag, lastRawProps, nextRawProps) {
  7859. // Update checked *before* name.
  7860. // In the middle of an update, it is possible to have multiple checked.
  7861. // When a checked radio tries to change name, browser makes another radio's checked false.
  7862. if (tag === 'input' && nextRawProps.type === 'radio' && nextRawProps.name != null) {
  7863. updateChecked(domElement, nextRawProps);
  7864. }
  7865. var wasCustomComponentTag = isCustomComponent(tag, lastRawProps);
  7866. var isCustomComponentTag = isCustomComponent(tag, nextRawProps); // Apply the diff.
  7867. updateDOMProperties(domElement, updatePayload, wasCustomComponentTag, isCustomComponentTag); // TODO: Ensure that an update gets scheduled if any of the special props
  7868. // changed.
  7869. switch (tag) {
  7870. case 'input':
  7871. // Update the wrapper around inputs *after* updating props. This has to
  7872. // happen after `updateDOMProperties`. Otherwise HTML5 input validations
  7873. // raise warnings and prevent the new value from being assigned.
  7874. updateWrapper(domElement, nextRawProps);
  7875. break;
  7876. case 'textarea':
  7877. updateWrapper$1(domElement, nextRawProps);
  7878. break;
  7879. case 'select':
  7880. // <select> value update needs to occur after <option> children
  7881. // reconciliation
  7882. postUpdateWrapper(domElement, nextRawProps);
  7883. break;
  7884. }
  7885. }
  7886. function getPossibleStandardName(propName) {
  7887. {
  7888. var lowerCasedName = propName.toLowerCase();
  7889. if (!possibleStandardNames.hasOwnProperty(lowerCasedName)) {
  7890. return null;
  7891. }
  7892. return possibleStandardNames[lowerCasedName] || null;
  7893. }
  7894. }
  7895. function diffHydratedProperties(domElement, tag, rawProps, parentNamespace, rootContainerElement) {
  7896. var isCustomComponentTag;
  7897. var extraAttributeNames;
  7898. {
  7899. suppressHydrationWarning = rawProps[SUPPRESS_HYDRATION_WARNING] === true;
  7900. isCustomComponentTag = isCustomComponent(tag, rawProps);
  7901. validatePropertiesInDevelopment(tag, rawProps);
  7902. } // TODO: Make sure that we check isMounted before firing any of these events.
  7903. switch (tag) {
  7904. case 'dialog':
  7905. listenToNonDelegatedEvent('cancel', domElement);
  7906. listenToNonDelegatedEvent('close', domElement);
  7907. break;
  7908. case 'iframe':
  7909. case 'object':
  7910. case 'embed':
  7911. // We listen to this event in case to ensure emulated bubble
  7912. // listeners still fire for the load event.
  7913. listenToNonDelegatedEvent('load', domElement);
  7914. break;
  7915. case 'video':
  7916. case 'audio':
  7917. // We listen to these events in case to ensure emulated bubble
  7918. // listeners still fire for all the media events.
  7919. for (var i = 0; i < mediaEventTypes.length; i++) {
  7920. listenToNonDelegatedEvent(mediaEventTypes[i], domElement);
  7921. }
  7922. break;
  7923. case 'source':
  7924. // We listen to this event in case to ensure emulated bubble
  7925. // listeners still fire for the error event.
  7926. listenToNonDelegatedEvent('error', domElement);
  7927. break;
  7928. case 'img':
  7929. case 'image':
  7930. case 'link':
  7931. // We listen to these events in case to ensure emulated bubble
  7932. // listeners still fire for error and load events.
  7933. listenToNonDelegatedEvent('error', domElement);
  7934. listenToNonDelegatedEvent('load', domElement);
  7935. break;
  7936. case 'details':
  7937. // We listen to this event in case to ensure emulated bubble
  7938. // listeners still fire for the toggle event.
  7939. listenToNonDelegatedEvent('toggle', domElement);
  7940. break;
  7941. case 'input':
  7942. initWrapperState(domElement, rawProps); // We listen to this event in case to ensure emulated bubble
  7943. // listeners still fire for the invalid event.
  7944. listenToNonDelegatedEvent('invalid', domElement);
  7945. break;
  7946. case 'option':
  7947. validateProps(domElement, rawProps);
  7948. break;
  7949. case 'select':
  7950. initWrapperState$1(domElement, rawProps); // We listen to this event in case to ensure emulated bubble
  7951. // listeners still fire for the invalid event.
  7952. listenToNonDelegatedEvent('invalid', domElement);
  7953. break;
  7954. case 'textarea':
  7955. initWrapperState$2(domElement, rawProps); // We listen to this event in case to ensure emulated bubble
  7956. // listeners still fire for the invalid event.
  7957. listenToNonDelegatedEvent('invalid', domElement);
  7958. break;
  7959. }
  7960. assertValidProps(tag, rawProps);
  7961. {
  7962. extraAttributeNames = new Set();
  7963. var attributes = domElement.attributes;
  7964. for (var _i = 0; _i < attributes.length; _i++) {
  7965. var name = attributes[_i].name.toLowerCase();
  7966. switch (name) {
  7967. // Built-in SSR attribute is allowed
  7968. case 'data-reactroot':
  7969. break;
  7970. // Controlled attributes are not validated
  7971. // TODO: Only ignore them on controlled tags.
  7972. case 'value':
  7973. break;
  7974. case 'checked':
  7975. break;
  7976. case 'selected':
  7977. break;
  7978. default:
  7979. // Intentionally use the original name.
  7980. // See discussion in https://github.com/facebook/react/pull/10676.
  7981. extraAttributeNames.add(attributes[_i].name);
  7982. }
  7983. }
  7984. }
  7985. var updatePayload = null;
  7986. for (var propKey in rawProps) {
  7987. if (!rawProps.hasOwnProperty(propKey)) {
  7988. continue;
  7989. }
  7990. var nextProp = rawProps[propKey];
  7991. if (propKey === CHILDREN) {
  7992. // For text content children we compare against textContent. This
  7993. // might match additional HTML that is hidden when we read it using
  7994. // textContent. E.g. "foo" will match "f<span>oo</span>" but that still
  7995. // satisfies our requirement. Our requirement is not to produce perfect
  7996. // HTML and attributes. Ideally we should preserve structure but it's
  7997. // ok not to if the visible content is still enough to indicate what
  7998. // even listeners these nodes might be wired up to.
  7999. // TODO: Warn if there is more than a single textNode as a child.
  8000. // TODO: Should we use domElement.firstChild.nodeValue to compare?
  8001. if (typeof nextProp === 'string') {
  8002. if (domElement.textContent !== nextProp) {
  8003. if ( !suppressHydrationWarning) {
  8004. warnForTextDifference(domElement.textContent, nextProp);
  8005. }
  8006. updatePayload = [CHILDREN, nextProp];
  8007. }
  8008. } else if (typeof nextProp === 'number') {
  8009. if (domElement.textContent !== '' + nextProp) {
  8010. if ( !suppressHydrationWarning) {
  8011. warnForTextDifference(domElement.textContent, nextProp);
  8012. }
  8013. updatePayload = [CHILDREN, '' + nextProp];
  8014. }
  8015. }
  8016. } else if (registrationNameDependencies.hasOwnProperty(propKey)) {
  8017. if (nextProp != null) {
  8018. if ( typeof nextProp !== 'function') {
  8019. warnForInvalidEventListener(propKey, nextProp);
  8020. }
  8021. if (propKey === 'onScroll') {
  8022. listenToNonDelegatedEvent('scroll', domElement);
  8023. }
  8024. }
  8025. } else if ( // Convince Flow we've calculated it (it's DEV-only in this method.)
  8026. typeof isCustomComponentTag === 'boolean') {
  8027. // Validate that the properties correspond to their expected values.
  8028. var serverValue = void 0;
  8029. var propertyInfo = getPropertyInfo(propKey);
  8030. if (suppressHydrationWarning) ; else if (propKey === SUPPRESS_CONTENT_EDITABLE_WARNING || propKey === SUPPRESS_HYDRATION_WARNING || // Controlled attributes are not validated
  8031. // TODO: Only ignore them on controlled tags.
  8032. propKey === 'value' || propKey === 'checked' || propKey === 'selected') ; else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
  8033. var serverHTML = domElement.innerHTML;
  8034. var nextHtml = nextProp ? nextProp[HTML$1] : undefined;
  8035. if (nextHtml != null) {
  8036. var expectedHTML = normalizeHTML(domElement, nextHtml);
  8037. if (expectedHTML !== serverHTML) {
  8038. warnForPropDifference(propKey, serverHTML, expectedHTML);
  8039. }
  8040. }
  8041. } else if (propKey === STYLE) {
  8042. // $FlowFixMe - Should be inferred as not undefined.
  8043. extraAttributeNames.delete(propKey);
  8044. if (canDiffStyleForHydrationWarning) {
  8045. var expectedStyle = createDangerousStringForStyles(nextProp);
  8046. serverValue = domElement.getAttribute('style');
  8047. if (expectedStyle !== serverValue) {
  8048. warnForPropDifference(propKey, serverValue, expectedStyle);
  8049. }
  8050. }
  8051. } else if (isCustomComponentTag) {
  8052. // $FlowFixMe - Should be inferred as not undefined.
  8053. extraAttributeNames.delete(propKey.toLowerCase());
  8054. serverValue = getValueForAttribute(domElement, propKey, nextProp);
  8055. if (nextProp !== serverValue) {
  8056. warnForPropDifference(propKey, serverValue, nextProp);
  8057. }
  8058. } else if (!shouldIgnoreAttribute(propKey, propertyInfo, isCustomComponentTag) && !shouldRemoveAttribute(propKey, nextProp, propertyInfo, isCustomComponentTag)) {
  8059. var isMismatchDueToBadCasing = false;
  8060. if (propertyInfo !== null) {
  8061. // $FlowFixMe - Should be inferred as not undefined.
  8062. extraAttributeNames.delete(propertyInfo.attributeName);
  8063. serverValue = getValueForProperty(domElement, propKey, nextProp, propertyInfo);
  8064. } else {
  8065. var ownNamespace = parentNamespace;
  8066. if (ownNamespace === HTML_NAMESPACE$1) {
  8067. ownNamespace = getIntrinsicNamespace(tag);
  8068. }
  8069. if (ownNamespace === HTML_NAMESPACE$1) {
  8070. // $FlowFixMe - Should be inferred as not undefined.
  8071. extraAttributeNames.delete(propKey.toLowerCase());
  8072. } else {
  8073. var standardName = getPossibleStandardName(propKey);
  8074. if (standardName !== null && standardName !== propKey) {
  8075. // If an SVG prop is supplied with bad casing, it will
  8076. // be successfully parsed from HTML, but will produce a mismatch
  8077. // (and would be incorrectly rendered on the client).
  8078. // However, we already warn about bad casing elsewhere.
  8079. // So we'll skip the misleading extra mismatch warning in this case.
  8080. isMismatchDueToBadCasing = true; // $FlowFixMe - Should be inferred as not undefined.
  8081. extraAttributeNames.delete(standardName);
  8082. } // $FlowFixMe - Should be inferred as not undefined.
  8083. extraAttributeNames.delete(propKey);
  8084. }
  8085. serverValue = getValueForAttribute(domElement, propKey, nextProp);
  8086. }
  8087. if (nextProp !== serverValue && !isMismatchDueToBadCasing) {
  8088. warnForPropDifference(propKey, serverValue, nextProp);
  8089. }
  8090. }
  8091. }
  8092. }
  8093. {
  8094. // $FlowFixMe - Should be inferred as not undefined.
  8095. if (extraAttributeNames.size > 0 && !suppressHydrationWarning) {
  8096. // $FlowFixMe - Should be inferred as not undefined.
  8097. warnForExtraAttributes(extraAttributeNames);
  8098. }
  8099. }
  8100. switch (tag) {
  8101. case 'input':
  8102. // TODO: Make sure we check if this is still unmounted or do any clean
  8103. // up necessary since we never stop tracking anymore.
  8104. track(domElement);
  8105. postMountWrapper(domElement, rawProps, true);
  8106. break;
  8107. case 'textarea':
  8108. // TODO: Make sure we check if this is still unmounted or do any clean
  8109. // up necessary since we never stop tracking anymore.
  8110. track(domElement);
  8111. postMountWrapper$3(domElement);
  8112. break;
  8113. case 'select':
  8114. case 'option':
  8115. // For input and textarea we current always set the value property at
  8116. // post mount to force it to diverge from attributes. However, for
  8117. // option and select we don't quite do the same thing and select
  8118. // is not resilient to the DOM state changing so we don't do that here.
  8119. // TODO: Consider not doing this for input and textarea.
  8120. break;
  8121. default:
  8122. if (typeof rawProps.onClick === 'function') {
  8123. // TODO: This cast may not be sound for SVG, MathML or custom elements.
  8124. trapClickOnNonInteractiveElement(domElement);
  8125. }
  8126. break;
  8127. }
  8128. return updatePayload;
  8129. }
  8130. function diffHydratedText(textNode, text) {
  8131. var isDifferent = textNode.nodeValue !== text;
  8132. return isDifferent;
  8133. }
  8134. function warnForUnmatchedText(textNode, text) {
  8135. {
  8136. warnForTextDifference(textNode.nodeValue, text);
  8137. }
  8138. }
  8139. function warnForDeletedHydratableElement(parentNode, child) {
  8140. {
  8141. if (didWarnInvalidHydration) {
  8142. return;
  8143. }
  8144. didWarnInvalidHydration = true;
  8145. error('Did not expect server HTML to contain a <%s> in <%s>.', child.nodeName.toLowerCase(), parentNode.nodeName.toLowerCase());
  8146. }
  8147. }
  8148. function warnForDeletedHydratableText(parentNode, child) {
  8149. {
  8150. if (didWarnInvalidHydration) {
  8151. return;
  8152. }
  8153. didWarnInvalidHydration = true;
  8154. error('Did not expect server HTML to contain the text node "%s" in <%s>.', child.nodeValue, parentNode.nodeName.toLowerCase());
  8155. }
  8156. }
  8157. function warnForInsertedHydratedElement(parentNode, tag, props) {
  8158. {
  8159. if (didWarnInvalidHydration) {
  8160. return;
  8161. }
  8162. didWarnInvalidHydration = true;
  8163. error('Expected server HTML to contain a matching <%s> in <%s>.', tag, parentNode.nodeName.toLowerCase());
  8164. }
  8165. }
  8166. function warnForInsertedHydratedText(parentNode, text) {
  8167. {
  8168. if (text === '') {
  8169. // We expect to insert empty text nodes since they're not represented in
  8170. // the HTML.
  8171. // TODO: Remove this special case if we can just avoid inserting empty
  8172. // text nodes.
  8173. return;
  8174. }
  8175. if (didWarnInvalidHydration) {
  8176. return;
  8177. }
  8178. didWarnInvalidHydration = true;
  8179. error('Expected server HTML to contain a matching text node for "%s" in <%s>.', text, parentNode.nodeName.toLowerCase());
  8180. }
  8181. }
  8182. function restoreControlledState$3(domElement, tag, props) {
  8183. switch (tag) {
  8184. case 'input':
  8185. restoreControlledState(domElement, props);
  8186. return;
  8187. case 'textarea':
  8188. restoreControlledState$2(domElement, props);
  8189. return;
  8190. case 'select':
  8191. restoreControlledState$1(domElement, props);
  8192. return;
  8193. }
  8194. }
  8195. var validateDOMNesting = function () {};
  8196. var updatedAncestorInfo = function () {};
  8197. {
  8198. // This validation code was written based on the HTML5 parsing spec:
  8199. // https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-scope
  8200. //
  8201. // Note: this does not catch all invalid nesting, nor does it try to (as it's
  8202. // not clear what practical benefit doing so provides); instead, we warn only
  8203. // for cases where the parser will give a parse tree differing from what React
  8204. // intended. For example, <b><div></div></b> is invalid but we don't warn
  8205. // because it still parses correctly; we do warn for other cases like nested
  8206. // <p> tags where the beginning of the second element implicitly closes the
  8207. // first, causing a confusing mess.
  8208. // https://html.spec.whatwg.org/multipage/syntax.html#special
  8209. var specialTags = ['address', 'applet', 'area', 'article', 'aside', 'base', 'basefont', 'bgsound', 'blockquote', 'body', 'br', 'button', 'caption', 'center', 'col', 'colgroup', 'dd', 'details', 'dir', 'div', 'dl', 'dt', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'iframe', 'img', 'input', 'isindex', 'li', 'link', 'listing', 'main', 'marquee', 'menu', 'menuitem', 'meta', 'nav', 'noembed', 'noframes', 'noscript', 'object', 'ol', 'p', 'param', 'plaintext', 'pre', 'script', 'section', 'select', 'source', 'style', 'summary', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'track', 'ul', 'wbr', 'xmp']; // https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-scope
  8210. var inScopeTags = ['applet', 'caption', 'html', 'table', 'td', 'th', 'marquee', 'object', 'template', // https://html.spec.whatwg.org/multipage/syntax.html#html-integration-point
  8211. // TODO: Distinguish by namespace here -- for <title>, including it here
  8212. // errs on the side of fewer warnings
  8213. 'foreignObject', 'desc', 'title']; // https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-button-scope
  8214. var buttonScopeTags = inScopeTags.concat(['button']); // https://html.spec.whatwg.org/multipage/syntax.html#generate-implied-end-tags
  8215. var impliedEndTags = ['dd', 'dt', 'li', 'option', 'optgroup', 'p', 'rp', 'rt'];
  8216. var emptyAncestorInfo = {
  8217. current: null,
  8218. formTag: null,
  8219. aTagInScope: null,
  8220. buttonTagInScope: null,
  8221. nobrTagInScope: null,
  8222. pTagInButtonScope: null,
  8223. listItemTagAutoclosing: null,
  8224. dlItemTagAutoclosing: null
  8225. };
  8226. updatedAncestorInfo = function (oldInfo, tag) {
  8227. var ancestorInfo = _assign({}, oldInfo || emptyAncestorInfo);
  8228. var info = {
  8229. tag: tag
  8230. };
  8231. if (inScopeTags.indexOf(tag) !== -1) {
  8232. ancestorInfo.aTagInScope = null;
  8233. ancestorInfo.buttonTagInScope = null;
  8234. ancestorInfo.nobrTagInScope = null;
  8235. }
  8236. if (buttonScopeTags.indexOf(tag) !== -1) {
  8237. ancestorInfo.pTagInButtonScope = null;
  8238. } // See rules for 'li', 'dd', 'dt' start tags in
  8239. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody
  8240. if (specialTags.indexOf(tag) !== -1 && tag !== 'address' && tag !== 'div' && tag !== 'p') {
  8241. ancestorInfo.listItemTagAutoclosing = null;
  8242. ancestorInfo.dlItemTagAutoclosing = null;
  8243. }
  8244. ancestorInfo.current = info;
  8245. if (tag === 'form') {
  8246. ancestorInfo.formTag = info;
  8247. }
  8248. if (tag === 'a') {
  8249. ancestorInfo.aTagInScope = info;
  8250. }
  8251. if (tag === 'button') {
  8252. ancestorInfo.buttonTagInScope = info;
  8253. }
  8254. if (tag === 'nobr') {
  8255. ancestorInfo.nobrTagInScope = info;
  8256. }
  8257. if (tag === 'p') {
  8258. ancestorInfo.pTagInButtonScope = info;
  8259. }
  8260. if (tag === 'li') {
  8261. ancestorInfo.listItemTagAutoclosing = info;
  8262. }
  8263. if (tag === 'dd' || tag === 'dt') {
  8264. ancestorInfo.dlItemTagAutoclosing = info;
  8265. }
  8266. return ancestorInfo;
  8267. };
  8268. /**
  8269. * Returns whether
  8270. */
  8271. var isTagValidWithParent = function (tag, parentTag) {
  8272. // First, let's check if we're in an unusual parsing mode...
  8273. switch (parentTag) {
  8274. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inselect
  8275. case 'select':
  8276. return tag === 'option' || tag === 'optgroup' || tag === '#text';
  8277. case 'optgroup':
  8278. return tag === 'option' || tag === '#text';
  8279. // Strictly speaking, seeing an <option> doesn't mean we're in a <select>
  8280. // but
  8281. case 'option':
  8282. return tag === '#text';
  8283. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intd
  8284. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incaption
  8285. // No special behavior since these rules fall back to "in body" mode for
  8286. // all except special table nodes which cause bad parsing behavior anyway.
  8287. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intr
  8288. case 'tr':
  8289. return tag === 'th' || tag === 'td' || tag === 'style' || tag === 'script' || tag === 'template';
  8290. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intbody
  8291. case 'tbody':
  8292. case 'thead':
  8293. case 'tfoot':
  8294. return tag === 'tr' || tag === 'style' || tag === 'script' || tag === 'template';
  8295. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incolgroup
  8296. case 'colgroup':
  8297. return tag === 'col' || tag === 'template';
  8298. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intable
  8299. case 'table':
  8300. return tag === 'caption' || tag === 'colgroup' || tag === 'tbody' || tag === 'tfoot' || tag === 'thead' || tag === 'style' || tag === 'script' || tag === 'template';
  8301. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inhead
  8302. case 'head':
  8303. return tag === 'base' || tag === 'basefont' || tag === 'bgsound' || tag === 'link' || tag === 'meta' || tag === 'title' || tag === 'noscript' || tag === 'noframes' || tag === 'style' || tag === 'script' || tag === 'template';
  8304. // https://html.spec.whatwg.org/multipage/semantics.html#the-html-element
  8305. case 'html':
  8306. return tag === 'head' || tag === 'body' || tag === 'frameset';
  8307. case 'frameset':
  8308. return tag === 'frame';
  8309. case '#document':
  8310. return tag === 'html';
  8311. } // Probably in the "in body" parsing mode, so we outlaw only tag combos
  8312. // where the parsing rules cause implicit opens or closes to be added.
  8313. // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody
  8314. switch (tag) {
  8315. case 'h1':
  8316. case 'h2':
  8317. case 'h3':
  8318. case 'h4':
  8319. case 'h5':
  8320. case 'h6':
  8321. return parentTag !== 'h1' && parentTag !== 'h2' && parentTag !== 'h3' && parentTag !== 'h4' && parentTag !== 'h5' && parentTag !== 'h6';
  8322. case 'rp':
  8323. case 'rt':
  8324. return impliedEndTags.indexOf(parentTag) === -1;
  8325. case 'body':
  8326. case 'caption':
  8327. case 'col':
  8328. case 'colgroup':
  8329. case 'frameset':
  8330. case 'frame':
  8331. case 'head':
  8332. case 'html':
  8333. case 'tbody':
  8334. case 'td':
  8335. case 'tfoot':
  8336. case 'th':
  8337. case 'thead':
  8338. case 'tr':
  8339. // These tags are only valid with a few parents that have special child
  8340. // parsing rules -- if we're down here, then none of those matched and
  8341. // so we allow it only if we don't know what the parent is, as all other
  8342. // cases are invalid.
  8343. return parentTag == null;
  8344. }
  8345. return true;
  8346. };
  8347. /**
  8348. * Returns whether
  8349. */
  8350. var findInvalidAncestorForTag = function (tag, ancestorInfo) {
  8351. switch (tag) {
  8352. case 'address':
  8353. case 'article':
  8354. case 'aside':
  8355. case 'blockquote':
  8356. case 'center':
  8357. case 'details':
  8358. case 'dialog':
  8359. case 'dir':
  8360. case 'div':
  8361. case 'dl':
  8362. case 'fieldset':
  8363. case 'figcaption':
  8364. case 'figure':
  8365. case 'footer':
  8366. case 'header':
  8367. case 'hgroup':
  8368. case 'main':
  8369. case 'menu':
  8370. case 'nav':
  8371. case 'ol':
  8372. case 'p':
  8373. case 'section':
  8374. case 'summary':
  8375. case 'ul':
  8376. case 'pre':
  8377. case 'listing':
  8378. case 'table':
  8379. case 'hr':
  8380. case 'xmp':
  8381. case 'h1':
  8382. case 'h2':
  8383. case 'h3':
  8384. case 'h4':
  8385. case 'h5':
  8386. case 'h6':
  8387. return ancestorInfo.pTagInButtonScope;
  8388. case 'form':
  8389. return ancestorInfo.formTag || ancestorInfo.pTagInButtonScope;
  8390. case 'li':
  8391. return ancestorInfo.listItemTagAutoclosing;
  8392. case 'dd':
  8393. case 'dt':
  8394. return ancestorInfo.dlItemTagAutoclosing;
  8395. case 'button':
  8396. return ancestorInfo.buttonTagInScope;
  8397. case 'a':
  8398. // Spec says something about storing a list of markers, but it sounds
  8399. // equivalent to this check.
  8400. return ancestorInfo.aTagInScope;
  8401. case 'nobr':
  8402. return ancestorInfo.nobrTagInScope;
  8403. }
  8404. return null;
  8405. };
  8406. var didWarn$1 = {};
  8407. validateDOMNesting = function (childTag, childText, ancestorInfo) {
  8408. ancestorInfo = ancestorInfo || emptyAncestorInfo;
  8409. var parentInfo = ancestorInfo.current;
  8410. var parentTag = parentInfo && parentInfo.tag;
  8411. if (childText != null) {
  8412. if (childTag != null) {
  8413. error('validateDOMNesting: when childText is passed, childTag should be null');
  8414. }
  8415. childTag = '#text';
  8416. }
  8417. var invalidParent = isTagValidWithParent(childTag, parentTag) ? null : parentInfo;
  8418. var invalidAncestor = invalidParent ? null : findInvalidAncestorForTag(childTag, ancestorInfo);
  8419. var invalidParentOrAncestor = invalidParent || invalidAncestor;
  8420. if (!invalidParentOrAncestor) {
  8421. return;
  8422. }
  8423. var ancestorTag = invalidParentOrAncestor.tag;
  8424. var warnKey = !!invalidParent + '|' + childTag + '|' + ancestorTag;
  8425. if (didWarn$1[warnKey]) {
  8426. return;
  8427. }
  8428. didWarn$1[warnKey] = true;
  8429. var tagDisplayName = childTag;
  8430. var whitespaceInfo = '';
  8431. if (childTag === '#text') {
  8432. if (/\S/.test(childText)) {
  8433. tagDisplayName = 'Text nodes';
  8434. } else {
  8435. tagDisplayName = 'Whitespace text nodes';
  8436. whitespaceInfo = " Make sure you don't have any extra whitespace between tags on " + 'each line of your source code.';
  8437. }
  8438. } else {
  8439. tagDisplayName = '<' + childTag + '>';
  8440. }
  8441. if (invalidParent) {
  8442. var info = '';
  8443. if (ancestorTag === 'table' && childTag === 'tr') {
  8444. info += ' Add a <tbody>, <thead> or <tfoot> to your code to match the DOM tree generated by ' + 'the browser.';
  8445. }
  8446. error('validateDOMNesting(...): %s cannot appear as a child of <%s>.%s%s', tagDisplayName, ancestorTag, whitespaceInfo, info);
  8447. } else {
  8448. error('validateDOMNesting(...): %s cannot appear as a descendant of ' + '<%s>.', tagDisplayName, ancestorTag);
  8449. }
  8450. };
  8451. }
  8452. var SUPPRESS_HYDRATION_WARNING$1;
  8453. {
  8454. SUPPRESS_HYDRATION_WARNING$1 = 'suppressHydrationWarning';
  8455. }
  8456. var SUSPENSE_START_DATA = '$';
  8457. var SUSPENSE_END_DATA = '/$';
  8458. var SUSPENSE_PENDING_START_DATA = '$?';
  8459. var SUSPENSE_FALLBACK_START_DATA = '$!';
  8460. var STYLE$1 = 'style';
  8461. var eventsEnabled = null;
  8462. var selectionInformation = null;
  8463. function shouldAutoFocusHostComponent(type, props) {
  8464. switch (type) {
  8465. case 'button':
  8466. case 'input':
  8467. case 'select':
  8468. case 'textarea':
  8469. return !!props.autoFocus;
  8470. }
  8471. return false;
  8472. }
  8473. function getRootHostContext(rootContainerInstance) {
  8474. var type;
  8475. var namespace;
  8476. var nodeType = rootContainerInstance.nodeType;
  8477. switch (nodeType) {
  8478. case DOCUMENT_NODE:
  8479. case DOCUMENT_FRAGMENT_NODE:
  8480. {
  8481. type = nodeType === DOCUMENT_NODE ? '#document' : '#fragment';
  8482. var root = rootContainerInstance.documentElement;
  8483. namespace = root ? root.namespaceURI : getChildNamespace(null, '');
  8484. break;
  8485. }
  8486. default:
  8487. {
  8488. var container = nodeType === COMMENT_NODE ? rootContainerInstance.parentNode : rootContainerInstance;
  8489. var ownNamespace = container.namespaceURI || null;
  8490. type = container.tagName;
  8491. namespace = getChildNamespace(ownNamespace, type);
  8492. break;
  8493. }
  8494. }
  8495. {
  8496. var validatedTag = type.toLowerCase();
  8497. var ancestorInfo = updatedAncestorInfo(null, validatedTag);
  8498. return {
  8499. namespace: namespace,
  8500. ancestorInfo: ancestorInfo
  8501. };
  8502. }
  8503. }
  8504. function getChildHostContext(parentHostContext, type, rootContainerInstance) {
  8505. {
  8506. var parentHostContextDev = parentHostContext;
  8507. var namespace = getChildNamespace(parentHostContextDev.namespace, type);
  8508. var ancestorInfo = updatedAncestorInfo(parentHostContextDev.ancestorInfo, type);
  8509. return {
  8510. namespace: namespace,
  8511. ancestorInfo: ancestorInfo
  8512. };
  8513. }
  8514. }
  8515. function getPublicInstance(instance) {
  8516. return instance;
  8517. }
  8518. function prepareForCommit(containerInfo) {
  8519. eventsEnabled = isEnabled();
  8520. selectionInformation = getSelectionInformation();
  8521. var activeInstance = null;
  8522. setEnabled(false);
  8523. return activeInstance;
  8524. }
  8525. function resetAfterCommit(containerInfo) {
  8526. restoreSelection(selectionInformation);
  8527. setEnabled(eventsEnabled);
  8528. eventsEnabled = null;
  8529. selectionInformation = null;
  8530. }
  8531. function createInstance(type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
  8532. var parentNamespace;
  8533. {
  8534. // TODO: take namespace into account when validating.
  8535. var hostContextDev = hostContext;
  8536. validateDOMNesting(type, null, hostContextDev.ancestorInfo);
  8537. if (typeof props.children === 'string' || typeof props.children === 'number') {
  8538. var string = '' + props.children;
  8539. var ownAncestorInfo = updatedAncestorInfo(hostContextDev.ancestorInfo, type);
  8540. validateDOMNesting(null, string, ownAncestorInfo);
  8541. }
  8542. parentNamespace = hostContextDev.namespace;
  8543. }
  8544. var domElement = createElement(type, props, rootContainerInstance, parentNamespace);
  8545. precacheFiberNode(internalInstanceHandle, domElement);
  8546. updateFiberProps(domElement, props);
  8547. return domElement;
  8548. }
  8549. function appendInitialChild(parentInstance, child) {
  8550. parentInstance.appendChild(child);
  8551. }
  8552. function finalizeInitialChildren(domElement, type, props, rootContainerInstance, hostContext) {
  8553. setInitialProperties(domElement, type, props, rootContainerInstance);
  8554. return shouldAutoFocusHostComponent(type, props);
  8555. }
  8556. function prepareUpdate(domElement, type, oldProps, newProps, rootContainerInstance, hostContext) {
  8557. {
  8558. var hostContextDev = hostContext;
  8559. if (typeof newProps.children !== typeof oldProps.children && (typeof newProps.children === 'string' || typeof newProps.children === 'number')) {
  8560. var string = '' + newProps.children;
  8561. var ownAncestorInfo = updatedAncestorInfo(hostContextDev.ancestorInfo, type);
  8562. validateDOMNesting(null, string, ownAncestorInfo);
  8563. }
  8564. }
  8565. return diffProperties(domElement, type, oldProps, newProps);
  8566. }
  8567. function shouldSetTextContent(type, props) {
  8568. return type === 'textarea' || type === 'option' || type === 'noscript' || typeof props.children === 'string' || typeof props.children === 'number' || typeof props.dangerouslySetInnerHTML === 'object' && props.dangerouslySetInnerHTML !== null && props.dangerouslySetInnerHTML.__html != null;
  8569. }
  8570. function createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {
  8571. {
  8572. var hostContextDev = hostContext;
  8573. validateDOMNesting(null, text, hostContextDev.ancestorInfo);
  8574. }
  8575. var textNode = createTextNode(text, rootContainerInstance);
  8576. precacheFiberNode(internalInstanceHandle, textNode);
  8577. return textNode;
  8578. }
  8579. // if a component just imports ReactDOM (e.g. for findDOMNode).
  8580. // Some environments might not have setTimeout or clearTimeout.
  8581. var scheduleTimeout = typeof setTimeout === 'function' ? setTimeout : undefined;
  8582. var cancelTimeout = typeof clearTimeout === 'function' ? clearTimeout : undefined;
  8583. var noTimeout = -1; // -------------------
  8584. function commitMount(domElement, type, newProps, internalInstanceHandle) {
  8585. // Despite the naming that might imply otherwise, this method only
  8586. // fires if there is an `Update` effect scheduled during mounting.
  8587. // This happens if `finalizeInitialChildren` returns `true` (which it
  8588. // does to implement the `autoFocus` attribute on the client). But
  8589. // there are also other cases when this might happen (such as patching
  8590. // up text content during hydration mismatch). So we'll check this again.
  8591. if (shouldAutoFocusHostComponent(type, newProps)) {
  8592. domElement.focus();
  8593. }
  8594. }
  8595. function commitUpdate(domElement, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
  8596. // Update the props handle so that we know which props are the ones with
  8597. // with current event handlers.
  8598. updateFiberProps(domElement, newProps); // Apply the diff to the DOM node.
  8599. updateProperties(domElement, updatePayload, type, oldProps, newProps);
  8600. }
  8601. function resetTextContent(domElement) {
  8602. setTextContent(domElement, '');
  8603. }
  8604. function commitTextUpdate(textInstance, oldText, newText) {
  8605. textInstance.nodeValue = newText;
  8606. }
  8607. function appendChild(parentInstance, child) {
  8608. parentInstance.appendChild(child);
  8609. }
  8610. function appendChildToContainer(container, child) {
  8611. var parentNode;
  8612. if (container.nodeType === COMMENT_NODE) {
  8613. parentNode = container.parentNode;
  8614. parentNode.insertBefore(child, container);
  8615. } else {
  8616. parentNode = container;
  8617. parentNode.appendChild(child);
  8618. } // This container might be used for a portal.
  8619. // If something inside a portal is clicked, that click should bubble
  8620. // through the React tree. However, on Mobile Safari the click would
  8621. // never bubble through the *DOM* tree unless an ancestor with onclick
  8622. // event exists. So we wouldn't see it and dispatch it.
  8623. // This is why we ensure that non React root containers have inline onclick
  8624. // defined.
  8625. // https://github.com/facebook/react/issues/11918
  8626. var reactRootContainer = container._reactRootContainer;
  8627. if ((reactRootContainer === null || reactRootContainer === undefined) && parentNode.onclick === null) {
  8628. // TODO: This cast may not be sound for SVG, MathML or custom elements.
  8629. trapClickOnNonInteractiveElement(parentNode);
  8630. }
  8631. }
  8632. function insertBefore(parentInstance, child, beforeChild) {
  8633. parentInstance.insertBefore(child, beforeChild);
  8634. }
  8635. function insertInContainerBefore(container, child, beforeChild) {
  8636. if (container.nodeType === COMMENT_NODE) {
  8637. container.parentNode.insertBefore(child, beforeChild);
  8638. } else {
  8639. container.insertBefore(child, beforeChild);
  8640. }
  8641. }
  8642. function removeChild(parentInstance, child) {
  8643. parentInstance.removeChild(child);
  8644. }
  8645. function removeChildFromContainer(container, child) {
  8646. if (container.nodeType === COMMENT_NODE) {
  8647. container.parentNode.removeChild(child);
  8648. } else {
  8649. container.removeChild(child);
  8650. }
  8651. }
  8652. function hideInstance(instance) {
  8653. // TODO: Does this work for all element types? What about MathML? Should we
  8654. // pass host context to this method?
  8655. instance = instance;
  8656. var style = instance.style;
  8657. if (typeof style.setProperty === 'function') {
  8658. style.setProperty('display', 'none', 'important');
  8659. } else {
  8660. style.display = 'none';
  8661. }
  8662. }
  8663. function hideTextInstance(textInstance) {
  8664. textInstance.nodeValue = '';
  8665. }
  8666. function unhideInstance(instance, props) {
  8667. instance = instance;
  8668. var styleProp = props[STYLE$1];
  8669. var display = styleProp !== undefined && styleProp !== null && styleProp.hasOwnProperty('display') ? styleProp.display : null;
  8670. instance.style.display = dangerousStyleValue('display', display);
  8671. }
  8672. function unhideTextInstance(textInstance, text) {
  8673. textInstance.nodeValue = text;
  8674. }
  8675. function clearContainer(container) {
  8676. if (container.nodeType === ELEMENT_NODE) {
  8677. container.textContent = '';
  8678. } else if (container.nodeType === DOCUMENT_NODE) {
  8679. var body = container.body;
  8680. if (body != null) {
  8681. body.textContent = '';
  8682. }
  8683. }
  8684. } // -------------------
  8685. function canHydrateInstance(instance, type, props) {
  8686. if (instance.nodeType !== ELEMENT_NODE || type.toLowerCase() !== instance.nodeName.toLowerCase()) {
  8687. return null;
  8688. } // This has now been refined to an element node.
  8689. return instance;
  8690. }
  8691. function canHydrateTextInstance(instance, text) {
  8692. if (text === '' || instance.nodeType !== TEXT_NODE) {
  8693. // Empty strings are not parsed by HTML so there won't be a correct match here.
  8694. return null;
  8695. } // This has now been refined to a text node.
  8696. return instance;
  8697. }
  8698. function isSuspenseInstancePending(instance) {
  8699. return instance.data === SUSPENSE_PENDING_START_DATA;
  8700. }
  8701. function isSuspenseInstanceFallback(instance) {
  8702. return instance.data === SUSPENSE_FALLBACK_START_DATA;
  8703. }
  8704. function getNextHydratable(node) {
  8705. // Skip non-hydratable nodes.
  8706. for (; node != null; node = node.nextSibling) {
  8707. var nodeType = node.nodeType;
  8708. if (nodeType === ELEMENT_NODE || nodeType === TEXT_NODE) {
  8709. break;
  8710. }
  8711. }
  8712. return node;
  8713. }
  8714. function getNextHydratableSibling(instance) {
  8715. return getNextHydratable(instance.nextSibling);
  8716. }
  8717. function getFirstHydratableChild(parentInstance) {
  8718. return getNextHydratable(parentInstance.firstChild);
  8719. }
  8720. function hydrateInstance(instance, type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
  8721. precacheFiberNode(internalInstanceHandle, instance); // TODO: Possibly defer this until the commit phase where all the events
  8722. // get attached.
  8723. updateFiberProps(instance, props);
  8724. var parentNamespace;
  8725. {
  8726. var hostContextDev = hostContext;
  8727. parentNamespace = hostContextDev.namespace;
  8728. }
  8729. return diffHydratedProperties(instance, type, props, parentNamespace);
  8730. }
  8731. function hydrateTextInstance(textInstance, text, internalInstanceHandle) {
  8732. precacheFiberNode(internalInstanceHandle, textInstance);
  8733. return diffHydratedText(textInstance, text);
  8734. }
  8735. function getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance) {
  8736. var node = suspenseInstance.nextSibling; // Skip past all nodes within this suspense boundary.
  8737. // There might be nested nodes so we need to keep track of how
  8738. // deep we are and only break out when we're back on top.
  8739. var depth = 0;
  8740. while (node) {
  8741. if (node.nodeType === COMMENT_NODE) {
  8742. var data = node.data;
  8743. if (data === SUSPENSE_END_DATA) {
  8744. if (depth === 0) {
  8745. return getNextHydratableSibling(node);
  8746. } else {
  8747. depth--;
  8748. }
  8749. } else if (data === SUSPENSE_START_DATA || data === SUSPENSE_FALLBACK_START_DATA || data === SUSPENSE_PENDING_START_DATA) {
  8750. depth++;
  8751. }
  8752. }
  8753. node = node.nextSibling;
  8754. } // TODO: Warn, we didn't find the end comment boundary.
  8755. return null;
  8756. } // Returns the SuspenseInstance if this node is a direct child of a
  8757. // SuspenseInstance. I.e. if its previous sibling is a Comment with
  8758. // SUSPENSE_x_START_DATA. Otherwise, null.
  8759. function getParentSuspenseInstance(targetInstance) {
  8760. var node = targetInstance.previousSibling; // Skip past all nodes within this suspense boundary.
  8761. // There might be nested nodes so we need to keep track of how
  8762. // deep we are and only break out when we're back on top.
  8763. var depth = 0;
  8764. while (node) {
  8765. if (node.nodeType === COMMENT_NODE) {
  8766. var data = node.data;
  8767. if (data === SUSPENSE_START_DATA || data === SUSPENSE_FALLBACK_START_DATA || data === SUSPENSE_PENDING_START_DATA) {
  8768. if (depth === 0) {
  8769. return node;
  8770. } else {
  8771. depth--;
  8772. }
  8773. } else if (data === SUSPENSE_END_DATA) {
  8774. depth++;
  8775. }
  8776. }
  8777. node = node.previousSibling;
  8778. }
  8779. return null;
  8780. }
  8781. function commitHydratedContainer(container) {
  8782. // Retry if any event replaying was blocked on this.
  8783. retryIfBlockedOn(container);
  8784. }
  8785. function commitHydratedSuspenseInstance(suspenseInstance) {
  8786. // Retry if any event replaying was blocked on this.
  8787. retryIfBlockedOn(suspenseInstance);
  8788. }
  8789. function didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, text) {
  8790. {
  8791. warnForUnmatchedText(textInstance, text);
  8792. }
  8793. }
  8794. function didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, text) {
  8795. if ( parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) {
  8796. warnForUnmatchedText(textInstance, text);
  8797. }
  8798. }
  8799. function didNotHydrateContainerInstance(parentContainer, instance) {
  8800. {
  8801. if (instance.nodeType === ELEMENT_NODE) {
  8802. warnForDeletedHydratableElement(parentContainer, instance);
  8803. } else if (instance.nodeType === COMMENT_NODE) ; else {
  8804. warnForDeletedHydratableText(parentContainer, instance);
  8805. }
  8806. }
  8807. }
  8808. function didNotHydrateInstance(parentType, parentProps, parentInstance, instance) {
  8809. if ( parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) {
  8810. if (instance.nodeType === ELEMENT_NODE) {
  8811. warnForDeletedHydratableElement(parentInstance, instance);
  8812. } else if (instance.nodeType === COMMENT_NODE) ; else {
  8813. warnForDeletedHydratableText(parentInstance, instance);
  8814. }
  8815. }
  8816. }
  8817. function didNotFindHydratableContainerInstance(parentContainer, type, props) {
  8818. {
  8819. warnForInsertedHydratedElement(parentContainer, type);
  8820. }
  8821. }
  8822. function didNotFindHydratableContainerTextInstance(parentContainer, text) {
  8823. {
  8824. warnForInsertedHydratedText(parentContainer, text);
  8825. }
  8826. }
  8827. function didNotFindHydratableInstance(parentType, parentProps, parentInstance, type, props) {
  8828. if ( parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) {
  8829. warnForInsertedHydratedElement(parentInstance, type);
  8830. }
  8831. }
  8832. function didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, text) {
  8833. if ( parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) {
  8834. warnForInsertedHydratedText(parentInstance, text);
  8835. }
  8836. }
  8837. function didNotFindHydratableSuspenseInstance(parentType, parentProps, parentInstance) {
  8838. if ( parentProps[SUPPRESS_HYDRATION_WARNING$1] !== true) ;
  8839. }
  8840. var clientId = 0;
  8841. function makeClientIdInDEV(warnOnAccessInDEV) {
  8842. var id = 'r:' + (clientId++).toString(36);
  8843. return {
  8844. toString: function () {
  8845. warnOnAccessInDEV();
  8846. return id;
  8847. },
  8848. valueOf: function () {
  8849. warnOnAccessInDEV();
  8850. return id;
  8851. }
  8852. };
  8853. }
  8854. function isOpaqueHydratingObject(value) {
  8855. return value !== null && typeof value === 'object' && value.$$typeof === REACT_OPAQUE_ID_TYPE;
  8856. }
  8857. function makeOpaqueHydratingObject(attemptToReadValue) {
  8858. return {
  8859. $$typeof: REACT_OPAQUE_ID_TYPE,
  8860. toString: attemptToReadValue,
  8861. valueOf: attemptToReadValue
  8862. };
  8863. }
  8864. function preparePortalMount(portalInstance) {
  8865. {
  8866. listenToAllSupportedEvents(portalInstance);
  8867. }
  8868. }
  8869. var randomKey = Math.random().toString(36).slice(2);
  8870. var internalInstanceKey = '__reactFiber$' + randomKey;
  8871. var internalPropsKey = '__reactProps$' + randomKey;
  8872. var internalContainerInstanceKey = '__reactContainer$' + randomKey;
  8873. var internalEventHandlersKey = '__reactEvents$' + randomKey;
  8874. function precacheFiberNode(hostInst, node) {
  8875. node[internalInstanceKey] = hostInst;
  8876. }
  8877. function markContainerAsRoot(hostRoot, node) {
  8878. node[internalContainerInstanceKey] = hostRoot;
  8879. }
  8880. function unmarkContainerAsRoot(node) {
  8881. node[internalContainerInstanceKey] = null;
  8882. }
  8883. function isContainerMarkedAsRoot(node) {
  8884. return !!node[internalContainerInstanceKey];
  8885. } // Given a DOM node, return the closest HostComponent or HostText fiber ancestor.
  8886. // If the target node is part of a hydrated or not yet rendered subtree, then
  8887. // this may also return a SuspenseComponent or HostRoot to indicate that.
  8888. // Conceptually the HostRoot fiber is a child of the Container node. So if you
  8889. // pass the Container node as the targetNode, you will not actually get the
  8890. // HostRoot back. To get to the HostRoot, you need to pass a child of it.
  8891. // The same thing applies to Suspense boundaries.
  8892. function getClosestInstanceFromNode(targetNode) {
  8893. var targetInst = targetNode[internalInstanceKey];
  8894. if (targetInst) {
  8895. // Don't return HostRoot or SuspenseComponent here.
  8896. return targetInst;
  8897. } // If the direct event target isn't a React owned DOM node, we need to look
  8898. // to see if one of its parents is a React owned DOM node.
  8899. var parentNode = targetNode.parentNode;
  8900. while (parentNode) {
  8901. // We'll check if this is a container root that could include
  8902. // React nodes in the future. We need to check this first because
  8903. // if we're a child of a dehydrated container, we need to first
  8904. // find that inner container before moving on to finding the parent
  8905. // instance. Note that we don't check this field on the targetNode
  8906. // itself because the fibers are conceptually between the container
  8907. // node and the first child. It isn't surrounding the container node.
  8908. // If it's not a container, we check if it's an instance.
  8909. targetInst = parentNode[internalContainerInstanceKey] || parentNode[internalInstanceKey];
  8910. if (targetInst) {
  8911. // Since this wasn't the direct target of the event, we might have
  8912. // stepped past dehydrated DOM nodes to get here. However they could
  8913. // also have been non-React nodes. We need to answer which one.
  8914. // If we the instance doesn't have any children, then there can't be
  8915. // a nested suspense boundary within it. So we can use this as a fast
  8916. // bailout. Most of the time, when people add non-React children to
  8917. // the tree, it is using a ref to a child-less DOM node.
  8918. // Normally we'd only need to check one of the fibers because if it
  8919. // has ever gone from having children to deleting them or vice versa
  8920. // it would have deleted the dehydrated boundary nested inside already.
  8921. // However, since the HostRoot starts out with an alternate it might
  8922. // have one on the alternate so we need to check in case this was a
  8923. // root.
  8924. var alternate = targetInst.alternate;
  8925. if (targetInst.child !== null || alternate !== null && alternate.child !== null) {
  8926. // Next we need to figure out if the node that skipped past is
  8927. // nested within a dehydrated boundary and if so, which one.
  8928. var suspenseInstance = getParentSuspenseInstance(targetNode);
  8929. while (suspenseInstance !== null) {
  8930. // We found a suspense instance. That means that we haven't
  8931. // hydrated it yet. Even though we leave the comments in the
  8932. // DOM after hydrating, and there are boundaries in the DOM
  8933. // that could already be hydrated, we wouldn't have found them
  8934. // through this pass since if the target is hydrated it would
  8935. // have had an internalInstanceKey on it.
  8936. // Let's get the fiber associated with the SuspenseComponent
  8937. // as the deepest instance.
  8938. var targetSuspenseInst = suspenseInstance[internalInstanceKey];
  8939. if (targetSuspenseInst) {
  8940. return targetSuspenseInst;
  8941. } // If we don't find a Fiber on the comment, it might be because
  8942. // we haven't gotten to hydrate it yet. There might still be a
  8943. // parent boundary that hasn't above this one so we need to find
  8944. // the outer most that is known.
  8945. suspenseInstance = getParentSuspenseInstance(suspenseInstance); // If we don't find one, then that should mean that the parent
  8946. // host component also hasn't hydrated yet. We can return it
  8947. // below since it will bail out on the isMounted check later.
  8948. }
  8949. }
  8950. return targetInst;
  8951. }
  8952. targetNode = parentNode;
  8953. parentNode = targetNode.parentNode;
  8954. }
  8955. return null;
  8956. }
  8957. /**
  8958. * Given a DOM node, return the ReactDOMComponent or ReactDOMTextComponent
  8959. * instance, or null if the node was not rendered by this React.
  8960. */
  8961. function getInstanceFromNode(node) {
  8962. var inst = node[internalInstanceKey] || node[internalContainerInstanceKey];
  8963. if (inst) {
  8964. if (inst.tag === HostComponent || inst.tag === HostText || inst.tag === SuspenseComponent || inst.tag === HostRoot) {
  8965. return inst;
  8966. } else {
  8967. return null;
  8968. }
  8969. }
  8970. return null;
  8971. }
  8972. /**
  8973. * Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
  8974. * DOM node.
  8975. */
  8976. function getNodeFromInstance(inst) {
  8977. if (inst.tag === HostComponent || inst.tag === HostText) {
  8978. // In Fiber this, is just the state node right now. We assume it will be
  8979. // a host component or host text.
  8980. return inst.stateNode;
  8981. } // Without this first invariant, passing a non-DOM-component triggers the next
  8982. // invariant for a missing parent, which is super confusing.
  8983. {
  8984. {
  8985. throw Error( "getNodeFromInstance: Invalid argument." );
  8986. }
  8987. }
  8988. }
  8989. function getFiberCurrentPropsFromNode(node) {
  8990. return node[internalPropsKey] || null;
  8991. }
  8992. function updateFiberProps(node, props) {
  8993. node[internalPropsKey] = props;
  8994. }
  8995. function getEventListenerSet(node) {
  8996. var elementListenerSet = node[internalEventHandlersKey];
  8997. if (elementListenerSet === undefined) {
  8998. elementListenerSet = node[internalEventHandlersKey] = new Set();
  8999. }
  9000. return elementListenerSet;
  9001. }
  9002. var loggedTypeFailures = {};
  9003. var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
  9004. function setCurrentlyValidatingElement(element) {
  9005. {
  9006. if (element) {
  9007. var owner = element._owner;
  9008. var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
  9009. ReactDebugCurrentFrame$1.setExtraStackFrame(stack);
  9010. } else {
  9011. ReactDebugCurrentFrame$1.setExtraStackFrame(null);
  9012. }
  9013. }
  9014. }
  9015. function checkPropTypes(typeSpecs, values, location, componentName, element) {
  9016. {
  9017. // $FlowFixMe This is okay but Flow doesn't know it.
  9018. var has = Function.call.bind(Object.prototype.hasOwnProperty);
  9019. for (var typeSpecName in typeSpecs) {
  9020. if (has(typeSpecs, typeSpecName)) {
  9021. var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
  9022. // fail the render phase where it didn't fail before. So we log it.
  9023. // After these have been cleaned up, we'll let them throw.
  9024. try {
  9025. // This is intentionally an invariant that gets caught. It's the same
  9026. // behavior as without this statement except with a better message.
  9027. if (typeof typeSpecs[typeSpecName] !== 'function') {
  9028. var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' + 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.');
  9029. err.name = 'Invariant Violation';
  9030. throw err;
  9031. }
  9032. error$1 = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED');
  9033. } catch (ex) {
  9034. error$1 = ex;
  9035. }
  9036. if (error$1 && !(error$1 instanceof Error)) {
  9037. setCurrentlyValidatingElement(element);
  9038. error('%s: type specification of %s' + ' `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error$1);
  9039. setCurrentlyValidatingElement(null);
  9040. }
  9041. if (error$1 instanceof Error && !(error$1.message in loggedTypeFailures)) {
  9042. // Only monitor this failure once because there tends to be a lot of the
  9043. // same error.
  9044. loggedTypeFailures[error$1.message] = true;
  9045. setCurrentlyValidatingElement(element);
  9046. error('Failed %s type: %s', location, error$1.message);
  9047. setCurrentlyValidatingElement(null);
  9048. }
  9049. }
  9050. }
  9051. }
  9052. }
  9053. var valueStack = [];
  9054. var fiberStack;
  9055. {
  9056. fiberStack = [];
  9057. }
  9058. var index = -1;
  9059. function createCursor(defaultValue) {
  9060. return {
  9061. current: defaultValue
  9062. };
  9063. }
  9064. function pop(cursor, fiber) {
  9065. if (index < 0) {
  9066. {
  9067. error('Unexpected pop.');
  9068. }
  9069. return;
  9070. }
  9071. {
  9072. if (fiber !== fiberStack[index]) {
  9073. error('Unexpected Fiber popped.');
  9074. }
  9075. }
  9076. cursor.current = valueStack[index];
  9077. valueStack[index] = null;
  9078. {
  9079. fiberStack[index] = null;
  9080. }
  9081. index--;
  9082. }
  9083. function push(cursor, value, fiber) {
  9084. index++;
  9085. valueStack[index] = cursor.current;
  9086. {
  9087. fiberStack[index] = fiber;
  9088. }
  9089. cursor.current = value;
  9090. }
  9091. var warnedAboutMissingGetChildContext;
  9092. {
  9093. warnedAboutMissingGetChildContext = {};
  9094. }
  9095. var emptyContextObject = {};
  9096. {
  9097. Object.freeze(emptyContextObject);
  9098. } // A cursor to the current merged context object on the stack.
  9099. var contextStackCursor = createCursor(emptyContextObject); // A cursor to a boolean indicating whether the context has changed.
  9100. var didPerformWorkStackCursor = createCursor(false); // Keep track of the previous context object that was on the stack.
  9101. // We use this to get access to the parent context after we have already
  9102. // pushed the next context provider, and now need to merge their contexts.
  9103. var previousContext = emptyContextObject;
  9104. function getUnmaskedContext(workInProgress, Component, didPushOwnContextIfProvider) {
  9105. {
  9106. if (didPushOwnContextIfProvider && isContextProvider(Component)) {
  9107. // If the fiber is a context provider itself, when we read its context
  9108. // we may have already pushed its own child context on the stack. A context
  9109. // provider should not "see" its own child context. Therefore we read the
  9110. // previous (parent) context instead for a context provider.
  9111. return previousContext;
  9112. }
  9113. return contextStackCursor.current;
  9114. }
  9115. }
  9116. function cacheContext(workInProgress, unmaskedContext, maskedContext) {
  9117. {
  9118. var instance = workInProgress.stateNode;
  9119. instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
  9120. instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
  9121. }
  9122. }
  9123. function getMaskedContext(workInProgress, unmaskedContext) {
  9124. {
  9125. var type = workInProgress.type;
  9126. var contextTypes = type.contextTypes;
  9127. if (!contextTypes) {
  9128. return emptyContextObject;
  9129. } // Avoid recreating masked context unless unmasked context has changed.
  9130. // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
  9131. // This may trigger infinite loops if componentWillReceiveProps calls setState.
  9132. var instance = workInProgress.stateNode;
  9133. if (instance && instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext) {
  9134. return instance.__reactInternalMemoizedMaskedChildContext;
  9135. }
  9136. var context = {};
  9137. for (var key in contextTypes) {
  9138. context[key] = unmaskedContext[key];
  9139. }
  9140. {
  9141. var name = getComponentName(type) || 'Unknown';
  9142. checkPropTypes(contextTypes, context, 'context', name);
  9143. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  9144. // Context is created before the class component is instantiated so check for instance.
  9145. if (instance) {
  9146. cacheContext(workInProgress, unmaskedContext, context);
  9147. }
  9148. return context;
  9149. }
  9150. }
  9151. function hasContextChanged() {
  9152. {
  9153. return didPerformWorkStackCursor.current;
  9154. }
  9155. }
  9156. function isContextProvider(type) {
  9157. {
  9158. var childContextTypes = type.childContextTypes;
  9159. return childContextTypes !== null && childContextTypes !== undefined;
  9160. }
  9161. }
  9162. function popContext(fiber) {
  9163. {
  9164. pop(didPerformWorkStackCursor, fiber);
  9165. pop(contextStackCursor, fiber);
  9166. }
  9167. }
  9168. function popTopLevelContextObject(fiber) {
  9169. {
  9170. pop(didPerformWorkStackCursor, fiber);
  9171. pop(contextStackCursor, fiber);
  9172. }
  9173. }
  9174. function pushTopLevelContextObject(fiber, context, didChange) {
  9175. {
  9176. if (!(contextStackCursor.current === emptyContextObject)) {
  9177. {
  9178. throw Error( "Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue." );
  9179. }
  9180. }
  9181. push(contextStackCursor, context, fiber);
  9182. push(didPerformWorkStackCursor, didChange, fiber);
  9183. }
  9184. }
  9185. function processChildContext(fiber, type, parentContext) {
  9186. {
  9187. var instance = fiber.stateNode;
  9188. var childContextTypes = type.childContextTypes; // TODO (bvaughn) Replace this behavior with an invariant() in the future.
  9189. // It has only been added in Fiber to match the (unintentional) behavior in Stack.
  9190. if (typeof instance.getChildContext !== 'function') {
  9191. {
  9192. var componentName = getComponentName(type) || 'Unknown';
  9193. if (!warnedAboutMissingGetChildContext[componentName]) {
  9194. warnedAboutMissingGetChildContext[componentName] = true;
  9195. error('%s.childContextTypes is specified but there is no getChildContext() method ' + 'on the instance. You can either define getChildContext() on %s or remove ' + 'childContextTypes from it.', componentName, componentName);
  9196. }
  9197. }
  9198. return parentContext;
  9199. }
  9200. var childContext = instance.getChildContext();
  9201. for (var contextKey in childContext) {
  9202. if (!(contextKey in childContextTypes)) {
  9203. {
  9204. throw Error( (getComponentName(type) || 'Unknown') + ".getChildContext(): key \"" + contextKey + "\" is not defined in childContextTypes." );
  9205. }
  9206. }
  9207. }
  9208. {
  9209. var name = getComponentName(type) || 'Unknown';
  9210. checkPropTypes(childContextTypes, childContext, 'child context', name);
  9211. }
  9212. return _assign({}, parentContext, childContext);
  9213. }
  9214. }
  9215. function pushContextProvider(workInProgress) {
  9216. {
  9217. var instance = workInProgress.stateNode; // We push the context as early as possible to ensure stack integrity.
  9218. // If the instance does not exist yet, we will push null at first,
  9219. // and replace it on the stack later when invalidating the context.
  9220. var memoizedMergedChildContext = instance && instance.__reactInternalMemoizedMergedChildContext || emptyContextObject; // Remember the parent context so we can merge with it later.
  9221. // Inherit the parent's did-perform-work value to avoid inadvertently blocking updates.
  9222. previousContext = contextStackCursor.current;
  9223. push(contextStackCursor, memoizedMergedChildContext, workInProgress);
  9224. push(didPerformWorkStackCursor, didPerformWorkStackCursor.current, workInProgress);
  9225. return true;
  9226. }
  9227. }
  9228. function invalidateContextProvider(workInProgress, type, didChange) {
  9229. {
  9230. var instance = workInProgress.stateNode;
  9231. if (!instance) {
  9232. {
  9233. throw Error( "Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue." );
  9234. }
  9235. }
  9236. if (didChange) {
  9237. // Merge parent and own context.
  9238. // Skip this if we're not updating due to sCU.
  9239. // This avoids unnecessarily recomputing memoized values.
  9240. var mergedContext = processChildContext(workInProgress, type, previousContext);
  9241. instance.__reactInternalMemoizedMergedChildContext = mergedContext; // Replace the old (or empty) context with the new one.
  9242. // It is important to unwind the context in the reverse order.
  9243. pop(didPerformWorkStackCursor, workInProgress);
  9244. pop(contextStackCursor, workInProgress); // Now push the new context and mark that it has changed.
  9245. push(contextStackCursor, mergedContext, workInProgress);
  9246. push(didPerformWorkStackCursor, didChange, workInProgress);
  9247. } else {
  9248. pop(didPerformWorkStackCursor, workInProgress);
  9249. push(didPerformWorkStackCursor, didChange, workInProgress);
  9250. }
  9251. }
  9252. }
  9253. function findCurrentUnmaskedContext(fiber) {
  9254. {
  9255. // Currently this is only used with renderSubtreeIntoContainer; not sure if it
  9256. // makes sense elsewhere
  9257. if (!(isFiberMounted(fiber) && fiber.tag === ClassComponent)) {
  9258. {
  9259. throw Error( "Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue." );
  9260. }
  9261. }
  9262. var node = fiber;
  9263. do {
  9264. switch (node.tag) {
  9265. case HostRoot:
  9266. return node.stateNode.context;
  9267. case ClassComponent:
  9268. {
  9269. var Component = node.type;
  9270. if (isContextProvider(Component)) {
  9271. return node.stateNode.__reactInternalMemoizedMergedChildContext;
  9272. }
  9273. break;
  9274. }
  9275. }
  9276. node = node.return;
  9277. } while (node !== null);
  9278. {
  9279. {
  9280. throw Error( "Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue." );
  9281. }
  9282. }
  9283. }
  9284. }
  9285. var LegacyRoot = 0;
  9286. var BlockingRoot = 1;
  9287. var ConcurrentRoot = 2;
  9288. var rendererID = null;
  9289. var injectedHook = null;
  9290. var hasLoggedError = false;
  9291. var isDevToolsPresent = typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined';
  9292. function injectInternals(internals) {
  9293. if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
  9294. // No DevTools
  9295. return false;
  9296. }
  9297. var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
  9298. if (hook.isDisabled) {
  9299. // This isn't a real property on the hook, but it can be set to opt out
  9300. // of DevTools integration and associated warnings and logs.
  9301. // https://github.com/facebook/react/issues/3877
  9302. return true;
  9303. }
  9304. if (!hook.supportsFiber) {
  9305. {
  9306. error('The installed version of React DevTools is too old and will not work ' + 'with the current version of React. Please update React DevTools. ' + 'https://reactjs.org/link/react-devtools');
  9307. } // DevTools exists, even though it doesn't support Fiber.
  9308. return true;
  9309. }
  9310. try {
  9311. rendererID = hook.inject(internals); // We have successfully injected, so now it is safe to set up hooks.
  9312. injectedHook = hook;
  9313. } catch (err) {
  9314. // Catch all errors because it is unsafe to throw during initialization.
  9315. {
  9316. error('React instrumentation encountered an error: %s.', err);
  9317. }
  9318. } // DevTools exists
  9319. return true;
  9320. }
  9321. function onScheduleRoot(root, children) {
  9322. {
  9323. if (injectedHook && typeof injectedHook.onScheduleFiberRoot === 'function') {
  9324. try {
  9325. injectedHook.onScheduleFiberRoot(rendererID, root, children);
  9326. } catch (err) {
  9327. if ( !hasLoggedError) {
  9328. hasLoggedError = true;
  9329. error('React instrumentation encountered an error: %s', err);
  9330. }
  9331. }
  9332. }
  9333. }
  9334. }
  9335. function onCommitRoot(root, priorityLevel) {
  9336. if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') {
  9337. try {
  9338. var didError = (root.current.flags & DidCapture) === DidCapture;
  9339. if (enableProfilerTimer) {
  9340. injectedHook.onCommitFiberRoot(rendererID, root, priorityLevel, didError);
  9341. } else {
  9342. injectedHook.onCommitFiberRoot(rendererID, root, undefined, didError);
  9343. }
  9344. } catch (err) {
  9345. {
  9346. if (!hasLoggedError) {
  9347. hasLoggedError = true;
  9348. error('React instrumentation encountered an error: %s', err);
  9349. }
  9350. }
  9351. }
  9352. }
  9353. }
  9354. function onCommitUnmount(fiber) {
  9355. if (injectedHook && typeof injectedHook.onCommitFiberUnmount === 'function') {
  9356. try {
  9357. injectedHook.onCommitFiberUnmount(rendererID, fiber);
  9358. } catch (err) {
  9359. {
  9360. if (!hasLoggedError) {
  9361. hasLoggedError = true;
  9362. error('React instrumentation encountered an error: %s', err);
  9363. }
  9364. }
  9365. }
  9366. }
  9367. }
  9368. var Scheduler_runWithPriority = unstable_runWithPriority,
  9369. Scheduler_scheduleCallback = unstable_scheduleCallback,
  9370. Scheduler_cancelCallback = unstable_cancelCallback,
  9371. Scheduler_shouldYield = unstable_shouldYield,
  9372. Scheduler_requestPaint = unstable_requestPaint,
  9373. Scheduler_now$1 = unstable_now,
  9374. Scheduler_getCurrentPriorityLevel = unstable_getCurrentPriorityLevel,
  9375. Scheduler_ImmediatePriority = unstable_ImmediatePriority,
  9376. Scheduler_UserBlockingPriority = unstable_UserBlockingPriority,
  9377. Scheduler_NormalPriority = unstable_NormalPriority,
  9378. Scheduler_LowPriority = unstable_LowPriority,
  9379. Scheduler_IdlePriority = unstable_IdlePriority;
  9380. {
  9381. // Provide explicit error message when production+profiling bundle of e.g.
  9382. // react-dom is used with production (non-profiling) bundle of
  9383. // scheduler/tracing
  9384. if (!(__interactionsRef != null && __interactionsRef.current != null)) {
  9385. {
  9386. throw Error( "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 https://reactjs.org/link/profiling" );
  9387. }
  9388. }
  9389. }
  9390. var fakeCallbackNode = {}; // Except for NoPriority, these correspond to Scheduler priorities. We use
  9391. // ascending numbers so we can compare them like numbers. They start at 90 to
  9392. // avoid clashing with Scheduler's priorities.
  9393. var ImmediatePriority$1 = 99;
  9394. var UserBlockingPriority$2 = 98;
  9395. var NormalPriority$1 = 97;
  9396. var LowPriority$1 = 96;
  9397. var IdlePriority$1 = 95; // NoPriority is the absence of priority. Also React-only.
  9398. var NoPriority$1 = 90;
  9399. var shouldYield = Scheduler_shouldYield;
  9400. var requestPaint = // Fall back gracefully if we're running an older version of Scheduler.
  9401. Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : function () {};
  9402. var syncQueue = null;
  9403. var immediateQueueCallbackNode = null;
  9404. var isFlushingSyncQueue = false;
  9405. var initialTimeMs$1 = Scheduler_now$1(); // If the initial timestamp is reasonably small, use Scheduler's `now` directly.
  9406. // This will be the case for modern browsers that support `performance.now`. In
  9407. // older browsers, Scheduler falls back to `Date.now`, which returns a Unix
  9408. // timestamp. In that case, subtract the module initialization time to simulate
  9409. // the behavior of performance.now and keep our times small enough to fit
  9410. // within 32 bits.
  9411. // TODO: Consider lifting this into Scheduler.
  9412. var now = initialTimeMs$1 < 10000 ? Scheduler_now$1 : function () {
  9413. return Scheduler_now$1() - initialTimeMs$1;
  9414. };
  9415. function getCurrentPriorityLevel() {
  9416. switch (Scheduler_getCurrentPriorityLevel()) {
  9417. case Scheduler_ImmediatePriority:
  9418. return ImmediatePriority$1;
  9419. case Scheduler_UserBlockingPriority:
  9420. return UserBlockingPriority$2;
  9421. case Scheduler_NormalPriority:
  9422. return NormalPriority$1;
  9423. case Scheduler_LowPriority:
  9424. return LowPriority$1;
  9425. case Scheduler_IdlePriority:
  9426. return IdlePriority$1;
  9427. default:
  9428. {
  9429. {
  9430. throw Error( "Unknown priority level." );
  9431. }
  9432. }
  9433. }
  9434. }
  9435. function reactPriorityToSchedulerPriority(reactPriorityLevel) {
  9436. switch (reactPriorityLevel) {
  9437. case ImmediatePriority$1:
  9438. return Scheduler_ImmediatePriority;
  9439. case UserBlockingPriority$2:
  9440. return Scheduler_UserBlockingPriority;
  9441. case NormalPriority$1:
  9442. return Scheduler_NormalPriority;
  9443. case LowPriority$1:
  9444. return Scheduler_LowPriority;
  9445. case IdlePriority$1:
  9446. return Scheduler_IdlePriority;
  9447. default:
  9448. {
  9449. {
  9450. throw Error( "Unknown priority level." );
  9451. }
  9452. }
  9453. }
  9454. }
  9455. function runWithPriority$1(reactPriorityLevel, fn) {
  9456. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  9457. return Scheduler_runWithPriority(priorityLevel, fn);
  9458. }
  9459. function scheduleCallback(reactPriorityLevel, callback, options) {
  9460. var priorityLevel = reactPriorityToSchedulerPriority(reactPriorityLevel);
  9461. return Scheduler_scheduleCallback(priorityLevel, callback, options);
  9462. }
  9463. function scheduleSyncCallback(callback) {
  9464. // Push this callback into an internal queue. We'll flush these either in
  9465. // the next tick, or earlier if something calls `flushSyncCallbackQueue`.
  9466. if (syncQueue === null) {
  9467. syncQueue = [callback]; // Flush the queue in the next tick, at the earliest.
  9468. immediateQueueCallbackNode = Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueueImpl);
  9469. } else {
  9470. // Push onto existing queue. Don't need to schedule a callback because
  9471. // we already scheduled one when we created the queue.
  9472. syncQueue.push(callback);
  9473. }
  9474. return fakeCallbackNode;
  9475. }
  9476. function cancelCallback(callbackNode) {
  9477. if (callbackNode !== fakeCallbackNode) {
  9478. Scheduler_cancelCallback(callbackNode);
  9479. }
  9480. }
  9481. function flushSyncCallbackQueue() {
  9482. if (immediateQueueCallbackNode !== null) {
  9483. var node = immediateQueueCallbackNode;
  9484. immediateQueueCallbackNode = null;
  9485. Scheduler_cancelCallback(node);
  9486. }
  9487. flushSyncCallbackQueueImpl();
  9488. }
  9489. function flushSyncCallbackQueueImpl() {
  9490. if (!isFlushingSyncQueue && syncQueue !== null) {
  9491. // Prevent re-entrancy.
  9492. isFlushingSyncQueue = true;
  9493. var i = 0;
  9494. {
  9495. try {
  9496. var _isSync2 = true;
  9497. var _queue = syncQueue;
  9498. runWithPriority$1(ImmediatePriority$1, function () {
  9499. for (; i < _queue.length; i++) {
  9500. var callback = _queue[i];
  9501. do {
  9502. callback = callback(_isSync2);
  9503. } while (callback !== null);
  9504. }
  9505. });
  9506. syncQueue = null;
  9507. } catch (error) {
  9508. // If something throws, leave the remaining callbacks on the queue.
  9509. if (syncQueue !== null) {
  9510. syncQueue = syncQueue.slice(i + 1);
  9511. } // Resume flushing in the next tick
  9512. Scheduler_scheduleCallback(Scheduler_ImmediatePriority, flushSyncCallbackQueue);
  9513. throw error;
  9514. } finally {
  9515. isFlushingSyncQueue = false;
  9516. }
  9517. }
  9518. }
  9519. }
  9520. // TODO: this is special because it gets imported during build.
  9521. var ReactVersion = '17.0.2';
  9522. var NoMode = 0;
  9523. var StrictMode = 1; // TODO: Remove BlockingMode and ConcurrentMode by reading from the root
  9524. // tag instead
  9525. var BlockingMode = 2;
  9526. var ConcurrentMode = 4;
  9527. var ProfileMode = 8;
  9528. var DebugTracingMode = 16;
  9529. var ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig;
  9530. var NoTransition = 0;
  9531. function requestCurrentTransition() {
  9532. return ReactCurrentBatchConfig.transition;
  9533. }
  9534. var ReactStrictModeWarnings = {
  9535. recordUnsafeLifecycleWarnings: function (fiber, instance) {},
  9536. flushPendingUnsafeLifecycleWarnings: function () {},
  9537. recordLegacyContextWarning: function (fiber, instance) {},
  9538. flushLegacyContextWarning: function () {},
  9539. discardPendingWarnings: function () {}
  9540. };
  9541. {
  9542. var findStrictRoot = function (fiber) {
  9543. var maybeStrictRoot = null;
  9544. var node = fiber;
  9545. while (node !== null) {
  9546. if (node.mode & StrictMode) {
  9547. maybeStrictRoot = node;
  9548. }
  9549. node = node.return;
  9550. }
  9551. return maybeStrictRoot;
  9552. };
  9553. var setToSortedString = function (set) {
  9554. var array = [];
  9555. set.forEach(function (value) {
  9556. array.push(value);
  9557. });
  9558. return array.sort().join(', ');
  9559. };
  9560. var pendingComponentWillMountWarnings = [];
  9561. var pendingUNSAFE_ComponentWillMountWarnings = [];
  9562. var pendingComponentWillReceivePropsWarnings = [];
  9563. var pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  9564. var pendingComponentWillUpdateWarnings = [];
  9565. var pendingUNSAFE_ComponentWillUpdateWarnings = []; // Tracks components we have already warned about.
  9566. var didWarnAboutUnsafeLifecycles = new Set();
  9567. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings = function (fiber, instance) {
  9568. // Dedup strategy: Warn once per component.
  9569. if (didWarnAboutUnsafeLifecycles.has(fiber.type)) {
  9570. return;
  9571. }
  9572. if (typeof instance.componentWillMount === 'function' && // Don't warn about react-lifecycles-compat polyfilled components.
  9573. instance.componentWillMount.__suppressDeprecationWarning !== true) {
  9574. pendingComponentWillMountWarnings.push(fiber);
  9575. }
  9576. if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillMount === 'function') {
  9577. pendingUNSAFE_ComponentWillMountWarnings.push(fiber);
  9578. }
  9579. if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
  9580. pendingComponentWillReceivePropsWarnings.push(fiber);
  9581. }
  9582. if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  9583. pendingUNSAFE_ComponentWillReceivePropsWarnings.push(fiber);
  9584. }
  9585. if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
  9586. pendingComponentWillUpdateWarnings.push(fiber);
  9587. }
  9588. if (fiber.mode & StrictMode && typeof instance.UNSAFE_componentWillUpdate === 'function') {
  9589. pendingUNSAFE_ComponentWillUpdateWarnings.push(fiber);
  9590. }
  9591. };
  9592. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings = function () {
  9593. // We do an initial pass to gather component names
  9594. var componentWillMountUniqueNames = new Set();
  9595. if (pendingComponentWillMountWarnings.length > 0) {
  9596. pendingComponentWillMountWarnings.forEach(function (fiber) {
  9597. componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
  9598. didWarnAboutUnsafeLifecycles.add(fiber.type);
  9599. });
  9600. pendingComponentWillMountWarnings = [];
  9601. }
  9602. var UNSAFE_componentWillMountUniqueNames = new Set();
  9603. if (pendingUNSAFE_ComponentWillMountWarnings.length > 0) {
  9604. pendingUNSAFE_ComponentWillMountWarnings.forEach(function (fiber) {
  9605. UNSAFE_componentWillMountUniqueNames.add(getComponentName(fiber.type) || 'Component');
  9606. didWarnAboutUnsafeLifecycles.add(fiber.type);
  9607. });
  9608. pendingUNSAFE_ComponentWillMountWarnings = [];
  9609. }
  9610. var componentWillReceivePropsUniqueNames = new Set();
  9611. if (pendingComponentWillReceivePropsWarnings.length > 0) {
  9612. pendingComponentWillReceivePropsWarnings.forEach(function (fiber) {
  9613. componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
  9614. didWarnAboutUnsafeLifecycles.add(fiber.type);
  9615. });
  9616. pendingComponentWillReceivePropsWarnings = [];
  9617. }
  9618. var UNSAFE_componentWillReceivePropsUniqueNames = new Set();
  9619. if (pendingUNSAFE_ComponentWillReceivePropsWarnings.length > 0) {
  9620. pendingUNSAFE_ComponentWillReceivePropsWarnings.forEach(function (fiber) {
  9621. UNSAFE_componentWillReceivePropsUniqueNames.add(getComponentName(fiber.type) || 'Component');
  9622. didWarnAboutUnsafeLifecycles.add(fiber.type);
  9623. });
  9624. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  9625. }
  9626. var componentWillUpdateUniqueNames = new Set();
  9627. if (pendingComponentWillUpdateWarnings.length > 0) {
  9628. pendingComponentWillUpdateWarnings.forEach(function (fiber) {
  9629. componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
  9630. didWarnAboutUnsafeLifecycles.add(fiber.type);
  9631. });
  9632. pendingComponentWillUpdateWarnings = [];
  9633. }
  9634. var UNSAFE_componentWillUpdateUniqueNames = new Set();
  9635. if (pendingUNSAFE_ComponentWillUpdateWarnings.length > 0) {
  9636. pendingUNSAFE_ComponentWillUpdateWarnings.forEach(function (fiber) {
  9637. UNSAFE_componentWillUpdateUniqueNames.add(getComponentName(fiber.type) || 'Component');
  9638. didWarnAboutUnsafeLifecycles.add(fiber.type);
  9639. });
  9640. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  9641. } // Finally, we flush all the warnings
  9642. // UNSAFE_ ones before the deprecated ones, since they'll be 'louder'
  9643. if (UNSAFE_componentWillMountUniqueNames.size > 0) {
  9644. var sortedNames = setToSortedString(UNSAFE_componentWillMountUniqueNames);
  9645. error('Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. ' + 'See https://reactjs.org/link/unsafe-component-lifecycles for details.\n\n' + '* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' + '\nPlease update the following components: %s', sortedNames);
  9646. }
  9647. if (UNSAFE_componentWillReceivePropsUniqueNames.size > 0) {
  9648. var _sortedNames = setToSortedString(UNSAFE_componentWillReceivePropsUniqueNames);
  9649. error('Using UNSAFE_componentWillReceiveProps in strict mode is not recommended ' + 'and may indicate bugs in your code. ' + 'See https://reactjs.org/link/unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + "* If you're updating state whenever props change, " + 'refactor your code to use memoization techniques or move it to ' + 'static getDerivedStateFromProps. Learn more at: https://reactjs.org/link/derived-state\n' + '\nPlease update the following components: %s', _sortedNames);
  9650. }
  9651. if (UNSAFE_componentWillUpdateUniqueNames.size > 0) {
  9652. var _sortedNames2 = setToSortedString(UNSAFE_componentWillUpdateUniqueNames);
  9653. error('Using UNSAFE_componentWillUpdate in strict mode is not recommended ' + 'and may indicate bugs in your code. ' + 'See https://reactjs.org/link/unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + '\nPlease update the following components: %s', _sortedNames2);
  9654. }
  9655. if (componentWillMountUniqueNames.size > 0) {
  9656. var _sortedNames3 = setToSortedString(componentWillMountUniqueNames);
  9657. warn('componentWillMount has been renamed, and is not recommended for use. ' + 'See https://reactjs.org/link/unsafe-component-lifecycles for details.\n\n' + '* Move code with side effects to componentDidMount, and set initial state in the constructor.\n' + '* Rename componentWillMount to UNSAFE_componentWillMount to suppress ' + 'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' + 'To rename all deprecated lifecycles to their new names, you can run ' + '`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' + '\nPlease update the following components: %s', _sortedNames3);
  9658. }
  9659. if (componentWillReceivePropsUniqueNames.size > 0) {
  9660. var _sortedNames4 = setToSortedString(componentWillReceivePropsUniqueNames);
  9661. warn('componentWillReceiveProps has been renamed, and is not recommended for use. ' + 'See https://reactjs.org/link/unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + "* If you're updating state whenever props change, refactor your " + 'code to use memoization techniques or move it to ' + 'static getDerivedStateFromProps. Learn more at: https://reactjs.org/link/derived-state\n' + '* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress ' + 'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' + 'To rename all deprecated lifecycles to their new names, you can run ' + '`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' + '\nPlease update the following components: %s', _sortedNames4);
  9662. }
  9663. if (componentWillUpdateUniqueNames.size > 0) {
  9664. var _sortedNames5 = setToSortedString(componentWillUpdateUniqueNames);
  9665. warn('componentWillUpdate has been renamed, and is not recommended for use. ' + 'See https://reactjs.org/link/unsafe-component-lifecycles for details.\n\n' + '* Move data fetching code or side effects to componentDidUpdate.\n' + '* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress ' + 'this warning in non-strict mode. In React 18.x, only the UNSAFE_ name will work. ' + 'To rename all deprecated lifecycles to their new names, you can run ' + '`npx react-codemod rename-unsafe-lifecycles` in your project source folder.\n' + '\nPlease update the following components: %s', _sortedNames5);
  9666. }
  9667. };
  9668. var pendingLegacyContextWarning = new Map(); // Tracks components we have already warned about.
  9669. var didWarnAboutLegacyContext = new Set();
  9670. ReactStrictModeWarnings.recordLegacyContextWarning = function (fiber, instance) {
  9671. var strictRoot = findStrictRoot(fiber);
  9672. if (strictRoot === null) {
  9673. error('Expected to find a StrictMode component in a strict mode tree. ' + 'This error is likely caused by a bug in React. Please file an issue.');
  9674. return;
  9675. } // Dedup strategy: Warn once per component.
  9676. if (didWarnAboutLegacyContext.has(fiber.type)) {
  9677. return;
  9678. }
  9679. var warningsForRoot = pendingLegacyContextWarning.get(strictRoot);
  9680. if (fiber.type.contextTypes != null || fiber.type.childContextTypes != null || instance !== null && typeof instance.getChildContext === 'function') {
  9681. if (warningsForRoot === undefined) {
  9682. warningsForRoot = [];
  9683. pendingLegacyContextWarning.set(strictRoot, warningsForRoot);
  9684. }
  9685. warningsForRoot.push(fiber);
  9686. }
  9687. };
  9688. ReactStrictModeWarnings.flushLegacyContextWarning = function () {
  9689. pendingLegacyContextWarning.forEach(function (fiberArray, strictRoot) {
  9690. if (fiberArray.length === 0) {
  9691. return;
  9692. }
  9693. var firstFiber = fiberArray[0];
  9694. var uniqueNames = new Set();
  9695. fiberArray.forEach(function (fiber) {
  9696. uniqueNames.add(getComponentName(fiber.type) || 'Component');
  9697. didWarnAboutLegacyContext.add(fiber.type);
  9698. });
  9699. var sortedNames = setToSortedString(uniqueNames);
  9700. try {
  9701. setCurrentFiber(firstFiber);
  9702. error('Legacy context API has been detected within a strict-mode tree.' + '\n\nThe old API will be supported in all 16.x releases, but applications ' + 'using it should migrate to the new version.' + '\n\nPlease update the following components: %s' + '\n\nLearn more about this warning here: https://reactjs.org/link/legacy-context', sortedNames);
  9703. } finally {
  9704. resetCurrentFiber();
  9705. }
  9706. });
  9707. };
  9708. ReactStrictModeWarnings.discardPendingWarnings = function () {
  9709. pendingComponentWillMountWarnings = [];
  9710. pendingUNSAFE_ComponentWillMountWarnings = [];
  9711. pendingComponentWillReceivePropsWarnings = [];
  9712. pendingUNSAFE_ComponentWillReceivePropsWarnings = [];
  9713. pendingComponentWillUpdateWarnings = [];
  9714. pendingUNSAFE_ComponentWillUpdateWarnings = [];
  9715. pendingLegacyContextWarning = new Map();
  9716. };
  9717. }
  9718. function resolveDefaultProps(Component, baseProps) {
  9719. if (Component && Component.defaultProps) {
  9720. // Resolve default props. Taken from ReactElement
  9721. var props = _assign({}, baseProps);
  9722. var defaultProps = Component.defaultProps;
  9723. for (var propName in defaultProps) {
  9724. if (props[propName] === undefined) {
  9725. props[propName] = defaultProps[propName];
  9726. }
  9727. }
  9728. return props;
  9729. }
  9730. return baseProps;
  9731. }
  9732. // Max 31 bit integer. The max integer size in V8 for 32-bit systems.
  9733. // Math.pow(2, 30) - 1
  9734. // 0b111111111111111111111111111111
  9735. var MAX_SIGNED_31_BIT_INT = 1073741823;
  9736. var valueCursor = createCursor(null);
  9737. var rendererSigil;
  9738. {
  9739. // Use this to detect multiple renderers using the same context
  9740. rendererSigil = {};
  9741. }
  9742. var currentlyRenderingFiber = null;
  9743. var lastContextDependency = null;
  9744. var lastContextWithAllBitsObserved = null;
  9745. var isDisallowedContextReadInDEV = false;
  9746. function resetContextDependencies() {
  9747. // This is called right before React yields execution, to ensure `readContext`
  9748. // cannot be called outside the render phase.
  9749. currentlyRenderingFiber = null;
  9750. lastContextDependency = null;
  9751. lastContextWithAllBitsObserved = null;
  9752. {
  9753. isDisallowedContextReadInDEV = false;
  9754. }
  9755. }
  9756. function enterDisallowedContextReadInDEV() {
  9757. {
  9758. isDisallowedContextReadInDEV = true;
  9759. }
  9760. }
  9761. function exitDisallowedContextReadInDEV() {
  9762. {
  9763. isDisallowedContextReadInDEV = false;
  9764. }
  9765. }
  9766. function pushProvider(providerFiber, nextValue) {
  9767. var context = providerFiber.type._context;
  9768. {
  9769. push(valueCursor, context._currentValue, providerFiber);
  9770. context._currentValue = nextValue;
  9771. {
  9772. if (context._currentRenderer !== undefined && context._currentRenderer !== null && context._currentRenderer !== rendererSigil) {
  9773. error('Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.');
  9774. }
  9775. context._currentRenderer = rendererSigil;
  9776. }
  9777. }
  9778. }
  9779. function popProvider(providerFiber) {
  9780. var currentValue = valueCursor.current;
  9781. pop(valueCursor, providerFiber);
  9782. var context = providerFiber.type._context;
  9783. {
  9784. context._currentValue = currentValue;
  9785. }
  9786. }
  9787. function calculateChangedBits(context, newValue, oldValue) {
  9788. if (objectIs(oldValue, newValue)) {
  9789. // No change
  9790. return 0;
  9791. } else {
  9792. var changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT;
  9793. {
  9794. if ((changedBits & MAX_SIGNED_31_BIT_INT) !== changedBits) {
  9795. error('calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: %s', changedBits);
  9796. }
  9797. }
  9798. return changedBits | 0;
  9799. }
  9800. }
  9801. function scheduleWorkOnParentPath(parent, renderLanes) {
  9802. // Update the child lanes of all the ancestors, including the alternates.
  9803. var node = parent;
  9804. while (node !== null) {
  9805. var alternate = node.alternate;
  9806. if (!isSubsetOfLanes(node.childLanes, renderLanes)) {
  9807. node.childLanes = mergeLanes(node.childLanes, renderLanes);
  9808. if (alternate !== null) {
  9809. alternate.childLanes = mergeLanes(alternate.childLanes, renderLanes);
  9810. }
  9811. } else if (alternate !== null && !isSubsetOfLanes(alternate.childLanes, renderLanes)) {
  9812. alternate.childLanes = mergeLanes(alternate.childLanes, renderLanes);
  9813. } else {
  9814. // Neither alternate was updated, which means the rest of the
  9815. // ancestor path already has sufficient priority.
  9816. break;
  9817. }
  9818. node = node.return;
  9819. }
  9820. }
  9821. function propagateContextChange(workInProgress, context, changedBits, renderLanes) {
  9822. var fiber = workInProgress.child;
  9823. if (fiber !== null) {
  9824. // Set the return pointer of the child to the work-in-progress fiber.
  9825. fiber.return = workInProgress;
  9826. }
  9827. while (fiber !== null) {
  9828. var nextFiber = void 0; // Visit this fiber.
  9829. var list = fiber.dependencies;
  9830. if (list !== null) {
  9831. nextFiber = fiber.child;
  9832. var dependency = list.firstContext;
  9833. while (dependency !== null) {
  9834. // Check if the context matches.
  9835. if (dependency.context === context && (dependency.observedBits & changedBits) !== 0) {
  9836. // Match! Schedule an update on this fiber.
  9837. if (fiber.tag === ClassComponent) {
  9838. // Schedule a force update on the work-in-progress.
  9839. var update = createUpdate(NoTimestamp, pickArbitraryLane(renderLanes));
  9840. update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
  9841. // update to the current fiber, too, which means it will persist even if
  9842. // this render is thrown away. Since it's a race condition, not sure it's
  9843. // worth fixing.
  9844. enqueueUpdate(fiber, update);
  9845. }
  9846. fiber.lanes = mergeLanes(fiber.lanes, renderLanes);
  9847. var alternate = fiber.alternate;
  9848. if (alternate !== null) {
  9849. alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
  9850. }
  9851. scheduleWorkOnParentPath(fiber.return, renderLanes); // Mark the updated lanes on the list, too.
  9852. list.lanes = mergeLanes(list.lanes, renderLanes); // Since we already found a match, we can stop traversing the
  9853. // dependency list.
  9854. break;
  9855. }
  9856. dependency = dependency.next;
  9857. }
  9858. } else if (fiber.tag === ContextProvider) {
  9859. // Don't scan deeper if this is a matching provider
  9860. nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
  9861. } else {
  9862. // Traverse down.
  9863. nextFiber = fiber.child;
  9864. }
  9865. if (nextFiber !== null) {
  9866. // Set the return pointer of the child to the work-in-progress fiber.
  9867. nextFiber.return = fiber;
  9868. } else {
  9869. // No child. Traverse to next sibling.
  9870. nextFiber = fiber;
  9871. while (nextFiber !== null) {
  9872. if (nextFiber === workInProgress) {
  9873. // We're back to the root of this subtree. Exit.
  9874. nextFiber = null;
  9875. break;
  9876. }
  9877. var sibling = nextFiber.sibling;
  9878. if (sibling !== null) {
  9879. // Set the return pointer of the sibling to the work-in-progress fiber.
  9880. sibling.return = nextFiber.return;
  9881. nextFiber = sibling;
  9882. break;
  9883. } // No more siblings. Traverse up.
  9884. nextFiber = nextFiber.return;
  9885. }
  9886. }
  9887. fiber = nextFiber;
  9888. }
  9889. }
  9890. function prepareToReadContext(workInProgress, renderLanes) {
  9891. currentlyRenderingFiber = workInProgress;
  9892. lastContextDependency = null;
  9893. lastContextWithAllBitsObserved = null;
  9894. var dependencies = workInProgress.dependencies;
  9895. if (dependencies !== null) {
  9896. var firstContext = dependencies.firstContext;
  9897. if (firstContext !== null) {
  9898. if (includesSomeLane(dependencies.lanes, renderLanes)) {
  9899. // Context list has a pending update. Mark that this fiber performed work.
  9900. markWorkInProgressReceivedUpdate();
  9901. } // Reset the work-in-progress list
  9902. dependencies.firstContext = null;
  9903. }
  9904. }
  9905. }
  9906. function readContext(context, observedBits) {
  9907. {
  9908. // This warning would fire if you read context inside a Hook like useMemo.
  9909. // Unlike the class check below, it's not enforced in production for perf.
  9910. if (isDisallowedContextReadInDEV) {
  9911. error('Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().');
  9912. }
  9913. }
  9914. if (lastContextWithAllBitsObserved === context) ; else if (observedBits === false || observedBits === 0) ; else {
  9915. var resolvedObservedBits; // Avoid deopting on observable arguments or heterogeneous types.
  9916. if (typeof observedBits !== 'number' || observedBits === MAX_SIGNED_31_BIT_INT) {
  9917. // Observe all updates.
  9918. lastContextWithAllBitsObserved = context;
  9919. resolvedObservedBits = MAX_SIGNED_31_BIT_INT;
  9920. } else {
  9921. resolvedObservedBits = observedBits;
  9922. }
  9923. var contextItem = {
  9924. context: context,
  9925. observedBits: resolvedObservedBits,
  9926. next: null
  9927. };
  9928. if (lastContextDependency === null) {
  9929. if (!(currentlyRenderingFiber !== null)) {
  9930. {
  9931. throw Error( "Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo()." );
  9932. }
  9933. } // This is the first dependency for this component. Create a new list.
  9934. lastContextDependency = contextItem;
  9935. currentlyRenderingFiber.dependencies = {
  9936. lanes: NoLanes,
  9937. firstContext: contextItem,
  9938. responders: null
  9939. };
  9940. } else {
  9941. // Append a new context item.
  9942. lastContextDependency = lastContextDependency.next = contextItem;
  9943. }
  9944. }
  9945. return context._currentValue ;
  9946. }
  9947. var UpdateState = 0;
  9948. var ReplaceState = 1;
  9949. var ForceUpdate = 2;
  9950. var CaptureUpdate = 3; // Global state that is reset at the beginning of calling `processUpdateQueue`.
  9951. // It should only be read right after calling `processUpdateQueue`, via
  9952. // `checkHasForceUpdateAfterProcessing`.
  9953. var hasForceUpdate = false;
  9954. var didWarnUpdateInsideUpdate;
  9955. var currentlyProcessingQueue;
  9956. {
  9957. didWarnUpdateInsideUpdate = false;
  9958. currentlyProcessingQueue = null;
  9959. }
  9960. function initializeUpdateQueue(fiber) {
  9961. var queue = {
  9962. baseState: fiber.memoizedState,
  9963. firstBaseUpdate: null,
  9964. lastBaseUpdate: null,
  9965. shared: {
  9966. pending: null
  9967. },
  9968. effects: null
  9969. };
  9970. fiber.updateQueue = queue;
  9971. }
  9972. function cloneUpdateQueue(current, workInProgress) {
  9973. // Clone the update queue from current. Unless it's already a clone.
  9974. var queue = workInProgress.updateQueue;
  9975. var currentQueue = current.updateQueue;
  9976. if (queue === currentQueue) {
  9977. var clone = {
  9978. baseState: currentQueue.baseState,
  9979. firstBaseUpdate: currentQueue.firstBaseUpdate,
  9980. lastBaseUpdate: currentQueue.lastBaseUpdate,
  9981. shared: currentQueue.shared,
  9982. effects: currentQueue.effects
  9983. };
  9984. workInProgress.updateQueue = clone;
  9985. }
  9986. }
  9987. function createUpdate(eventTime, lane) {
  9988. var update = {
  9989. eventTime: eventTime,
  9990. lane: lane,
  9991. tag: UpdateState,
  9992. payload: null,
  9993. callback: null,
  9994. next: null
  9995. };
  9996. return update;
  9997. }
  9998. function enqueueUpdate(fiber, update) {
  9999. var updateQueue = fiber.updateQueue;
  10000. if (updateQueue === null) {
  10001. // Only occurs if the fiber has been unmounted.
  10002. return;
  10003. }
  10004. var sharedQueue = updateQueue.shared;
  10005. var pending = sharedQueue.pending;
  10006. if (pending === null) {
  10007. // This is the first update. Create a circular list.
  10008. update.next = update;
  10009. } else {
  10010. update.next = pending.next;
  10011. pending.next = update;
  10012. }
  10013. sharedQueue.pending = update;
  10014. {
  10015. if (currentlyProcessingQueue === sharedQueue && !didWarnUpdateInsideUpdate) {
  10016. error('An update (setState, replaceState, or forceUpdate) was scheduled ' + 'from inside an update function. Update functions should be pure, ' + 'with zero side-effects. Consider using componentDidUpdate or a ' + 'callback.');
  10017. didWarnUpdateInsideUpdate = true;
  10018. }
  10019. }
  10020. }
  10021. function enqueueCapturedUpdate(workInProgress, capturedUpdate) {
  10022. // Captured updates are updates that are thrown by a child during the render
  10023. // phase. They should be discarded if the render is aborted. Therefore,
  10024. // we should only put them on the work-in-progress queue, not the current one.
  10025. var queue = workInProgress.updateQueue; // Check if the work-in-progress queue is a clone.
  10026. var current = workInProgress.alternate;
  10027. if (current !== null) {
  10028. var currentQueue = current.updateQueue;
  10029. if (queue === currentQueue) {
  10030. // The work-in-progress queue is the same as current. This happens when
  10031. // we bail out on a parent fiber that then captures an error thrown by
  10032. // a child. Since we want to append the update only to the work-in
  10033. // -progress queue, we need to clone the updates. We usually clone during
  10034. // processUpdateQueue, but that didn't happen in this case because we
  10035. // skipped over the parent when we bailed out.
  10036. var newFirst = null;
  10037. var newLast = null;
  10038. var firstBaseUpdate = queue.firstBaseUpdate;
  10039. if (firstBaseUpdate !== null) {
  10040. // Loop through the updates and clone them.
  10041. var update = firstBaseUpdate;
  10042. do {
  10043. var clone = {
  10044. eventTime: update.eventTime,
  10045. lane: update.lane,
  10046. tag: update.tag,
  10047. payload: update.payload,
  10048. callback: update.callback,
  10049. next: null
  10050. };
  10051. if (newLast === null) {
  10052. newFirst = newLast = clone;
  10053. } else {
  10054. newLast.next = clone;
  10055. newLast = clone;
  10056. }
  10057. update = update.next;
  10058. } while (update !== null); // Append the captured update the end of the cloned list.
  10059. if (newLast === null) {
  10060. newFirst = newLast = capturedUpdate;
  10061. } else {
  10062. newLast.next = capturedUpdate;
  10063. newLast = capturedUpdate;
  10064. }
  10065. } else {
  10066. // There are no base updates.
  10067. newFirst = newLast = capturedUpdate;
  10068. }
  10069. queue = {
  10070. baseState: currentQueue.baseState,
  10071. firstBaseUpdate: newFirst,
  10072. lastBaseUpdate: newLast,
  10073. shared: currentQueue.shared,
  10074. effects: currentQueue.effects
  10075. };
  10076. workInProgress.updateQueue = queue;
  10077. return;
  10078. }
  10079. } // Append the update to the end of the list.
  10080. var lastBaseUpdate = queue.lastBaseUpdate;
  10081. if (lastBaseUpdate === null) {
  10082. queue.firstBaseUpdate = capturedUpdate;
  10083. } else {
  10084. lastBaseUpdate.next = capturedUpdate;
  10085. }
  10086. queue.lastBaseUpdate = capturedUpdate;
  10087. }
  10088. function getStateFromUpdate(workInProgress, queue, update, prevState, nextProps, instance) {
  10089. switch (update.tag) {
  10090. case ReplaceState:
  10091. {
  10092. var payload = update.payload;
  10093. if (typeof payload === 'function') {
  10094. // Updater function
  10095. {
  10096. enterDisallowedContextReadInDEV();
  10097. }
  10098. var nextState = payload.call(instance, prevState, nextProps);
  10099. {
  10100. if ( workInProgress.mode & StrictMode) {
  10101. disableLogs();
  10102. try {
  10103. payload.call(instance, prevState, nextProps);
  10104. } finally {
  10105. reenableLogs();
  10106. }
  10107. }
  10108. exitDisallowedContextReadInDEV();
  10109. }
  10110. return nextState;
  10111. } // State object
  10112. return payload;
  10113. }
  10114. case CaptureUpdate:
  10115. {
  10116. workInProgress.flags = workInProgress.flags & ~ShouldCapture | DidCapture;
  10117. }
  10118. // Intentional fallthrough
  10119. case UpdateState:
  10120. {
  10121. var _payload = update.payload;
  10122. var partialState;
  10123. if (typeof _payload === 'function') {
  10124. // Updater function
  10125. {
  10126. enterDisallowedContextReadInDEV();
  10127. }
  10128. partialState = _payload.call(instance, prevState, nextProps);
  10129. {
  10130. if ( workInProgress.mode & StrictMode) {
  10131. disableLogs();
  10132. try {
  10133. _payload.call(instance, prevState, nextProps);
  10134. } finally {
  10135. reenableLogs();
  10136. }
  10137. }
  10138. exitDisallowedContextReadInDEV();
  10139. }
  10140. } else {
  10141. // Partial state object
  10142. partialState = _payload;
  10143. }
  10144. if (partialState === null || partialState === undefined) {
  10145. // Null and undefined are treated as no-ops.
  10146. return prevState;
  10147. } // Merge the partial state and the previous state.
  10148. return _assign({}, prevState, partialState);
  10149. }
  10150. case ForceUpdate:
  10151. {
  10152. hasForceUpdate = true;
  10153. return prevState;
  10154. }
  10155. }
  10156. return prevState;
  10157. }
  10158. function processUpdateQueue(workInProgress, props, instance, renderLanes) {
  10159. // This is always non-null on a ClassComponent or HostRoot
  10160. var queue = workInProgress.updateQueue;
  10161. hasForceUpdate = false;
  10162. {
  10163. currentlyProcessingQueue = queue.shared;
  10164. }
  10165. var firstBaseUpdate = queue.firstBaseUpdate;
  10166. var lastBaseUpdate = queue.lastBaseUpdate; // Check if there are pending updates. If so, transfer them to the base queue.
  10167. var pendingQueue = queue.shared.pending;
  10168. if (pendingQueue !== null) {
  10169. queue.shared.pending = null; // The pending queue is circular. Disconnect the pointer between first
  10170. // and last so that it's non-circular.
  10171. var lastPendingUpdate = pendingQueue;
  10172. var firstPendingUpdate = lastPendingUpdate.next;
  10173. lastPendingUpdate.next = null; // Append pending updates to base queue
  10174. if (lastBaseUpdate === null) {
  10175. firstBaseUpdate = firstPendingUpdate;
  10176. } else {
  10177. lastBaseUpdate.next = firstPendingUpdate;
  10178. }
  10179. lastBaseUpdate = lastPendingUpdate; // If there's a current queue, and it's different from the base queue, then
  10180. // we need to transfer the updates to that queue, too. Because the base
  10181. // queue is a singly-linked list with no cycles, we can append to both
  10182. // lists and take advantage of structural sharing.
  10183. // TODO: Pass `current` as argument
  10184. var current = workInProgress.alternate;
  10185. if (current !== null) {
  10186. // This is always non-null on a ClassComponent or HostRoot
  10187. var currentQueue = current.updateQueue;
  10188. var currentLastBaseUpdate = currentQueue.lastBaseUpdate;
  10189. if (currentLastBaseUpdate !== lastBaseUpdate) {
  10190. if (currentLastBaseUpdate === null) {
  10191. currentQueue.firstBaseUpdate = firstPendingUpdate;
  10192. } else {
  10193. currentLastBaseUpdate.next = firstPendingUpdate;
  10194. }
  10195. currentQueue.lastBaseUpdate = lastPendingUpdate;
  10196. }
  10197. }
  10198. } // These values may change as we process the queue.
  10199. if (firstBaseUpdate !== null) {
  10200. // Iterate through the list of updates to compute the result.
  10201. var newState = queue.baseState; // TODO: Don't need to accumulate this. Instead, we can remove renderLanes
  10202. // from the original lanes.
  10203. var newLanes = NoLanes;
  10204. var newBaseState = null;
  10205. var newFirstBaseUpdate = null;
  10206. var newLastBaseUpdate = null;
  10207. var update = firstBaseUpdate;
  10208. do {
  10209. var updateLane = update.lane;
  10210. var updateEventTime = update.eventTime;
  10211. if (!isSubsetOfLanes(renderLanes, updateLane)) {
  10212. // Priority is insufficient. Skip this update. If this is the first
  10213. // skipped update, the previous update/state is the new base
  10214. // update/state.
  10215. var clone = {
  10216. eventTime: updateEventTime,
  10217. lane: updateLane,
  10218. tag: update.tag,
  10219. payload: update.payload,
  10220. callback: update.callback,
  10221. next: null
  10222. };
  10223. if (newLastBaseUpdate === null) {
  10224. newFirstBaseUpdate = newLastBaseUpdate = clone;
  10225. newBaseState = newState;
  10226. } else {
  10227. newLastBaseUpdate = newLastBaseUpdate.next = clone;
  10228. } // Update the remaining priority in the queue.
  10229. newLanes = mergeLanes(newLanes, updateLane);
  10230. } else {
  10231. // This update does have sufficient priority.
  10232. if (newLastBaseUpdate !== null) {
  10233. var _clone = {
  10234. eventTime: updateEventTime,
  10235. // This update is going to be committed so we never want uncommit
  10236. // it. Using NoLane works because 0 is a subset of all bitmasks, so
  10237. // this will never be skipped by the check above.
  10238. lane: NoLane,
  10239. tag: update.tag,
  10240. payload: update.payload,
  10241. callback: update.callback,
  10242. next: null
  10243. };
  10244. newLastBaseUpdate = newLastBaseUpdate.next = _clone;
  10245. } // Process this update.
  10246. newState = getStateFromUpdate(workInProgress, queue, update, newState, props, instance);
  10247. var callback = update.callback;
  10248. if (callback !== null) {
  10249. workInProgress.flags |= Callback;
  10250. var effects = queue.effects;
  10251. if (effects === null) {
  10252. queue.effects = [update];
  10253. } else {
  10254. effects.push(update);
  10255. }
  10256. }
  10257. }
  10258. update = update.next;
  10259. if (update === null) {
  10260. pendingQueue = queue.shared.pending;
  10261. if (pendingQueue === null) {
  10262. break;
  10263. } else {
  10264. // An update was scheduled from inside a reducer. Add the new
  10265. // pending updates to the end of the list and keep processing.
  10266. var _lastPendingUpdate = pendingQueue; // Intentionally unsound. Pending updates form a circular list, but we
  10267. // unravel them when transferring them to the base queue.
  10268. var _firstPendingUpdate = _lastPendingUpdate.next;
  10269. _lastPendingUpdate.next = null;
  10270. update = _firstPendingUpdate;
  10271. queue.lastBaseUpdate = _lastPendingUpdate;
  10272. queue.shared.pending = null;
  10273. }
  10274. }
  10275. } while (true);
  10276. if (newLastBaseUpdate === null) {
  10277. newBaseState = newState;
  10278. }
  10279. queue.baseState = newBaseState;
  10280. queue.firstBaseUpdate = newFirstBaseUpdate;
  10281. queue.lastBaseUpdate = newLastBaseUpdate; // Set the remaining expiration time to be whatever is remaining in the queue.
  10282. // This should be fine because the only two other things that contribute to
  10283. // expiration time are props and context. We're already in the middle of the
  10284. // begin phase by the time we start processing the queue, so we've already
  10285. // dealt with the props. Context in components that specify
  10286. // shouldComponentUpdate is tricky; but we'll have to account for
  10287. // that regardless.
  10288. markSkippedUpdateLanes(newLanes);
  10289. workInProgress.lanes = newLanes;
  10290. workInProgress.memoizedState = newState;
  10291. }
  10292. {
  10293. currentlyProcessingQueue = null;
  10294. }
  10295. }
  10296. function callCallback(callback, context) {
  10297. if (!(typeof callback === 'function')) {
  10298. {
  10299. throw Error( "Invalid argument passed as callback. Expected a function. Instead received: " + callback );
  10300. }
  10301. }
  10302. callback.call(context);
  10303. }
  10304. function resetHasForceUpdateBeforeProcessing() {
  10305. hasForceUpdate = false;
  10306. }
  10307. function checkHasForceUpdateAfterProcessing() {
  10308. return hasForceUpdate;
  10309. }
  10310. function commitUpdateQueue(finishedWork, finishedQueue, instance) {
  10311. // Commit the effects
  10312. var effects = finishedQueue.effects;
  10313. finishedQueue.effects = null;
  10314. if (effects !== null) {
  10315. for (var i = 0; i < effects.length; i++) {
  10316. var effect = effects[i];
  10317. var callback = effect.callback;
  10318. if (callback !== null) {
  10319. effect.callback = null;
  10320. callCallback(callback, instance);
  10321. }
  10322. }
  10323. }
  10324. }
  10325. var fakeInternalInstance = {};
  10326. var isArray = Array.isArray; // React.Component uses a shared frozen object by default.
  10327. // We'll use it to determine whether we need to initialize legacy refs.
  10328. var emptyRefsObject = new React.Component().refs;
  10329. var didWarnAboutStateAssignmentForComponent;
  10330. var didWarnAboutUninitializedState;
  10331. var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
  10332. var didWarnAboutLegacyLifecyclesAndDerivedState;
  10333. var didWarnAboutUndefinedDerivedState;
  10334. var warnOnUndefinedDerivedState;
  10335. var warnOnInvalidCallback;
  10336. var didWarnAboutDirectlyAssigningPropsToState;
  10337. var didWarnAboutContextTypeAndContextTypes;
  10338. var didWarnAboutInvalidateContextType;
  10339. {
  10340. didWarnAboutStateAssignmentForComponent = new Set();
  10341. didWarnAboutUninitializedState = new Set();
  10342. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
  10343. didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
  10344. didWarnAboutDirectlyAssigningPropsToState = new Set();
  10345. didWarnAboutUndefinedDerivedState = new Set();
  10346. didWarnAboutContextTypeAndContextTypes = new Set();
  10347. didWarnAboutInvalidateContextType = new Set();
  10348. var didWarnOnInvalidCallback = new Set();
  10349. warnOnInvalidCallback = function (callback, callerName) {
  10350. if (callback === null || typeof callback === 'function') {
  10351. return;
  10352. }
  10353. var key = callerName + '_' + callback;
  10354. if (!didWarnOnInvalidCallback.has(key)) {
  10355. didWarnOnInvalidCallback.add(key);
  10356. error('%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
  10357. }
  10358. };
  10359. warnOnUndefinedDerivedState = function (type, partialState) {
  10360. if (partialState === undefined) {
  10361. var componentName = getComponentName(type) || 'Component';
  10362. if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
  10363. didWarnAboutUndefinedDerivedState.add(componentName);
  10364. error('%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
  10365. }
  10366. }
  10367. }; // This is so gross but it's at least non-critical and can be removed if
  10368. // it causes problems. This is meant to give a nicer error message for
  10369. // ReactDOM15.unstable_renderSubtreeIntoContainer(reactDOM16Component,
  10370. // ...)) which otherwise throws a "_processChildContext is not a function"
  10371. // exception.
  10372. Object.defineProperty(fakeInternalInstance, '_processChildContext', {
  10373. enumerable: false,
  10374. value: function () {
  10375. {
  10376. {
  10377. throw Error( "_processChildContext is not available in React 16+. This likely means you have multiple copies of React and are attempting to nest a React 15 tree inside a React 16 tree using unstable_renderSubtreeIntoContainer, which isn't supported. Try to make sure you have only one copy of React (and ideally, switch to ReactDOM.createPortal)." );
  10378. }
  10379. }
  10380. }
  10381. });
  10382. Object.freeze(fakeInternalInstance);
  10383. }
  10384. function applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, nextProps) {
  10385. var prevState = workInProgress.memoizedState;
  10386. {
  10387. if ( workInProgress.mode & StrictMode) {
  10388. disableLogs();
  10389. try {
  10390. // Invoke the function an extra time to help detect side-effects.
  10391. getDerivedStateFromProps(nextProps, prevState);
  10392. } finally {
  10393. reenableLogs();
  10394. }
  10395. }
  10396. }
  10397. var partialState = getDerivedStateFromProps(nextProps, prevState);
  10398. {
  10399. warnOnUndefinedDerivedState(ctor, partialState);
  10400. } // Merge the partial state and the previous state.
  10401. var memoizedState = partialState === null || partialState === undefined ? prevState : _assign({}, prevState, partialState);
  10402. workInProgress.memoizedState = memoizedState; // Once the update queue is empty, persist the derived state onto the
  10403. // base state.
  10404. if (workInProgress.lanes === NoLanes) {
  10405. // Queue is always non-null for classes
  10406. var updateQueue = workInProgress.updateQueue;
  10407. updateQueue.baseState = memoizedState;
  10408. }
  10409. }
  10410. var classComponentUpdater = {
  10411. isMounted: isMounted,
  10412. enqueueSetState: function (inst, payload, callback) {
  10413. var fiber = get(inst);
  10414. var eventTime = requestEventTime();
  10415. var lane = requestUpdateLane(fiber);
  10416. var update = createUpdate(eventTime, lane);
  10417. update.payload = payload;
  10418. if (callback !== undefined && callback !== null) {
  10419. {
  10420. warnOnInvalidCallback(callback, 'setState');
  10421. }
  10422. update.callback = callback;
  10423. }
  10424. enqueueUpdate(fiber, update);
  10425. scheduleUpdateOnFiber(fiber, lane, eventTime);
  10426. },
  10427. enqueueReplaceState: function (inst, payload, callback) {
  10428. var fiber = get(inst);
  10429. var eventTime = requestEventTime();
  10430. var lane = requestUpdateLane(fiber);
  10431. var update = createUpdate(eventTime, lane);
  10432. update.tag = ReplaceState;
  10433. update.payload = payload;
  10434. if (callback !== undefined && callback !== null) {
  10435. {
  10436. warnOnInvalidCallback(callback, 'replaceState');
  10437. }
  10438. update.callback = callback;
  10439. }
  10440. enqueueUpdate(fiber, update);
  10441. scheduleUpdateOnFiber(fiber, lane, eventTime);
  10442. },
  10443. enqueueForceUpdate: function (inst, callback) {
  10444. var fiber = get(inst);
  10445. var eventTime = requestEventTime();
  10446. var lane = requestUpdateLane(fiber);
  10447. var update = createUpdate(eventTime, lane);
  10448. update.tag = ForceUpdate;
  10449. if (callback !== undefined && callback !== null) {
  10450. {
  10451. warnOnInvalidCallback(callback, 'forceUpdate');
  10452. }
  10453. update.callback = callback;
  10454. }
  10455. enqueueUpdate(fiber, update);
  10456. scheduleUpdateOnFiber(fiber, lane, eventTime);
  10457. }
  10458. };
  10459. function checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext) {
  10460. var instance = workInProgress.stateNode;
  10461. if (typeof instance.shouldComponentUpdate === 'function') {
  10462. {
  10463. if ( workInProgress.mode & StrictMode) {
  10464. disableLogs();
  10465. try {
  10466. // Invoke the function an extra time to help detect side-effects.
  10467. instance.shouldComponentUpdate(newProps, newState, nextContext);
  10468. } finally {
  10469. reenableLogs();
  10470. }
  10471. }
  10472. }
  10473. var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, nextContext);
  10474. {
  10475. if (shouldUpdate === undefined) {
  10476. error('%s.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', getComponentName(ctor) || 'Component');
  10477. }
  10478. }
  10479. return shouldUpdate;
  10480. }
  10481. if (ctor.prototype && ctor.prototype.isPureReactComponent) {
  10482. return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
  10483. }
  10484. return true;
  10485. }
  10486. function checkClassInstance(workInProgress, ctor, newProps) {
  10487. var instance = workInProgress.stateNode;
  10488. {
  10489. var name = getComponentName(ctor) || 'Component';
  10490. var renderPresent = instance.render;
  10491. if (!renderPresent) {
  10492. if (ctor.prototype && typeof ctor.prototype.render === 'function') {
  10493. error('%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
  10494. } else {
  10495. error('%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
  10496. }
  10497. }
  10498. if (instance.getInitialState && !instance.getInitialState.isReactClassApproved && !instance.state) {
  10499. error('getInitialState was defined on %s, a plain JavaScript class. ' + 'This is only supported for classes created using React.createClass. ' + 'Did you mean to define a state property instead?', name);
  10500. }
  10501. if (instance.getDefaultProps && !instance.getDefaultProps.isReactClassApproved) {
  10502. error('getDefaultProps was defined on %s, a plain JavaScript class. ' + 'This is only supported for classes created using React.createClass. ' + 'Use a static property to define defaultProps instead.', name);
  10503. }
  10504. if (instance.propTypes) {
  10505. error('propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name);
  10506. }
  10507. if (instance.contextType) {
  10508. error('contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name);
  10509. }
  10510. {
  10511. if (instance.contextTypes) {
  10512. error('contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name);
  10513. }
  10514. if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
  10515. didWarnAboutContextTypeAndContextTypes.add(ctor);
  10516. error('%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
  10517. }
  10518. }
  10519. if (typeof instance.componentShouldUpdate === 'function') {
  10520. error('%s has a method called ' + 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' + 'The name is phrased as a question because the function is ' + 'expected to return a value.', name);
  10521. }
  10522. if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
  10523. error('%s has a method called shouldComponentUpdate(). ' + 'shouldComponentUpdate should not be used when extending React.PureComponent. ' + 'Please extend React.Component if shouldComponentUpdate is used.', getComponentName(ctor) || 'A pure component');
  10524. }
  10525. if (typeof instance.componentDidUnmount === 'function') {
  10526. error('%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name);
  10527. }
  10528. if (typeof instance.componentDidReceiveProps === 'function') {
  10529. error('%s has a method called ' + 'componentDidReceiveProps(). But there is no such lifecycle method. ' + 'If you meant to update the state in response to changing props, ' + 'use componentWillReceiveProps(). If you meant to fetch data or ' + 'run side-effects or mutations after React has updated the UI, use componentDidUpdate().', name);
  10530. }
  10531. if (typeof instance.componentWillRecieveProps === 'function') {
  10532. error('%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name);
  10533. }
  10534. if (typeof instance.UNSAFE_componentWillRecieveProps === 'function') {
  10535. error('%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name);
  10536. }
  10537. var hasMutatedProps = instance.props !== newProps;
  10538. if (instance.props !== undefined && hasMutatedProps) {
  10539. error('%s(...): When calling super() in `%s`, make sure to pass ' + "up the same props that your component's constructor was passed.", name, name);
  10540. }
  10541. if (instance.defaultProps) {
  10542. error('Setting defaultProps as an instance property on %s is not supported and will be ignored.' + ' Instead, define defaultProps as a static property on %s.', name, name);
  10543. }
  10544. if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
  10545. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
  10546. error('%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentName(ctor));
  10547. }
  10548. if (typeof instance.getDerivedStateFromProps === 'function') {
  10549. error('%s: getDerivedStateFromProps() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name);
  10550. }
  10551. if (typeof instance.getDerivedStateFromError === 'function') {
  10552. error('%s: getDerivedStateFromError() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name);
  10553. }
  10554. if (typeof ctor.getSnapshotBeforeUpdate === 'function') {
  10555. error('%s: getSnapshotBeforeUpdate() is defined as a static method ' + 'and will be ignored. Instead, declare it as an instance method.', name);
  10556. }
  10557. var _state = instance.state;
  10558. if (_state && (typeof _state !== 'object' || isArray(_state))) {
  10559. error('%s.state: must be set to an object or null', name);
  10560. }
  10561. if (typeof instance.getChildContext === 'function' && typeof ctor.childContextTypes !== 'object') {
  10562. error('%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name);
  10563. }
  10564. }
  10565. }
  10566. function adoptClassInstance(workInProgress, instance) {
  10567. instance.updater = classComponentUpdater;
  10568. workInProgress.stateNode = instance; // The instance needs access to the fiber so that it can schedule updates
  10569. set(instance, workInProgress);
  10570. {
  10571. instance._reactInternalInstance = fakeInternalInstance;
  10572. }
  10573. }
  10574. function constructClassInstance(workInProgress, ctor, props) {
  10575. var isLegacyContextConsumer = false;
  10576. var unmaskedContext = emptyContextObject;
  10577. var context = emptyContextObject;
  10578. var contextType = ctor.contextType;
  10579. {
  10580. if ('contextType' in ctor) {
  10581. var isValid = // Allow null for conditional declaration
  10582. contextType === null || contextType !== undefined && contextType.$$typeof === REACT_CONTEXT_TYPE && contextType._context === undefined; // Not a <Context.Consumer>
  10583. if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
  10584. didWarnAboutInvalidateContextType.add(ctor);
  10585. var addendum = '';
  10586. if (contextType === undefined) {
  10587. addendum = ' However, it is set to undefined. ' + 'This can be caused by a typo or by mixing up named and default imports. ' + 'This can also happen due to a circular dependency, so ' + 'try moving the createContext() call to a separate file.';
  10588. } else if (typeof contextType !== 'object') {
  10589. addendum = ' However, it is set to a ' + typeof contextType + '.';
  10590. } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
  10591. addendum = ' Did you accidentally pass the Context.Provider instead?';
  10592. } else if (contextType._context !== undefined) {
  10593. // <Context.Consumer>
  10594. addendum = ' Did you accidentally pass the Context.Consumer instead?';
  10595. } else {
  10596. addendum = ' However, it is set to an object with keys {' + Object.keys(contextType).join(', ') + '}.';
  10597. }
  10598. error('%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentName(ctor) || 'Component', addendum);
  10599. }
  10600. }
  10601. }
  10602. if (typeof contextType === 'object' && contextType !== null) {
  10603. context = readContext(contextType);
  10604. } else {
  10605. unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  10606. var contextTypes = ctor.contextTypes;
  10607. isLegacyContextConsumer = contextTypes !== null && contextTypes !== undefined;
  10608. context = isLegacyContextConsumer ? getMaskedContext(workInProgress, unmaskedContext) : emptyContextObject;
  10609. } // Instantiate twice to help detect side-effects.
  10610. {
  10611. if ( workInProgress.mode & StrictMode) {
  10612. disableLogs();
  10613. try {
  10614. new ctor(props, context); // eslint-disable-line no-new
  10615. } finally {
  10616. reenableLogs();
  10617. }
  10618. }
  10619. }
  10620. var instance = new ctor(props, context);
  10621. var state = workInProgress.memoizedState = instance.state !== null && instance.state !== undefined ? instance.state : null;
  10622. adoptClassInstance(workInProgress, instance);
  10623. {
  10624. if (typeof ctor.getDerivedStateFromProps === 'function' && state === null) {
  10625. var componentName = getComponentName(ctor) || 'Component';
  10626. if (!didWarnAboutUninitializedState.has(componentName)) {
  10627. didWarnAboutUninitializedState.add(componentName);
  10628. error('`%s` uses `getDerivedStateFromProps` but its initial state is ' + '%s. This is not recommended. Instead, define the initial state by ' + 'assigning an object to `this.state` in the constructor of `%s`. ' + 'This ensures that `getDerivedStateFromProps` arguments have a consistent shape.', componentName, instance.state === null ? 'null' : 'undefined', componentName);
  10629. }
  10630. } // If new component APIs are defined, "unsafe" lifecycles won't be called.
  10631. // Warn about these lifecycles if they are present.
  10632. // Don't warn about react-lifecycles-compat polyfilled methods though.
  10633. if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
  10634. var foundWillMountName = null;
  10635. var foundWillReceivePropsName = null;
  10636. var foundWillUpdateName = null;
  10637. if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
  10638. foundWillMountName = 'componentWillMount';
  10639. } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
  10640. foundWillMountName = 'UNSAFE_componentWillMount';
  10641. }
  10642. if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
  10643. foundWillReceivePropsName = 'componentWillReceiveProps';
  10644. } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  10645. foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
  10646. }
  10647. if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
  10648. foundWillUpdateName = 'componentWillUpdate';
  10649. } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
  10650. foundWillUpdateName = 'UNSAFE_componentWillUpdate';
  10651. }
  10652. if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
  10653. var _componentName = getComponentName(ctor) || 'Component';
  10654. var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
  10655. if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
  10656. didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
  10657. error('Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' + '%s uses %s but also contains the following legacy lifecycles:%s%s%s\n\n' + 'The above lifecycles should be removed. Learn more about this warning here:\n' + 'https://reactjs.org/link/unsafe-component-lifecycles', _componentName, newApiName, foundWillMountName !== null ? "\n " + foundWillMountName : '', foundWillReceivePropsName !== null ? "\n " + foundWillReceivePropsName : '', foundWillUpdateName !== null ? "\n " + foundWillUpdateName : '');
  10658. }
  10659. }
  10660. }
  10661. } // Cache unmasked context so we can avoid recreating masked context unless necessary.
  10662. // ReactFiberContext usually updates this cache but can't for newly-created instances.
  10663. if (isLegacyContextConsumer) {
  10664. cacheContext(workInProgress, unmaskedContext, context);
  10665. }
  10666. return instance;
  10667. }
  10668. function callComponentWillMount(workInProgress, instance) {
  10669. var oldState = instance.state;
  10670. if (typeof instance.componentWillMount === 'function') {
  10671. instance.componentWillMount();
  10672. }
  10673. if (typeof instance.UNSAFE_componentWillMount === 'function') {
  10674. instance.UNSAFE_componentWillMount();
  10675. }
  10676. if (oldState !== instance.state) {
  10677. {
  10678. error('%s.componentWillMount(): Assigning directly to this.state is ' + "deprecated (except inside a component's " + 'constructor). Use setState instead.', getComponentName(workInProgress.type) || 'Component');
  10679. }
  10680. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  10681. }
  10682. }
  10683. function callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext) {
  10684. var oldState = instance.state;
  10685. if (typeof instance.componentWillReceiveProps === 'function') {
  10686. instance.componentWillReceiveProps(newProps, nextContext);
  10687. }
  10688. if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  10689. instance.UNSAFE_componentWillReceiveProps(newProps, nextContext);
  10690. }
  10691. if (instance.state !== oldState) {
  10692. {
  10693. var componentName = getComponentName(workInProgress.type) || 'Component';
  10694. if (!didWarnAboutStateAssignmentForComponent.has(componentName)) {
  10695. didWarnAboutStateAssignmentForComponent.add(componentName);
  10696. error('%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', componentName);
  10697. }
  10698. }
  10699. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  10700. }
  10701. } // Invokes the mount life-cycles on a previously never rendered instance.
  10702. function mountClassInstance(workInProgress, ctor, newProps, renderLanes) {
  10703. {
  10704. checkClassInstance(workInProgress, ctor, newProps);
  10705. }
  10706. var instance = workInProgress.stateNode;
  10707. instance.props = newProps;
  10708. instance.state = workInProgress.memoizedState;
  10709. instance.refs = emptyRefsObject;
  10710. initializeUpdateQueue(workInProgress);
  10711. var contextType = ctor.contextType;
  10712. if (typeof contextType === 'object' && contextType !== null) {
  10713. instance.context = readContext(contextType);
  10714. } else {
  10715. var unmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  10716. instance.context = getMaskedContext(workInProgress, unmaskedContext);
  10717. }
  10718. {
  10719. if (instance.state === newProps) {
  10720. var componentName = getComponentName(ctor) || 'Component';
  10721. if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
  10722. didWarnAboutDirectlyAssigningPropsToState.add(componentName);
  10723. error('%s: It is not recommended to assign props directly to state ' + "because updates to props won't be reflected in state. " + 'In most cases, it is better to use props directly.', componentName);
  10724. }
  10725. }
  10726. if (workInProgress.mode & StrictMode) {
  10727. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, instance);
  10728. }
  10729. {
  10730. ReactStrictModeWarnings.recordUnsafeLifecycleWarnings(workInProgress, instance);
  10731. }
  10732. }
  10733. processUpdateQueue(workInProgress, newProps, instance, renderLanes);
  10734. instance.state = workInProgress.memoizedState;
  10735. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  10736. if (typeof getDerivedStateFromProps === 'function') {
  10737. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  10738. instance.state = workInProgress.memoizedState;
  10739. } // In order to support react-lifecycles-compat polyfilled components,
  10740. // Unsafe lifecycles should not be invoked for components using the new APIs.
  10741. if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
  10742. callComponentWillMount(workInProgress, instance); // If we had additional state updates during this life-cycle, let's
  10743. // process them now.
  10744. processUpdateQueue(workInProgress, newProps, instance, renderLanes);
  10745. instance.state = workInProgress.memoizedState;
  10746. }
  10747. if (typeof instance.componentDidMount === 'function') {
  10748. workInProgress.flags |= Update;
  10749. }
  10750. }
  10751. function resumeMountClassInstance(workInProgress, ctor, newProps, renderLanes) {
  10752. var instance = workInProgress.stateNode;
  10753. var oldProps = workInProgress.memoizedProps;
  10754. instance.props = oldProps;
  10755. var oldContext = instance.context;
  10756. var contextType = ctor.contextType;
  10757. var nextContext = emptyContextObject;
  10758. if (typeof contextType === 'object' && contextType !== null) {
  10759. nextContext = readContext(contextType);
  10760. } else {
  10761. var nextLegacyUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  10762. nextContext = getMaskedContext(workInProgress, nextLegacyUnmaskedContext);
  10763. }
  10764. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  10765. var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
  10766. // ever the previously attempted to render - not the "current". However,
  10767. // during componentDidUpdate we pass the "current" props.
  10768. // In order to support react-lifecycles-compat polyfilled components,
  10769. // Unsafe lifecycles should not be invoked for components using the new APIs.
  10770. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
  10771. if (oldProps !== newProps || oldContext !== nextContext) {
  10772. callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
  10773. }
  10774. }
  10775. resetHasForceUpdateBeforeProcessing();
  10776. var oldState = workInProgress.memoizedState;
  10777. var newState = instance.state = oldState;
  10778. processUpdateQueue(workInProgress, newProps, instance, renderLanes);
  10779. newState = workInProgress.memoizedState;
  10780. if (oldProps === newProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
  10781. // If an update was already in progress, we should schedule an Update
  10782. // effect even though we're bailing out, so that cWU/cDU are called.
  10783. if (typeof instance.componentDidMount === 'function') {
  10784. workInProgress.flags |= Update;
  10785. }
  10786. return false;
  10787. }
  10788. if (typeof getDerivedStateFromProps === 'function') {
  10789. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  10790. newState = workInProgress.memoizedState;
  10791. }
  10792. var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
  10793. if (shouldUpdate) {
  10794. // In order to support react-lifecycles-compat polyfilled components,
  10795. // Unsafe lifecycles should not be invoked for components using the new APIs.
  10796. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
  10797. if (typeof instance.componentWillMount === 'function') {
  10798. instance.componentWillMount();
  10799. }
  10800. if (typeof instance.UNSAFE_componentWillMount === 'function') {
  10801. instance.UNSAFE_componentWillMount();
  10802. }
  10803. }
  10804. if (typeof instance.componentDidMount === 'function') {
  10805. workInProgress.flags |= Update;
  10806. }
  10807. } else {
  10808. // If an update was already in progress, we should schedule an Update
  10809. // effect even though we're bailing out, so that cWU/cDU are called.
  10810. if (typeof instance.componentDidMount === 'function') {
  10811. workInProgress.flags |= Update;
  10812. } // If shouldComponentUpdate returned false, we should still update the
  10813. // memoized state to indicate that this work can be reused.
  10814. workInProgress.memoizedProps = newProps;
  10815. workInProgress.memoizedState = newState;
  10816. } // Update the existing instance's state, props, and context pointers even
  10817. // if shouldComponentUpdate returns false.
  10818. instance.props = newProps;
  10819. instance.state = newState;
  10820. instance.context = nextContext;
  10821. return shouldUpdate;
  10822. } // Invokes the update life-cycles and returns false if it shouldn't rerender.
  10823. function updateClassInstance(current, workInProgress, ctor, newProps, renderLanes) {
  10824. var instance = workInProgress.stateNode;
  10825. cloneUpdateQueue(current, workInProgress);
  10826. var unresolvedOldProps = workInProgress.memoizedProps;
  10827. var oldProps = workInProgress.type === workInProgress.elementType ? unresolvedOldProps : resolveDefaultProps(workInProgress.type, unresolvedOldProps);
  10828. instance.props = oldProps;
  10829. var unresolvedNewProps = workInProgress.pendingProps;
  10830. var oldContext = instance.context;
  10831. var contextType = ctor.contextType;
  10832. var nextContext = emptyContextObject;
  10833. if (typeof contextType === 'object' && contextType !== null) {
  10834. nextContext = readContext(contextType);
  10835. } else {
  10836. var nextUnmaskedContext = getUnmaskedContext(workInProgress, ctor, true);
  10837. nextContext = getMaskedContext(workInProgress, nextUnmaskedContext);
  10838. }
  10839. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  10840. var hasNewLifecycles = typeof getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function'; // Note: During these life-cycles, instance.props/instance.state are what
  10841. // ever the previously attempted to render - not the "current". However,
  10842. // during componentDidUpdate we pass the "current" props.
  10843. // In order to support react-lifecycles-compat polyfilled components,
  10844. // Unsafe lifecycles should not be invoked for components using the new APIs.
  10845. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillReceiveProps === 'function' || typeof instance.componentWillReceiveProps === 'function')) {
  10846. if (unresolvedOldProps !== unresolvedNewProps || oldContext !== nextContext) {
  10847. callComponentWillReceiveProps(workInProgress, instance, newProps, nextContext);
  10848. }
  10849. }
  10850. resetHasForceUpdateBeforeProcessing();
  10851. var oldState = workInProgress.memoizedState;
  10852. var newState = instance.state = oldState;
  10853. processUpdateQueue(workInProgress, newProps, instance, renderLanes);
  10854. newState = workInProgress.memoizedState;
  10855. if (unresolvedOldProps === unresolvedNewProps && oldState === newState && !hasContextChanged() && !checkHasForceUpdateAfterProcessing()) {
  10856. // If an update was already in progress, we should schedule an Update
  10857. // effect even though we're bailing out, so that cWU/cDU are called.
  10858. if (typeof instance.componentDidUpdate === 'function') {
  10859. if (unresolvedOldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  10860. workInProgress.flags |= Update;
  10861. }
  10862. }
  10863. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  10864. if (unresolvedOldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  10865. workInProgress.flags |= Snapshot;
  10866. }
  10867. }
  10868. return false;
  10869. }
  10870. if (typeof getDerivedStateFromProps === 'function') {
  10871. applyDerivedStateFromProps(workInProgress, ctor, getDerivedStateFromProps, newProps);
  10872. newState = workInProgress.memoizedState;
  10873. }
  10874. var shouldUpdate = checkHasForceUpdateAfterProcessing() || checkShouldComponentUpdate(workInProgress, ctor, oldProps, newProps, oldState, newState, nextContext);
  10875. if (shouldUpdate) {
  10876. // In order to support react-lifecycles-compat polyfilled components,
  10877. // Unsafe lifecycles should not be invoked for components using the new APIs.
  10878. if (!hasNewLifecycles && (typeof instance.UNSAFE_componentWillUpdate === 'function' || typeof instance.componentWillUpdate === 'function')) {
  10879. if (typeof instance.componentWillUpdate === 'function') {
  10880. instance.componentWillUpdate(newProps, newState, nextContext);
  10881. }
  10882. if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
  10883. instance.UNSAFE_componentWillUpdate(newProps, newState, nextContext);
  10884. }
  10885. }
  10886. if (typeof instance.componentDidUpdate === 'function') {
  10887. workInProgress.flags |= Update;
  10888. }
  10889. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  10890. workInProgress.flags |= Snapshot;
  10891. }
  10892. } else {
  10893. // If an update was already in progress, we should schedule an Update
  10894. // effect even though we're bailing out, so that cWU/cDU are called.
  10895. if (typeof instance.componentDidUpdate === 'function') {
  10896. if (unresolvedOldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  10897. workInProgress.flags |= Update;
  10898. }
  10899. }
  10900. if (typeof instance.getSnapshotBeforeUpdate === 'function') {
  10901. if (unresolvedOldProps !== current.memoizedProps || oldState !== current.memoizedState) {
  10902. workInProgress.flags |= Snapshot;
  10903. }
  10904. } // If shouldComponentUpdate returned false, we should still update the
  10905. // memoized props/state to indicate that this work can be reused.
  10906. workInProgress.memoizedProps = newProps;
  10907. workInProgress.memoizedState = newState;
  10908. } // Update the existing instance's state, props, and context pointers even
  10909. // if shouldComponentUpdate returns false.
  10910. instance.props = newProps;
  10911. instance.state = newState;
  10912. instance.context = nextContext;
  10913. return shouldUpdate;
  10914. }
  10915. var didWarnAboutMaps;
  10916. var didWarnAboutGenerators;
  10917. var didWarnAboutStringRefs;
  10918. var ownerHasKeyUseWarning;
  10919. var ownerHasFunctionTypeWarning;
  10920. var warnForMissingKey = function (child, returnFiber) {};
  10921. {
  10922. didWarnAboutMaps = false;
  10923. didWarnAboutGenerators = false;
  10924. didWarnAboutStringRefs = {};
  10925. /**
  10926. * Warn if there's no key explicitly set on dynamic arrays of children or
  10927. * object keys are not valid. This allows us to keep track of children between
  10928. * updates.
  10929. */
  10930. ownerHasKeyUseWarning = {};
  10931. ownerHasFunctionTypeWarning = {};
  10932. warnForMissingKey = function (child, returnFiber) {
  10933. if (child === null || typeof child !== 'object') {
  10934. return;
  10935. }
  10936. if (!child._store || child._store.validated || child.key != null) {
  10937. return;
  10938. }
  10939. if (!(typeof child._store === 'object')) {
  10940. {
  10941. throw Error( "React Component in warnForMissingKey should have a _store. This error is likely caused by a bug in React. Please file an issue." );
  10942. }
  10943. }
  10944. child._store.validated = true;
  10945. var componentName = getComponentName(returnFiber.type) || 'Component';
  10946. if (ownerHasKeyUseWarning[componentName]) {
  10947. return;
  10948. }
  10949. ownerHasKeyUseWarning[componentName] = true;
  10950. error('Each child in a list should have a unique ' + '"key" prop. See https://reactjs.org/link/warning-keys for ' + 'more information.');
  10951. };
  10952. }
  10953. var isArray$1 = Array.isArray;
  10954. function coerceRef(returnFiber, current, element) {
  10955. var mixedRef = element.ref;
  10956. if (mixedRef !== null && typeof mixedRef !== 'function' && typeof mixedRef !== 'object') {
  10957. {
  10958. // TODO: Clean this up once we turn on the string ref warning for
  10959. // everyone, because the strict mode case will no longer be relevant
  10960. if ((returnFiber.mode & StrictMode || warnAboutStringRefs) && // We warn in ReactElement.js if owner and self are equal for string refs
  10961. // because these cannot be automatically converted to an arrow function
  10962. // using a codemod. Therefore, we don't have to warn about string refs again.
  10963. !(element._owner && element._self && element._owner.stateNode !== element._self)) {
  10964. var componentName = getComponentName(returnFiber.type) || 'Component';
  10965. if (!didWarnAboutStringRefs[componentName]) {
  10966. {
  10967. error('A string ref, "%s", has been found within a strict mode tree. ' + 'String refs are a source of potential bugs and should be avoided. ' + 'We recommend using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-string-ref', mixedRef);
  10968. }
  10969. didWarnAboutStringRefs[componentName] = true;
  10970. }
  10971. }
  10972. }
  10973. if (element._owner) {
  10974. var owner = element._owner;
  10975. var inst;
  10976. if (owner) {
  10977. var ownerFiber = owner;
  10978. if (!(ownerFiber.tag === ClassComponent)) {
  10979. {
  10980. throw Error( "Function components cannot have string refs. We recommend using useRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref" );
  10981. }
  10982. }
  10983. inst = ownerFiber.stateNode;
  10984. }
  10985. if (!inst) {
  10986. {
  10987. throw Error( "Missing owner for string ref " + mixedRef + ". This error is likely caused by a bug in React. Please file an issue." );
  10988. }
  10989. }
  10990. var stringRef = '' + mixedRef; // Check if previous string ref matches new string ref
  10991. if (current !== null && current.ref !== null && typeof current.ref === 'function' && current.ref._stringRef === stringRef) {
  10992. return current.ref;
  10993. }
  10994. var ref = function (value) {
  10995. var refs = inst.refs;
  10996. if (refs === emptyRefsObject) {
  10997. // This is a lazy pooled frozen object, so we need to initialize.
  10998. refs = inst.refs = {};
  10999. }
  11000. if (value === null) {
  11001. delete refs[stringRef];
  11002. } else {
  11003. refs[stringRef] = value;
  11004. }
  11005. };
  11006. ref._stringRef = stringRef;
  11007. return ref;
  11008. } else {
  11009. if (!(typeof mixedRef === 'string')) {
  11010. {
  11011. throw Error( "Expected ref to be a function, a string, an object returned by React.createRef(), or null." );
  11012. }
  11013. }
  11014. if (!element._owner) {
  11015. {
  11016. throw Error( "Element ref was specified as a string (" + mixedRef + ") 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://reactjs.org/link/refs-must-have-owner for more information." );
  11017. }
  11018. }
  11019. }
  11020. }
  11021. return mixedRef;
  11022. }
  11023. function throwOnInvalidObjectType(returnFiber, newChild) {
  11024. if (returnFiber.type !== 'textarea') {
  11025. {
  11026. {
  11027. throw Error( "Objects are not valid as a React child (found: " + (Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild) + "). If you meant to render a collection of children, use an array instead." );
  11028. }
  11029. }
  11030. }
  11031. }
  11032. function warnOnFunctionType(returnFiber) {
  11033. {
  11034. var componentName = getComponentName(returnFiber.type) || 'Component';
  11035. if (ownerHasFunctionTypeWarning[componentName]) {
  11036. return;
  11037. }
  11038. ownerHasFunctionTypeWarning[componentName] = true;
  11039. error('Functions are not valid as a React child. This may happen if ' + 'you return a Component instead of <Component /> from render. ' + 'Or maybe you meant to call this function rather than return it.');
  11040. }
  11041. } // We avoid inlining this to avoid potential deopts from using try/catch.
  11042. // to be able to optimize each path individually by branching early. This needs
  11043. // a compiler or we can do it manually. Helpers that don't need this branching
  11044. // live outside of this function.
  11045. function ChildReconciler(shouldTrackSideEffects) {
  11046. function deleteChild(returnFiber, childToDelete) {
  11047. if (!shouldTrackSideEffects) {
  11048. // Noop.
  11049. return;
  11050. } // Deletions are added in reversed order so we add it to the front.
  11051. // At this point, the return fiber's effect list is empty except for
  11052. // deletions, so we can just append the deletion to the list. The remaining
  11053. // effects aren't added until the complete phase. Once we implement
  11054. // resuming, this may not be true.
  11055. var last = returnFiber.lastEffect;
  11056. if (last !== null) {
  11057. last.nextEffect = childToDelete;
  11058. returnFiber.lastEffect = childToDelete;
  11059. } else {
  11060. returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
  11061. }
  11062. childToDelete.nextEffect = null;
  11063. childToDelete.flags = Deletion;
  11064. }
  11065. function deleteRemainingChildren(returnFiber, currentFirstChild) {
  11066. if (!shouldTrackSideEffects) {
  11067. // Noop.
  11068. return null;
  11069. } // TODO: For the shouldClone case, this could be micro-optimized a bit by
  11070. // assuming that after the first child we've already added everything.
  11071. var childToDelete = currentFirstChild;
  11072. while (childToDelete !== null) {
  11073. deleteChild(returnFiber, childToDelete);
  11074. childToDelete = childToDelete.sibling;
  11075. }
  11076. return null;
  11077. }
  11078. function mapRemainingChildren(returnFiber, currentFirstChild) {
  11079. // Add the remaining children to a temporary map so that we can find them by
  11080. // keys quickly. Implicit (null) keys get added to this set with their index
  11081. // instead.
  11082. var existingChildren = new Map();
  11083. var existingChild = currentFirstChild;
  11084. while (existingChild !== null) {
  11085. if (existingChild.key !== null) {
  11086. existingChildren.set(existingChild.key, existingChild);
  11087. } else {
  11088. existingChildren.set(existingChild.index, existingChild);
  11089. }
  11090. existingChild = existingChild.sibling;
  11091. }
  11092. return existingChildren;
  11093. }
  11094. function useFiber(fiber, pendingProps) {
  11095. // We currently set sibling to null and index to 0 here because it is easy
  11096. // to forget to do before returning it. E.g. for the single child case.
  11097. var clone = createWorkInProgress(fiber, pendingProps);
  11098. clone.index = 0;
  11099. clone.sibling = null;
  11100. return clone;
  11101. }
  11102. function placeChild(newFiber, lastPlacedIndex, newIndex) {
  11103. newFiber.index = newIndex;
  11104. if (!shouldTrackSideEffects) {
  11105. // Noop.
  11106. return lastPlacedIndex;
  11107. }
  11108. var current = newFiber.alternate;
  11109. if (current !== null) {
  11110. var oldIndex = current.index;
  11111. if (oldIndex < lastPlacedIndex) {
  11112. // This is a move.
  11113. newFiber.flags = Placement;
  11114. return lastPlacedIndex;
  11115. } else {
  11116. // This item can stay in place.
  11117. return oldIndex;
  11118. }
  11119. } else {
  11120. // This is an insertion.
  11121. newFiber.flags = Placement;
  11122. return lastPlacedIndex;
  11123. }
  11124. }
  11125. function placeSingleChild(newFiber) {
  11126. // This is simpler for the single child case. We only need to do a
  11127. // placement for inserting new children.
  11128. if (shouldTrackSideEffects && newFiber.alternate === null) {
  11129. newFiber.flags = Placement;
  11130. }
  11131. return newFiber;
  11132. }
  11133. function updateTextNode(returnFiber, current, textContent, lanes) {
  11134. if (current === null || current.tag !== HostText) {
  11135. // Insert
  11136. var created = createFiberFromText(textContent, returnFiber.mode, lanes);
  11137. created.return = returnFiber;
  11138. return created;
  11139. } else {
  11140. // Update
  11141. var existing = useFiber(current, textContent);
  11142. existing.return = returnFiber;
  11143. return existing;
  11144. }
  11145. }
  11146. function updateElement(returnFiber, current, element, lanes) {
  11147. if (current !== null) {
  11148. if (current.elementType === element.type || ( // Keep this check inline so it only runs on the false path:
  11149. isCompatibleFamilyForHotReloading(current, element) )) {
  11150. // Move based on index
  11151. var existing = useFiber(current, element.props);
  11152. existing.ref = coerceRef(returnFiber, current, element);
  11153. existing.return = returnFiber;
  11154. {
  11155. existing._debugSource = element._source;
  11156. existing._debugOwner = element._owner;
  11157. }
  11158. return existing;
  11159. }
  11160. } // Insert
  11161. var created = createFiberFromElement(element, returnFiber.mode, lanes);
  11162. created.ref = coerceRef(returnFiber, current, element);
  11163. created.return = returnFiber;
  11164. return created;
  11165. }
  11166. function updatePortal(returnFiber, current, portal, lanes) {
  11167. if (current === null || current.tag !== HostPortal || current.stateNode.containerInfo !== portal.containerInfo || current.stateNode.implementation !== portal.implementation) {
  11168. // Insert
  11169. var created = createFiberFromPortal(portal, returnFiber.mode, lanes);
  11170. created.return = returnFiber;
  11171. return created;
  11172. } else {
  11173. // Update
  11174. var existing = useFiber(current, portal.children || []);
  11175. existing.return = returnFiber;
  11176. return existing;
  11177. }
  11178. }
  11179. function updateFragment(returnFiber, current, fragment, lanes, key) {
  11180. if (current === null || current.tag !== Fragment) {
  11181. // Insert
  11182. var created = createFiberFromFragment(fragment, returnFiber.mode, lanes, key);
  11183. created.return = returnFiber;
  11184. return created;
  11185. } else {
  11186. // Update
  11187. var existing = useFiber(current, fragment);
  11188. existing.return = returnFiber;
  11189. return existing;
  11190. }
  11191. }
  11192. function createChild(returnFiber, newChild, lanes) {
  11193. if (typeof newChild === 'string' || typeof newChild === 'number') {
  11194. // Text nodes don't have keys. If the previous node is implicitly keyed
  11195. // we can continue to replace it without aborting even if it is not a text
  11196. // node.
  11197. var created = createFiberFromText('' + newChild, returnFiber.mode, lanes);
  11198. created.return = returnFiber;
  11199. return created;
  11200. }
  11201. if (typeof newChild === 'object' && newChild !== null) {
  11202. switch (newChild.$$typeof) {
  11203. case REACT_ELEMENT_TYPE:
  11204. {
  11205. var _created = createFiberFromElement(newChild, returnFiber.mode, lanes);
  11206. _created.ref = coerceRef(returnFiber, null, newChild);
  11207. _created.return = returnFiber;
  11208. return _created;
  11209. }
  11210. case REACT_PORTAL_TYPE:
  11211. {
  11212. var _created2 = createFiberFromPortal(newChild, returnFiber.mode, lanes);
  11213. _created2.return = returnFiber;
  11214. return _created2;
  11215. }
  11216. }
  11217. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  11218. var _created3 = createFiberFromFragment(newChild, returnFiber.mode, lanes, null);
  11219. _created3.return = returnFiber;
  11220. return _created3;
  11221. }
  11222. throwOnInvalidObjectType(returnFiber, newChild);
  11223. }
  11224. {
  11225. if (typeof newChild === 'function') {
  11226. warnOnFunctionType(returnFiber);
  11227. }
  11228. }
  11229. return null;
  11230. }
  11231. function updateSlot(returnFiber, oldFiber, newChild, lanes) {
  11232. // Update the fiber if the keys match, otherwise return null.
  11233. var key = oldFiber !== null ? oldFiber.key : null;
  11234. if (typeof newChild === 'string' || typeof newChild === 'number') {
  11235. // Text nodes don't have keys. If the previous node is implicitly keyed
  11236. // we can continue to replace it without aborting even if it is not a text
  11237. // node.
  11238. if (key !== null) {
  11239. return null;
  11240. }
  11241. return updateTextNode(returnFiber, oldFiber, '' + newChild, lanes);
  11242. }
  11243. if (typeof newChild === 'object' && newChild !== null) {
  11244. switch (newChild.$$typeof) {
  11245. case REACT_ELEMENT_TYPE:
  11246. {
  11247. if (newChild.key === key) {
  11248. if (newChild.type === REACT_FRAGMENT_TYPE) {
  11249. return updateFragment(returnFiber, oldFiber, newChild.props.children, lanes, key);
  11250. }
  11251. return updateElement(returnFiber, oldFiber, newChild, lanes);
  11252. } else {
  11253. return null;
  11254. }
  11255. }
  11256. case REACT_PORTAL_TYPE:
  11257. {
  11258. if (newChild.key === key) {
  11259. return updatePortal(returnFiber, oldFiber, newChild, lanes);
  11260. } else {
  11261. return null;
  11262. }
  11263. }
  11264. }
  11265. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  11266. if (key !== null) {
  11267. return null;
  11268. }
  11269. return updateFragment(returnFiber, oldFiber, newChild, lanes, null);
  11270. }
  11271. throwOnInvalidObjectType(returnFiber, newChild);
  11272. }
  11273. {
  11274. if (typeof newChild === 'function') {
  11275. warnOnFunctionType(returnFiber);
  11276. }
  11277. }
  11278. return null;
  11279. }
  11280. function updateFromMap(existingChildren, returnFiber, newIdx, newChild, lanes) {
  11281. if (typeof newChild === 'string' || typeof newChild === 'number') {
  11282. // Text nodes don't have keys, so we neither have to check the old nor
  11283. // new node for the key. If both are text nodes, they match.
  11284. var matchedFiber = existingChildren.get(newIdx) || null;
  11285. return updateTextNode(returnFiber, matchedFiber, '' + newChild, lanes);
  11286. }
  11287. if (typeof newChild === 'object' && newChild !== null) {
  11288. switch (newChild.$$typeof) {
  11289. case REACT_ELEMENT_TYPE:
  11290. {
  11291. var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
  11292. if (newChild.type === REACT_FRAGMENT_TYPE) {
  11293. return updateFragment(returnFiber, _matchedFiber, newChild.props.children, lanes, newChild.key);
  11294. }
  11295. return updateElement(returnFiber, _matchedFiber, newChild, lanes);
  11296. }
  11297. case REACT_PORTAL_TYPE:
  11298. {
  11299. var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;
  11300. return updatePortal(returnFiber, _matchedFiber2, newChild, lanes);
  11301. }
  11302. }
  11303. if (isArray$1(newChild) || getIteratorFn(newChild)) {
  11304. var _matchedFiber3 = existingChildren.get(newIdx) || null;
  11305. return updateFragment(returnFiber, _matchedFiber3, newChild, lanes, null);
  11306. }
  11307. throwOnInvalidObjectType(returnFiber, newChild);
  11308. }
  11309. {
  11310. if (typeof newChild === 'function') {
  11311. warnOnFunctionType(returnFiber);
  11312. }
  11313. }
  11314. return null;
  11315. }
  11316. /**
  11317. * Warns if there is a duplicate or missing key
  11318. */
  11319. function warnOnInvalidKey(child, knownKeys, returnFiber) {
  11320. {
  11321. if (typeof child !== 'object' || child === null) {
  11322. return knownKeys;
  11323. }
  11324. switch (child.$$typeof) {
  11325. case REACT_ELEMENT_TYPE:
  11326. case REACT_PORTAL_TYPE:
  11327. warnForMissingKey(child, returnFiber);
  11328. var key = child.key;
  11329. if (typeof key !== 'string') {
  11330. break;
  11331. }
  11332. if (knownKeys === null) {
  11333. knownKeys = new Set();
  11334. knownKeys.add(key);
  11335. break;
  11336. }
  11337. if (!knownKeys.has(key)) {
  11338. knownKeys.add(key);
  11339. break;
  11340. }
  11341. error('Encountered two children with the same key, `%s`. ' + 'Keys should be unique so that components maintain their identity ' + 'across updates. Non-unique keys may cause children to be ' + 'duplicated and/or omitted — the behavior is unsupported and ' + 'could change in a future version.', key);
  11342. break;
  11343. }
  11344. }
  11345. return knownKeys;
  11346. }
  11347. function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, lanes) {
  11348. // This algorithm can't optimize by searching from both ends since we
  11349. // don't have backpointers on fibers. I'm trying to see how far we can get
  11350. // with that model. If it ends up not being worth the tradeoffs, we can
  11351. // add it later.
  11352. // Even with a two ended optimization, we'd want to optimize for the case
  11353. // where there are few changes and brute force the comparison instead of
  11354. // going for the Map. It'd like to explore hitting that path first in
  11355. // forward-only mode and only go for the Map once we notice that we need
  11356. // lots of look ahead. This doesn't handle reversal as well as two ended
  11357. // search but that's unusual. Besides, for the two ended optimization to
  11358. // work on Iterables, we'd need to copy the whole set.
  11359. // In this first iteration, we'll just live with hitting the bad case
  11360. // (adding everything to a Map) in for every insert/move.
  11361. // If you change this code, also update reconcileChildrenIterator() which
  11362. // uses the same algorithm.
  11363. {
  11364. // First, validate keys.
  11365. var knownKeys = null;
  11366. for (var i = 0; i < newChildren.length; i++) {
  11367. var child = newChildren[i];
  11368. knownKeys = warnOnInvalidKey(child, knownKeys, returnFiber);
  11369. }
  11370. }
  11371. var resultingFirstChild = null;
  11372. var previousNewFiber = null;
  11373. var oldFiber = currentFirstChild;
  11374. var lastPlacedIndex = 0;
  11375. var newIdx = 0;
  11376. var nextOldFiber = null;
  11377. for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {
  11378. if (oldFiber.index > newIdx) {
  11379. nextOldFiber = oldFiber;
  11380. oldFiber = null;
  11381. } else {
  11382. nextOldFiber = oldFiber.sibling;
  11383. }
  11384. var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], lanes);
  11385. if (newFiber === null) {
  11386. // TODO: This breaks on empty slots like null children. That's
  11387. // unfortunate because it triggers the slow path all the time. We need
  11388. // a better way to communicate whether this was a miss or null,
  11389. // boolean, undefined, etc.
  11390. if (oldFiber === null) {
  11391. oldFiber = nextOldFiber;
  11392. }
  11393. break;
  11394. }
  11395. if (shouldTrackSideEffects) {
  11396. if (oldFiber && newFiber.alternate === null) {
  11397. // We matched the slot, but we didn't reuse the existing fiber, so we
  11398. // need to delete the existing child.
  11399. deleteChild(returnFiber, oldFiber);
  11400. }
  11401. }
  11402. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  11403. if (previousNewFiber === null) {
  11404. // TODO: Move out of the loop. This only happens for the first run.
  11405. resultingFirstChild = newFiber;
  11406. } else {
  11407. // TODO: Defer siblings if we're not at the right index for this slot.
  11408. // I.e. if we had null values before, then we want to defer this
  11409. // for each null value. However, we also don't want to call updateSlot
  11410. // with the previous one.
  11411. previousNewFiber.sibling = newFiber;
  11412. }
  11413. previousNewFiber = newFiber;
  11414. oldFiber = nextOldFiber;
  11415. }
  11416. if (newIdx === newChildren.length) {
  11417. // We've reached the end of the new children. We can delete the rest.
  11418. deleteRemainingChildren(returnFiber, oldFiber);
  11419. return resultingFirstChild;
  11420. }
  11421. if (oldFiber === null) {
  11422. // If we don't have any more existing children we can choose a fast path
  11423. // since the rest will all be insertions.
  11424. for (; newIdx < newChildren.length; newIdx++) {
  11425. var _newFiber = createChild(returnFiber, newChildren[newIdx], lanes);
  11426. if (_newFiber === null) {
  11427. continue;
  11428. }
  11429. lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);
  11430. if (previousNewFiber === null) {
  11431. // TODO: Move out of the loop. This only happens for the first run.
  11432. resultingFirstChild = _newFiber;
  11433. } else {
  11434. previousNewFiber.sibling = _newFiber;
  11435. }
  11436. previousNewFiber = _newFiber;
  11437. }
  11438. return resultingFirstChild;
  11439. } // Add all children to a key map for quick lookups.
  11440. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  11441. for (; newIdx < newChildren.length; newIdx++) {
  11442. var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], lanes);
  11443. if (_newFiber2 !== null) {
  11444. if (shouldTrackSideEffects) {
  11445. if (_newFiber2.alternate !== null) {
  11446. // The new fiber is a work in progress, but if there exists a
  11447. // current, that means that we reused the fiber. We need to delete
  11448. // it from the child list so that we don't add it to the deletion
  11449. // list.
  11450. existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);
  11451. }
  11452. }
  11453. lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);
  11454. if (previousNewFiber === null) {
  11455. resultingFirstChild = _newFiber2;
  11456. } else {
  11457. previousNewFiber.sibling = _newFiber2;
  11458. }
  11459. previousNewFiber = _newFiber2;
  11460. }
  11461. }
  11462. if (shouldTrackSideEffects) {
  11463. // Any existing children that weren't consumed above were deleted. We need
  11464. // to add them to the deletion list.
  11465. existingChildren.forEach(function (child) {
  11466. return deleteChild(returnFiber, child);
  11467. });
  11468. }
  11469. return resultingFirstChild;
  11470. }
  11471. function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, lanes) {
  11472. // This is the same implementation as reconcileChildrenArray(),
  11473. // but using the iterator instead.
  11474. var iteratorFn = getIteratorFn(newChildrenIterable);
  11475. if (!(typeof iteratorFn === 'function')) {
  11476. {
  11477. throw Error( "An object is not an iterable. This error is likely caused by a bug in React. Please file an issue." );
  11478. }
  11479. }
  11480. {
  11481. // We don't support rendering Generators because it's a mutation.
  11482. // See https://github.com/facebook/react/issues/12995
  11483. if (typeof Symbol === 'function' && // $FlowFixMe Flow doesn't know about toStringTag
  11484. newChildrenIterable[Symbol.toStringTag] === 'Generator') {
  11485. if (!didWarnAboutGenerators) {
  11486. error('Using Generators as children is unsupported and will likely yield ' + 'unexpected results because enumerating a generator mutates it. ' + 'You may convert it to an array with `Array.from()` or the ' + '`[...spread]` operator before rendering. Keep in mind ' + 'you might need to polyfill these features for older browsers.');
  11487. }
  11488. didWarnAboutGenerators = true;
  11489. } // Warn about using Maps as children
  11490. if (newChildrenIterable.entries === iteratorFn) {
  11491. if (!didWarnAboutMaps) {
  11492. error('Using Maps as children is not supported. ' + 'Use an array of keyed ReactElements instead.');
  11493. }
  11494. didWarnAboutMaps = true;
  11495. } // First, validate keys.
  11496. // We'll get a different iterator later for the main pass.
  11497. var _newChildren = iteratorFn.call(newChildrenIterable);
  11498. if (_newChildren) {
  11499. var knownKeys = null;
  11500. var _step = _newChildren.next();
  11501. for (; !_step.done; _step = _newChildren.next()) {
  11502. var child = _step.value;
  11503. knownKeys = warnOnInvalidKey(child, knownKeys, returnFiber);
  11504. }
  11505. }
  11506. }
  11507. var newChildren = iteratorFn.call(newChildrenIterable);
  11508. if (!(newChildren != null)) {
  11509. {
  11510. throw Error( "An iterable object provided no iterator." );
  11511. }
  11512. }
  11513. var resultingFirstChild = null;
  11514. var previousNewFiber = null;
  11515. var oldFiber = currentFirstChild;
  11516. var lastPlacedIndex = 0;
  11517. var newIdx = 0;
  11518. var nextOldFiber = null;
  11519. var step = newChildren.next();
  11520. for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
  11521. if (oldFiber.index > newIdx) {
  11522. nextOldFiber = oldFiber;
  11523. oldFiber = null;
  11524. } else {
  11525. nextOldFiber = oldFiber.sibling;
  11526. }
  11527. var newFiber = updateSlot(returnFiber, oldFiber, step.value, lanes);
  11528. if (newFiber === null) {
  11529. // TODO: This breaks on empty slots like null children. That's
  11530. // unfortunate because it triggers the slow path all the time. We need
  11531. // a better way to communicate whether this was a miss or null,
  11532. // boolean, undefined, etc.
  11533. if (oldFiber === null) {
  11534. oldFiber = nextOldFiber;
  11535. }
  11536. break;
  11537. }
  11538. if (shouldTrackSideEffects) {
  11539. if (oldFiber && newFiber.alternate === null) {
  11540. // We matched the slot, but we didn't reuse the existing fiber, so we
  11541. // need to delete the existing child.
  11542. deleteChild(returnFiber, oldFiber);
  11543. }
  11544. }
  11545. lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);
  11546. if (previousNewFiber === null) {
  11547. // TODO: Move out of the loop. This only happens for the first run.
  11548. resultingFirstChild = newFiber;
  11549. } else {
  11550. // TODO: Defer siblings if we're not at the right index for this slot.
  11551. // I.e. if we had null values before, then we want to defer this
  11552. // for each null value. However, we also don't want to call updateSlot
  11553. // with the previous one.
  11554. previousNewFiber.sibling = newFiber;
  11555. }
  11556. previousNewFiber = newFiber;
  11557. oldFiber = nextOldFiber;
  11558. }
  11559. if (step.done) {
  11560. // We've reached the end of the new children. We can delete the rest.
  11561. deleteRemainingChildren(returnFiber, oldFiber);
  11562. return resultingFirstChild;
  11563. }
  11564. if (oldFiber === null) {
  11565. // If we don't have any more existing children we can choose a fast path
  11566. // since the rest will all be insertions.
  11567. for (; !step.done; newIdx++, step = newChildren.next()) {
  11568. var _newFiber3 = createChild(returnFiber, step.value, lanes);
  11569. if (_newFiber3 === null) {
  11570. continue;
  11571. }
  11572. lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);
  11573. if (previousNewFiber === null) {
  11574. // TODO: Move out of the loop. This only happens for the first run.
  11575. resultingFirstChild = _newFiber3;
  11576. } else {
  11577. previousNewFiber.sibling = _newFiber3;
  11578. }
  11579. previousNewFiber = _newFiber3;
  11580. }
  11581. return resultingFirstChild;
  11582. } // Add all children to a key map for quick lookups.
  11583. var existingChildren = mapRemainingChildren(returnFiber, oldFiber); // Keep scanning and use the map to restore deleted items as moves.
  11584. for (; !step.done; newIdx++, step = newChildren.next()) {
  11585. var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, lanes);
  11586. if (_newFiber4 !== null) {
  11587. if (shouldTrackSideEffects) {
  11588. if (_newFiber4.alternate !== null) {
  11589. // The new fiber is a work in progress, but if there exists a
  11590. // current, that means that we reused the fiber. We need to delete
  11591. // it from the child list so that we don't add it to the deletion
  11592. // list.
  11593. existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);
  11594. }
  11595. }
  11596. lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);
  11597. if (previousNewFiber === null) {
  11598. resultingFirstChild = _newFiber4;
  11599. } else {
  11600. previousNewFiber.sibling = _newFiber4;
  11601. }
  11602. previousNewFiber = _newFiber4;
  11603. }
  11604. }
  11605. if (shouldTrackSideEffects) {
  11606. // Any existing children that weren't consumed above were deleted. We need
  11607. // to add them to the deletion list.
  11608. existingChildren.forEach(function (child) {
  11609. return deleteChild(returnFiber, child);
  11610. });
  11611. }
  11612. return resultingFirstChild;
  11613. }
  11614. function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, lanes) {
  11615. // There's no need to check for keys on text nodes since we don't have a
  11616. // way to define them.
  11617. if (currentFirstChild !== null && currentFirstChild.tag === HostText) {
  11618. // We already have an existing node so let's just update it and delete
  11619. // the rest.
  11620. deleteRemainingChildren(returnFiber, currentFirstChild.sibling);
  11621. var existing = useFiber(currentFirstChild, textContent);
  11622. existing.return = returnFiber;
  11623. return existing;
  11624. } // The existing first child is not a text node so we need to create one
  11625. // and delete the existing ones.
  11626. deleteRemainingChildren(returnFiber, currentFirstChild);
  11627. var created = createFiberFromText(textContent, returnFiber.mode, lanes);
  11628. created.return = returnFiber;
  11629. return created;
  11630. }
  11631. function reconcileSingleElement(returnFiber, currentFirstChild, element, lanes) {
  11632. var key = element.key;
  11633. var child = currentFirstChild;
  11634. while (child !== null) {
  11635. // TODO: If key === null and child.key === null, then this only applies to
  11636. // the first item in the list.
  11637. if (child.key === key) {
  11638. switch (child.tag) {
  11639. case Fragment:
  11640. {
  11641. if (element.type === REACT_FRAGMENT_TYPE) {
  11642. deleteRemainingChildren(returnFiber, child.sibling);
  11643. var existing = useFiber(child, element.props.children);
  11644. existing.return = returnFiber;
  11645. {
  11646. existing._debugSource = element._source;
  11647. existing._debugOwner = element._owner;
  11648. }
  11649. return existing;
  11650. }
  11651. break;
  11652. }
  11653. case Block:
  11654. // We intentionally fallthrough here if enableBlocksAPI is not on.
  11655. // eslint-disable-next-lined no-fallthrough
  11656. default:
  11657. {
  11658. if (child.elementType === element.type || ( // Keep this check inline so it only runs on the false path:
  11659. isCompatibleFamilyForHotReloading(child, element) )) {
  11660. deleteRemainingChildren(returnFiber, child.sibling);
  11661. var _existing3 = useFiber(child, element.props);
  11662. _existing3.ref = coerceRef(returnFiber, child, element);
  11663. _existing3.return = returnFiber;
  11664. {
  11665. _existing3._debugSource = element._source;
  11666. _existing3._debugOwner = element._owner;
  11667. }
  11668. return _existing3;
  11669. }
  11670. break;
  11671. }
  11672. } // Didn't match.
  11673. deleteRemainingChildren(returnFiber, child);
  11674. break;
  11675. } else {
  11676. deleteChild(returnFiber, child);
  11677. }
  11678. child = child.sibling;
  11679. }
  11680. if (element.type === REACT_FRAGMENT_TYPE) {
  11681. var created = createFiberFromFragment(element.props.children, returnFiber.mode, lanes, element.key);
  11682. created.return = returnFiber;
  11683. return created;
  11684. } else {
  11685. var _created4 = createFiberFromElement(element, returnFiber.mode, lanes);
  11686. _created4.ref = coerceRef(returnFiber, currentFirstChild, element);
  11687. _created4.return = returnFiber;
  11688. return _created4;
  11689. }
  11690. }
  11691. function reconcileSinglePortal(returnFiber, currentFirstChild, portal, lanes) {
  11692. var key = portal.key;
  11693. var child = currentFirstChild;
  11694. while (child !== null) {
  11695. // TODO: If key === null and child.key === null, then this only applies to
  11696. // the first item in the list.
  11697. if (child.key === key) {
  11698. if (child.tag === HostPortal && child.stateNode.containerInfo === portal.containerInfo && child.stateNode.implementation === portal.implementation) {
  11699. deleteRemainingChildren(returnFiber, child.sibling);
  11700. var existing = useFiber(child, portal.children || []);
  11701. existing.return = returnFiber;
  11702. return existing;
  11703. } else {
  11704. deleteRemainingChildren(returnFiber, child);
  11705. break;
  11706. }
  11707. } else {
  11708. deleteChild(returnFiber, child);
  11709. }
  11710. child = child.sibling;
  11711. }
  11712. var created = createFiberFromPortal(portal, returnFiber.mode, lanes);
  11713. created.return = returnFiber;
  11714. return created;
  11715. } // This API will tag the children with the side-effect of the reconciliation
  11716. // itself. They will be added to the side-effect list as we pass through the
  11717. // children and the parent.
  11718. function reconcileChildFibers(returnFiber, currentFirstChild, newChild, lanes) {
  11719. // This function is not recursive.
  11720. // If the top level item is an array, we treat it as a set of children,
  11721. // not as a fragment. Nested arrays on the other hand will be treated as
  11722. // fragment nodes. Recursion happens at the normal flow.
  11723. // Handle top level unkeyed fragments as if they were arrays.
  11724. // This leads to an ambiguity between <>{[...]}</> and <>...</>.
  11725. // We treat the ambiguous cases above the same.
  11726. var isUnkeyedTopLevelFragment = typeof newChild === 'object' && newChild !== null && newChild.type === REACT_FRAGMENT_TYPE && newChild.key === null;
  11727. if (isUnkeyedTopLevelFragment) {
  11728. newChild = newChild.props.children;
  11729. } // Handle object types
  11730. var isObject = typeof newChild === 'object' && newChild !== null;
  11731. if (isObject) {
  11732. switch (newChild.$$typeof) {
  11733. case REACT_ELEMENT_TYPE:
  11734. return placeSingleChild(reconcileSingleElement(returnFiber, currentFirstChild, newChild, lanes));
  11735. case REACT_PORTAL_TYPE:
  11736. return placeSingleChild(reconcileSinglePortal(returnFiber, currentFirstChild, newChild, lanes));
  11737. }
  11738. }
  11739. if (typeof newChild === 'string' || typeof newChild === 'number') {
  11740. return placeSingleChild(reconcileSingleTextNode(returnFiber, currentFirstChild, '' + newChild, lanes));
  11741. }
  11742. if (isArray$1(newChild)) {
  11743. return reconcileChildrenArray(returnFiber, currentFirstChild, newChild, lanes);
  11744. }
  11745. if (getIteratorFn(newChild)) {
  11746. return reconcileChildrenIterator(returnFiber, currentFirstChild, newChild, lanes);
  11747. }
  11748. if (isObject) {
  11749. throwOnInvalidObjectType(returnFiber, newChild);
  11750. }
  11751. {
  11752. if (typeof newChild === 'function') {
  11753. warnOnFunctionType(returnFiber);
  11754. }
  11755. }
  11756. if (typeof newChild === 'undefined' && !isUnkeyedTopLevelFragment) {
  11757. // If the new child is undefined, and the return fiber is a composite
  11758. // component, throw an error. If Fiber return types are disabled,
  11759. // we already threw above.
  11760. switch (returnFiber.tag) {
  11761. case ClassComponent:
  11762. {
  11763. {
  11764. var instance = returnFiber.stateNode;
  11765. if (instance.render._isMockFunction) {
  11766. // We allow auto-mocks to proceed as if they're returning null.
  11767. break;
  11768. }
  11769. }
  11770. }
  11771. // Intentionally fall through to the next case, which handles both
  11772. // functions and classes
  11773. // eslint-disable-next-lined no-fallthrough
  11774. case Block:
  11775. case FunctionComponent:
  11776. case ForwardRef:
  11777. case SimpleMemoComponent:
  11778. {
  11779. {
  11780. {
  11781. throw Error( (getComponentName(returnFiber.type) || 'Component') + "(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null." );
  11782. }
  11783. }
  11784. }
  11785. }
  11786. } // Remaining cases are all treated as empty.
  11787. return deleteRemainingChildren(returnFiber, currentFirstChild);
  11788. }
  11789. return reconcileChildFibers;
  11790. }
  11791. var reconcileChildFibers = ChildReconciler(true);
  11792. var mountChildFibers = ChildReconciler(false);
  11793. function cloneChildFibers(current, workInProgress) {
  11794. if (!(current === null || workInProgress.child === current.child)) {
  11795. {
  11796. throw Error( "Resuming work not yet implemented." );
  11797. }
  11798. }
  11799. if (workInProgress.child === null) {
  11800. return;
  11801. }
  11802. var currentChild = workInProgress.child;
  11803. var newChild = createWorkInProgress(currentChild, currentChild.pendingProps);
  11804. workInProgress.child = newChild;
  11805. newChild.return = workInProgress;
  11806. while (currentChild.sibling !== null) {
  11807. currentChild = currentChild.sibling;
  11808. newChild = newChild.sibling = createWorkInProgress(currentChild, currentChild.pendingProps);
  11809. newChild.return = workInProgress;
  11810. }
  11811. newChild.sibling = null;
  11812. } // Reset a workInProgress child set to prepare it for a second pass.
  11813. function resetChildFibers(workInProgress, lanes) {
  11814. var child = workInProgress.child;
  11815. while (child !== null) {
  11816. resetWorkInProgress(child, lanes);
  11817. child = child.sibling;
  11818. }
  11819. }
  11820. var NO_CONTEXT = {};
  11821. var contextStackCursor$1 = createCursor(NO_CONTEXT);
  11822. var contextFiberStackCursor = createCursor(NO_CONTEXT);
  11823. var rootInstanceStackCursor = createCursor(NO_CONTEXT);
  11824. function requiredContext(c) {
  11825. if (!(c !== NO_CONTEXT)) {
  11826. {
  11827. throw Error( "Expected host context to exist. This error is likely caused by a bug in React. Please file an issue." );
  11828. }
  11829. }
  11830. return c;
  11831. }
  11832. function getRootHostContainer() {
  11833. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  11834. return rootInstance;
  11835. }
  11836. function pushHostContainer(fiber, nextRootInstance) {
  11837. // Push current root instance onto the stack;
  11838. // This allows us to reset root when portals are popped.
  11839. push(rootInstanceStackCursor, nextRootInstance, fiber); // Track the context and the Fiber that provided it.
  11840. // This enables us to pop only Fibers that provide unique contexts.
  11841. push(contextFiberStackCursor, fiber, fiber); // Finally, we need to push the host context to the stack.
  11842. // However, we can't just call getRootHostContext() and push it because
  11843. // we'd have a different number of entries on the stack depending on
  11844. // whether getRootHostContext() throws somewhere in renderer code or not.
  11845. // So we push an empty value first. This lets us safely unwind on errors.
  11846. push(contextStackCursor$1, NO_CONTEXT, fiber);
  11847. var nextRootContext = getRootHostContext(nextRootInstance); // Now that we know this function doesn't throw, replace it.
  11848. pop(contextStackCursor$1, fiber);
  11849. push(contextStackCursor$1, nextRootContext, fiber);
  11850. }
  11851. function popHostContainer(fiber) {
  11852. pop(contextStackCursor$1, fiber);
  11853. pop(contextFiberStackCursor, fiber);
  11854. pop(rootInstanceStackCursor, fiber);
  11855. }
  11856. function getHostContext() {
  11857. var context = requiredContext(contextStackCursor$1.current);
  11858. return context;
  11859. }
  11860. function pushHostContext(fiber) {
  11861. var rootInstance = requiredContext(rootInstanceStackCursor.current);
  11862. var context = requiredContext(contextStackCursor$1.current);
  11863. var nextContext = getChildHostContext(context, fiber.type); // Don't push this Fiber's context unless it's unique.
  11864. if (context === nextContext) {
  11865. return;
  11866. } // Track the context and the Fiber that provided it.
  11867. // This enables us to pop only Fibers that provide unique contexts.
  11868. push(contextFiberStackCursor, fiber, fiber);
  11869. push(contextStackCursor$1, nextContext, fiber);
  11870. }
  11871. function popHostContext(fiber) {
  11872. // Do not pop unless this Fiber provided the current context.
  11873. // pushHostContext() only pushes Fibers that provide unique contexts.
  11874. if (contextFiberStackCursor.current !== fiber) {
  11875. return;
  11876. }
  11877. pop(contextStackCursor$1, fiber);
  11878. pop(contextFiberStackCursor, fiber);
  11879. }
  11880. var DefaultSuspenseContext = 0; // The Suspense Context is split into two parts. The lower bits is
  11881. // inherited deeply down the subtree. The upper bits only affect
  11882. // this immediate suspense boundary and gets reset each new
  11883. // boundary or suspense list.
  11884. var SubtreeSuspenseContextMask = 1; // Subtree Flags:
  11885. // InvisibleParentSuspenseContext indicates that one of our parent Suspense
  11886. // boundaries is not currently showing visible main content.
  11887. // Either because it is already showing a fallback or is not mounted at all.
  11888. // We can use this to determine if it is desirable to trigger a fallback at
  11889. // the parent. If not, then we might need to trigger undesirable boundaries
  11890. // and/or suspend the commit to avoid hiding the parent content.
  11891. var InvisibleParentSuspenseContext = 1; // Shallow Flags:
  11892. // ForceSuspenseFallback can be used by SuspenseList to force newly added
  11893. // items into their fallback state during one of the render passes.
  11894. var ForceSuspenseFallback = 2;
  11895. var suspenseStackCursor = createCursor(DefaultSuspenseContext);
  11896. function hasSuspenseContext(parentContext, flag) {
  11897. return (parentContext & flag) !== 0;
  11898. }
  11899. function setDefaultShallowSuspenseContext(parentContext) {
  11900. return parentContext & SubtreeSuspenseContextMask;
  11901. }
  11902. function setShallowSuspenseContext(parentContext, shallowContext) {
  11903. return parentContext & SubtreeSuspenseContextMask | shallowContext;
  11904. }
  11905. function addSubtreeSuspenseContext(parentContext, subtreeContext) {
  11906. return parentContext | subtreeContext;
  11907. }
  11908. function pushSuspenseContext(fiber, newContext) {
  11909. push(suspenseStackCursor, newContext, fiber);
  11910. }
  11911. function popSuspenseContext(fiber) {
  11912. pop(suspenseStackCursor, fiber);
  11913. }
  11914. function shouldCaptureSuspense(workInProgress, hasInvisibleParent) {
  11915. // If it was the primary children that just suspended, capture and render the
  11916. // fallback. Otherwise, don't capture and bubble to the next boundary.
  11917. var nextState = workInProgress.memoizedState;
  11918. if (nextState !== null) {
  11919. if (nextState.dehydrated !== null) {
  11920. // A dehydrated boundary always captures.
  11921. return true;
  11922. }
  11923. return false;
  11924. }
  11925. var props = workInProgress.memoizedProps; // In order to capture, the Suspense component must have a fallback prop.
  11926. if (props.fallback === undefined) {
  11927. return false;
  11928. } // Regular boundaries always capture.
  11929. if (props.unstable_avoidThisFallback !== true) {
  11930. return true;
  11931. } // If it's a boundary we should avoid, then we prefer to bubble up to the
  11932. // parent boundary if it is currently invisible.
  11933. if (hasInvisibleParent) {
  11934. return false;
  11935. } // If the parent is not able to handle it, we must handle it.
  11936. return true;
  11937. }
  11938. function findFirstSuspended(row) {
  11939. var node = row;
  11940. while (node !== null) {
  11941. if (node.tag === SuspenseComponent) {
  11942. var state = node.memoizedState;
  11943. if (state !== null) {
  11944. var dehydrated = state.dehydrated;
  11945. if (dehydrated === null || isSuspenseInstancePending(dehydrated) || isSuspenseInstanceFallback(dehydrated)) {
  11946. return node;
  11947. }
  11948. }
  11949. } else if (node.tag === SuspenseListComponent && // revealOrder undefined can't be trusted because it don't
  11950. // keep track of whether it suspended or not.
  11951. node.memoizedProps.revealOrder !== undefined) {
  11952. var didSuspend = (node.flags & DidCapture) !== NoFlags;
  11953. if (didSuspend) {
  11954. return node;
  11955. }
  11956. } else if (node.child !== null) {
  11957. node.child.return = node;
  11958. node = node.child;
  11959. continue;
  11960. }
  11961. if (node === row) {
  11962. return null;
  11963. }
  11964. while (node.sibling === null) {
  11965. if (node.return === null || node.return === row) {
  11966. return null;
  11967. }
  11968. node = node.return;
  11969. }
  11970. node.sibling.return = node.return;
  11971. node = node.sibling;
  11972. }
  11973. return null;
  11974. }
  11975. var NoFlags$1 =
  11976. /* */
  11977. 0; // Represents whether effect should fire.
  11978. var HasEffect =
  11979. /* */
  11980. 1; // Represents the phase in which the effect (not the clean-up) fires.
  11981. var Layout =
  11982. /* */
  11983. 2;
  11984. var Passive$1 =
  11985. /* */
  11986. 4;
  11987. // This may have been an insertion or a hydration.
  11988. var hydrationParentFiber = null;
  11989. var nextHydratableInstance = null;
  11990. var isHydrating = false;
  11991. function enterHydrationState(fiber) {
  11992. var parentInstance = fiber.stateNode.containerInfo;
  11993. nextHydratableInstance = getFirstHydratableChild(parentInstance);
  11994. hydrationParentFiber = fiber;
  11995. isHydrating = true;
  11996. return true;
  11997. }
  11998. function deleteHydratableInstance(returnFiber, instance) {
  11999. {
  12000. switch (returnFiber.tag) {
  12001. case HostRoot:
  12002. didNotHydrateContainerInstance(returnFiber.stateNode.containerInfo, instance);
  12003. break;
  12004. case HostComponent:
  12005. didNotHydrateInstance(returnFiber.type, returnFiber.memoizedProps, returnFiber.stateNode, instance);
  12006. break;
  12007. }
  12008. }
  12009. var childToDelete = createFiberFromHostInstanceForDeletion();
  12010. childToDelete.stateNode = instance;
  12011. childToDelete.return = returnFiber;
  12012. childToDelete.flags = Deletion; // This might seem like it belongs on progressedFirstDeletion. However,
  12013. // these children are not part of the reconciliation list of children.
  12014. // Even if we abort and rereconcile the children, that will try to hydrate
  12015. // again and the nodes are still in the host tree so these will be
  12016. // recreated.
  12017. if (returnFiber.lastEffect !== null) {
  12018. returnFiber.lastEffect.nextEffect = childToDelete;
  12019. returnFiber.lastEffect = childToDelete;
  12020. } else {
  12021. returnFiber.firstEffect = returnFiber.lastEffect = childToDelete;
  12022. }
  12023. }
  12024. function insertNonHydratedInstance(returnFiber, fiber) {
  12025. fiber.flags = fiber.flags & ~Hydrating | Placement;
  12026. {
  12027. switch (returnFiber.tag) {
  12028. case HostRoot:
  12029. {
  12030. var parentContainer = returnFiber.stateNode.containerInfo;
  12031. switch (fiber.tag) {
  12032. case HostComponent:
  12033. var type = fiber.type;
  12034. var props = fiber.pendingProps;
  12035. didNotFindHydratableContainerInstance(parentContainer, type);
  12036. break;
  12037. case HostText:
  12038. var text = fiber.pendingProps;
  12039. didNotFindHydratableContainerTextInstance(parentContainer, text);
  12040. break;
  12041. }
  12042. break;
  12043. }
  12044. case HostComponent:
  12045. {
  12046. var parentType = returnFiber.type;
  12047. var parentProps = returnFiber.memoizedProps;
  12048. var parentInstance = returnFiber.stateNode;
  12049. switch (fiber.tag) {
  12050. case HostComponent:
  12051. var _type = fiber.type;
  12052. var _props = fiber.pendingProps;
  12053. didNotFindHydratableInstance(parentType, parentProps, parentInstance, _type);
  12054. break;
  12055. case HostText:
  12056. var _text = fiber.pendingProps;
  12057. didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, _text);
  12058. break;
  12059. case SuspenseComponent:
  12060. didNotFindHydratableSuspenseInstance(parentType, parentProps);
  12061. break;
  12062. }
  12063. break;
  12064. }
  12065. default:
  12066. return;
  12067. }
  12068. }
  12069. }
  12070. function tryHydrate(fiber, nextInstance) {
  12071. switch (fiber.tag) {
  12072. case HostComponent:
  12073. {
  12074. var type = fiber.type;
  12075. var props = fiber.pendingProps;
  12076. var instance = canHydrateInstance(nextInstance, type);
  12077. if (instance !== null) {
  12078. fiber.stateNode = instance;
  12079. return true;
  12080. }
  12081. return false;
  12082. }
  12083. case HostText:
  12084. {
  12085. var text = fiber.pendingProps;
  12086. var textInstance = canHydrateTextInstance(nextInstance, text);
  12087. if (textInstance !== null) {
  12088. fiber.stateNode = textInstance;
  12089. return true;
  12090. }
  12091. return false;
  12092. }
  12093. case SuspenseComponent:
  12094. {
  12095. return false;
  12096. }
  12097. default:
  12098. return false;
  12099. }
  12100. }
  12101. function tryToClaimNextHydratableInstance(fiber) {
  12102. if (!isHydrating) {
  12103. return;
  12104. }
  12105. var nextInstance = nextHydratableInstance;
  12106. if (!nextInstance) {
  12107. // Nothing to hydrate. Make it an insertion.
  12108. insertNonHydratedInstance(hydrationParentFiber, fiber);
  12109. isHydrating = false;
  12110. hydrationParentFiber = fiber;
  12111. return;
  12112. }
  12113. var firstAttemptedInstance = nextInstance;
  12114. if (!tryHydrate(fiber, nextInstance)) {
  12115. // If we can't hydrate this instance let's try the next one.
  12116. // We use this as a heuristic. It's based on intuition and not data so it
  12117. // might be flawed or unnecessary.
  12118. nextInstance = getNextHydratableSibling(firstAttemptedInstance);
  12119. if (!nextInstance || !tryHydrate(fiber, nextInstance)) {
  12120. // Nothing to hydrate. Make it an insertion.
  12121. insertNonHydratedInstance(hydrationParentFiber, fiber);
  12122. isHydrating = false;
  12123. hydrationParentFiber = fiber;
  12124. return;
  12125. } // We matched the next one, we'll now assume that the first one was
  12126. // superfluous and we'll delete it. Since we can't eagerly delete it
  12127. // we'll have to schedule a deletion. To do that, this node needs a dummy
  12128. // fiber associated with it.
  12129. deleteHydratableInstance(hydrationParentFiber, firstAttemptedInstance);
  12130. }
  12131. hydrationParentFiber = fiber;
  12132. nextHydratableInstance = getFirstHydratableChild(nextInstance);
  12133. }
  12134. function prepareToHydrateHostInstance(fiber, rootContainerInstance, hostContext) {
  12135. var instance = fiber.stateNode;
  12136. var updatePayload = hydrateInstance(instance, fiber.type, fiber.memoizedProps, rootContainerInstance, hostContext, fiber); // TODO: Type this specific to this type of component.
  12137. fiber.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
  12138. // is a new ref we mark this as an update.
  12139. if (updatePayload !== null) {
  12140. return true;
  12141. }
  12142. return false;
  12143. }
  12144. function prepareToHydrateHostTextInstance(fiber) {
  12145. var textInstance = fiber.stateNode;
  12146. var textContent = fiber.memoizedProps;
  12147. var shouldUpdate = hydrateTextInstance(textInstance, textContent, fiber);
  12148. {
  12149. if (shouldUpdate) {
  12150. // We assume that prepareToHydrateHostTextInstance is called in a context where the
  12151. // hydration parent is the parent host component of this host text.
  12152. var returnFiber = hydrationParentFiber;
  12153. if (returnFiber !== null) {
  12154. switch (returnFiber.tag) {
  12155. case HostRoot:
  12156. {
  12157. var parentContainer = returnFiber.stateNode.containerInfo;
  12158. didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, textContent);
  12159. break;
  12160. }
  12161. case HostComponent:
  12162. {
  12163. var parentType = returnFiber.type;
  12164. var parentProps = returnFiber.memoizedProps;
  12165. var parentInstance = returnFiber.stateNode;
  12166. didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, textContent);
  12167. break;
  12168. }
  12169. }
  12170. }
  12171. }
  12172. }
  12173. return shouldUpdate;
  12174. }
  12175. function skipPastDehydratedSuspenseInstance(fiber) {
  12176. var suspenseState = fiber.memoizedState;
  12177. var suspenseInstance = suspenseState !== null ? suspenseState.dehydrated : null;
  12178. if (!suspenseInstance) {
  12179. {
  12180. throw Error( "Expected to have a hydrated suspense instance. This error is likely caused by a bug in React. Please file an issue." );
  12181. }
  12182. }
  12183. return getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance);
  12184. }
  12185. function popToNextHostParent(fiber) {
  12186. var parent = fiber.return;
  12187. while (parent !== null && parent.tag !== HostComponent && parent.tag !== HostRoot && parent.tag !== SuspenseComponent) {
  12188. parent = parent.return;
  12189. }
  12190. hydrationParentFiber = parent;
  12191. }
  12192. function popHydrationState(fiber) {
  12193. if (fiber !== hydrationParentFiber) {
  12194. // We're deeper than the current hydration context, inside an inserted
  12195. // tree.
  12196. return false;
  12197. }
  12198. if (!isHydrating) {
  12199. // If we're not currently hydrating but we're in a hydration context, then
  12200. // we were an insertion and now need to pop up reenter hydration of our
  12201. // siblings.
  12202. popToNextHostParent(fiber);
  12203. isHydrating = true;
  12204. return false;
  12205. }
  12206. var type = fiber.type; // If we have any remaining hydratable nodes, we need to delete them now.
  12207. // We only do this deeper than head and body since they tend to have random
  12208. // other nodes in them. We also ignore components with pure text content in
  12209. // side of them.
  12210. // TODO: Better heuristic.
  12211. if (fiber.tag !== HostComponent || type !== 'head' && type !== 'body' && !shouldSetTextContent(type, fiber.memoizedProps)) {
  12212. var nextInstance = nextHydratableInstance;
  12213. while (nextInstance) {
  12214. deleteHydratableInstance(fiber, nextInstance);
  12215. nextInstance = getNextHydratableSibling(nextInstance);
  12216. }
  12217. }
  12218. popToNextHostParent(fiber);
  12219. if (fiber.tag === SuspenseComponent) {
  12220. nextHydratableInstance = skipPastDehydratedSuspenseInstance(fiber);
  12221. } else {
  12222. nextHydratableInstance = hydrationParentFiber ? getNextHydratableSibling(fiber.stateNode) : null;
  12223. }
  12224. return true;
  12225. }
  12226. function resetHydrationState() {
  12227. hydrationParentFiber = null;
  12228. nextHydratableInstance = null;
  12229. isHydrating = false;
  12230. }
  12231. function getIsHydrating() {
  12232. return isHydrating;
  12233. }
  12234. // and should be reset before starting a new render.
  12235. // This tracks which mutable sources need to be reset after a render.
  12236. var workInProgressSources = [];
  12237. var rendererSigil$1;
  12238. {
  12239. // Used to detect multiple renderers using the same mutable source.
  12240. rendererSigil$1 = {};
  12241. }
  12242. function markSourceAsDirty(mutableSource) {
  12243. workInProgressSources.push(mutableSource);
  12244. }
  12245. function resetWorkInProgressVersions() {
  12246. for (var i = 0; i < workInProgressSources.length; i++) {
  12247. var mutableSource = workInProgressSources[i];
  12248. {
  12249. mutableSource._workInProgressVersionPrimary = null;
  12250. }
  12251. }
  12252. workInProgressSources.length = 0;
  12253. }
  12254. function getWorkInProgressVersion(mutableSource) {
  12255. {
  12256. return mutableSource._workInProgressVersionPrimary;
  12257. }
  12258. }
  12259. function setWorkInProgressVersion(mutableSource, version) {
  12260. {
  12261. mutableSource._workInProgressVersionPrimary = version;
  12262. }
  12263. workInProgressSources.push(mutableSource);
  12264. }
  12265. function warnAboutMultipleRenderersDEV(mutableSource) {
  12266. {
  12267. {
  12268. if (mutableSource._currentPrimaryRenderer == null) {
  12269. mutableSource._currentPrimaryRenderer = rendererSigil$1;
  12270. } else if (mutableSource._currentPrimaryRenderer !== rendererSigil$1) {
  12271. error('Detected multiple renderers concurrently rendering the ' + 'same mutable source. This is currently unsupported.');
  12272. }
  12273. }
  12274. }
  12275. } // Eager reads the version of a mutable source and stores it on the root.
  12276. var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher,
  12277. ReactCurrentBatchConfig$1 = ReactSharedInternals.ReactCurrentBatchConfig;
  12278. var didWarnAboutMismatchedHooksForComponent;
  12279. var didWarnAboutUseOpaqueIdentifier;
  12280. {
  12281. didWarnAboutUseOpaqueIdentifier = {};
  12282. didWarnAboutMismatchedHooksForComponent = new Set();
  12283. }
  12284. // These are set right before calling the component.
  12285. var renderLanes = NoLanes; // The work-in-progress fiber. I've named it differently to distinguish it from
  12286. // the work-in-progress hook.
  12287. var currentlyRenderingFiber$1 = null; // Hooks are stored as a linked list on the fiber's memoizedState field. The
  12288. // current hook list is the list that belongs to the current fiber. The
  12289. // work-in-progress hook list is a new list that will be added to the
  12290. // work-in-progress fiber.
  12291. var currentHook = null;
  12292. var workInProgressHook = null; // Whether an update was scheduled at any point during the render phase. This
  12293. // does not get reset if we do another render pass; only when we're completely
  12294. // finished evaluating this component. This is an optimization so we know
  12295. // whether we need to clear render phase updates after a throw.
  12296. var didScheduleRenderPhaseUpdate = false; // Where an update was scheduled only during the current render pass. This
  12297. // gets reset after each attempt.
  12298. // TODO: Maybe there's some way to consolidate this with
  12299. // `didScheduleRenderPhaseUpdate`. Or with `numberOfReRenders`.
  12300. var didScheduleRenderPhaseUpdateDuringThisPass = false;
  12301. var RE_RENDER_LIMIT = 25; // In DEV, this is the name of the currently executing primitive hook
  12302. var currentHookNameInDev = null; // In DEV, this list ensures that hooks are called in the same order between renders.
  12303. // The list stores the order of hooks used during the initial render (mount).
  12304. // Subsequent renders (updates) reference this list.
  12305. var hookTypesDev = null;
  12306. var hookTypesUpdateIndexDev = -1; // In DEV, this tracks whether currently rendering component needs to ignore
  12307. // the dependencies for Hooks that need them (e.g. useEffect or useMemo).
  12308. // When true, such Hooks will always be "remounted". Only used during hot reload.
  12309. var ignorePreviousDependencies = false;
  12310. function mountHookTypesDev() {
  12311. {
  12312. var hookName = currentHookNameInDev;
  12313. if (hookTypesDev === null) {
  12314. hookTypesDev = [hookName];
  12315. } else {
  12316. hookTypesDev.push(hookName);
  12317. }
  12318. }
  12319. }
  12320. function updateHookTypesDev() {
  12321. {
  12322. var hookName = currentHookNameInDev;
  12323. if (hookTypesDev !== null) {
  12324. hookTypesUpdateIndexDev++;
  12325. if (hookTypesDev[hookTypesUpdateIndexDev] !== hookName) {
  12326. warnOnHookMismatchInDev(hookName);
  12327. }
  12328. }
  12329. }
  12330. }
  12331. function checkDepsAreArrayDev(deps) {
  12332. {
  12333. if (deps !== undefined && deps !== null && !Array.isArray(deps)) {
  12334. // Verify deps, but only on mount to avoid extra checks.
  12335. // It's unlikely their type would change as usually you define them inline.
  12336. error('%s received a final argument that is not an array (instead, received `%s`). When ' + 'specified, the final argument must be an array.', currentHookNameInDev, typeof deps);
  12337. }
  12338. }
  12339. }
  12340. function warnOnHookMismatchInDev(currentHookName) {
  12341. {
  12342. var componentName = getComponentName(currentlyRenderingFiber$1.type);
  12343. if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {
  12344. didWarnAboutMismatchedHooksForComponent.add(componentName);
  12345. if (hookTypesDev !== null) {
  12346. var table = '';
  12347. var secondColumnStart = 30;
  12348. for (var i = 0; i <= hookTypesUpdateIndexDev; i++) {
  12349. var oldHookName = hookTypesDev[i];
  12350. var newHookName = i === hookTypesUpdateIndexDev ? currentHookName : oldHookName;
  12351. var row = i + 1 + ". " + oldHookName; // Extra space so second column lines up
  12352. // lol @ IE not supporting String#repeat
  12353. while (row.length < secondColumnStart) {
  12354. row += ' ';
  12355. }
  12356. row += newHookName + '\n';
  12357. table += row;
  12358. }
  12359. error('React has detected a change in the order of Hooks called by %s. ' + 'This will lead to bugs and errors if not fixed. ' + 'For more information, read the Rules of Hooks: https://reactjs.org/link/rules-of-hooks\n\n' + ' Previous render Next render\n' + ' ------------------------------------------------------\n' + '%s' + ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', componentName, table);
  12360. }
  12361. }
  12362. }
  12363. }
  12364. function throwInvalidHookError() {
  12365. {
  12366. {
  12367. throw Error( "Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\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://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem." );
  12368. }
  12369. }
  12370. }
  12371. function areHookInputsEqual(nextDeps, prevDeps) {
  12372. {
  12373. if (ignorePreviousDependencies) {
  12374. // Only true when this component is being hot reloaded.
  12375. return false;
  12376. }
  12377. }
  12378. if (prevDeps === null) {
  12379. {
  12380. error('%s received a final argument during this render, but not during ' + 'the previous render. Even though the final argument is optional, ' + 'its type cannot change between renders.', currentHookNameInDev);
  12381. }
  12382. return false;
  12383. }
  12384. {
  12385. // Don't bother comparing lengths in prod because these arrays should be
  12386. // passed inline.
  12387. if (nextDeps.length !== prevDeps.length) {
  12388. error('The final argument passed to %s changed size between renders. The ' + 'order and size of this array must remain constant.\n\n' + 'Previous: %s\n' + 'Incoming: %s', currentHookNameInDev, "[" + prevDeps.join(', ') + "]", "[" + nextDeps.join(', ') + "]");
  12389. }
  12390. }
  12391. for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
  12392. if (objectIs(nextDeps[i], prevDeps[i])) {
  12393. continue;
  12394. }
  12395. return false;
  12396. }
  12397. return true;
  12398. }
  12399. function renderWithHooks(current, workInProgress, Component, props, secondArg, nextRenderLanes) {
  12400. renderLanes = nextRenderLanes;
  12401. currentlyRenderingFiber$1 = workInProgress;
  12402. {
  12403. hookTypesDev = current !== null ? current._debugHookTypes : null;
  12404. hookTypesUpdateIndexDev = -1; // Used for hot reloading:
  12405. ignorePreviousDependencies = current !== null && current.type !== workInProgress.type;
  12406. }
  12407. workInProgress.memoizedState = null;
  12408. workInProgress.updateQueue = null;
  12409. workInProgress.lanes = NoLanes; // The following should have already been reset
  12410. // currentHook = null;
  12411. // workInProgressHook = null;
  12412. // didScheduleRenderPhaseUpdate = false;
  12413. // TODO Warn if no hooks are used at all during mount, then some are used during update.
  12414. // Currently we will identify the update render as a mount because memoizedState === null.
  12415. // This is tricky because it's valid for certain types of components (e.g. React.lazy)
  12416. // Using memoizedState to differentiate between mount/update only works if at least one stateful hook is used.
  12417. // Non-stateful hooks (e.g. context) don't get added to memoizedState,
  12418. // so memoizedState would be null during updates and mounts.
  12419. {
  12420. if (current !== null && current.memoizedState !== null) {
  12421. ReactCurrentDispatcher$1.current = HooksDispatcherOnUpdateInDEV;
  12422. } else if (hookTypesDev !== null) {
  12423. // This dispatcher handles an edge case where a component is updating,
  12424. // but no stateful hooks have been used.
  12425. // We want to match the production code behavior (which will use HooksDispatcherOnMount),
  12426. // but with the extra DEV validation to ensure hooks ordering hasn't changed.
  12427. // This dispatcher does that.
  12428. ReactCurrentDispatcher$1.current = HooksDispatcherOnMountWithHookTypesInDEV;
  12429. } else {
  12430. ReactCurrentDispatcher$1.current = HooksDispatcherOnMountInDEV;
  12431. }
  12432. }
  12433. var children = Component(props, secondArg); // Check if there was a render phase update
  12434. if (didScheduleRenderPhaseUpdateDuringThisPass) {
  12435. // Keep rendering in a loop for as long as render phase updates continue to
  12436. // be scheduled. Use a counter to prevent infinite loops.
  12437. var numberOfReRenders = 0;
  12438. do {
  12439. didScheduleRenderPhaseUpdateDuringThisPass = false;
  12440. if (!(numberOfReRenders < RE_RENDER_LIMIT)) {
  12441. {
  12442. throw Error( "Too many re-renders. React limits the number of renders to prevent an infinite loop." );
  12443. }
  12444. }
  12445. numberOfReRenders += 1;
  12446. {
  12447. // Even when hot reloading, allow dependencies to stabilize
  12448. // after first render to prevent infinite render phase updates.
  12449. ignorePreviousDependencies = false;
  12450. } // Start over from the beginning of the list
  12451. currentHook = null;
  12452. workInProgressHook = null;
  12453. workInProgress.updateQueue = null;
  12454. {
  12455. // Also validate hook order for cascading updates.
  12456. hookTypesUpdateIndexDev = -1;
  12457. }
  12458. ReactCurrentDispatcher$1.current = HooksDispatcherOnRerenderInDEV ;
  12459. children = Component(props, secondArg);
  12460. } while (didScheduleRenderPhaseUpdateDuringThisPass);
  12461. } // We can assume the previous dispatcher is always this one, since we set it
  12462. // at the beginning of the render phase and there's no re-entrancy.
  12463. ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
  12464. {
  12465. workInProgress._debugHookTypes = hookTypesDev;
  12466. } // This check uses currentHook so that it works the same in DEV and prod bundles.
  12467. // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
  12468. var didRenderTooFewHooks = currentHook !== null && currentHook.next !== null;
  12469. renderLanes = NoLanes;
  12470. currentlyRenderingFiber$1 = null;
  12471. currentHook = null;
  12472. workInProgressHook = null;
  12473. {
  12474. currentHookNameInDev = null;
  12475. hookTypesDev = null;
  12476. hookTypesUpdateIndexDev = -1;
  12477. }
  12478. didScheduleRenderPhaseUpdate = false;
  12479. if (!!didRenderTooFewHooks) {
  12480. {
  12481. throw Error( "Rendered fewer hooks than expected. This may be caused by an accidental early return statement." );
  12482. }
  12483. }
  12484. return children;
  12485. }
  12486. function bailoutHooks(current, workInProgress, lanes) {
  12487. workInProgress.updateQueue = current.updateQueue;
  12488. workInProgress.flags &= ~(Passive | Update);
  12489. current.lanes = removeLanes(current.lanes, lanes);
  12490. }
  12491. function resetHooksAfterThrow() {
  12492. // We can assume the previous dispatcher is always this one, since we set it
  12493. // at the beginning of the render phase and there's no re-entrancy.
  12494. ReactCurrentDispatcher$1.current = ContextOnlyDispatcher;
  12495. if (didScheduleRenderPhaseUpdate) {
  12496. // There were render phase updates. These are only valid for this render
  12497. // phase, which we are now aborting. Remove the updates from the queues so
  12498. // they do not persist to the next render. Do not remove updates from hooks
  12499. // that weren't processed.
  12500. //
  12501. // Only reset the updates from the queue if it has a clone. If it does
  12502. // not have a clone, that means it wasn't processed, and the updates were
  12503. // scheduled before we entered the render phase.
  12504. var hook = currentlyRenderingFiber$1.memoizedState;
  12505. while (hook !== null) {
  12506. var queue = hook.queue;
  12507. if (queue !== null) {
  12508. queue.pending = null;
  12509. }
  12510. hook = hook.next;
  12511. }
  12512. didScheduleRenderPhaseUpdate = false;
  12513. }
  12514. renderLanes = NoLanes;
  12515. currentlyRenderingFiber$1 = null;
  12516. currentHook = null;
  12517. workInProgressHook = null;
  12518. {
  12519. hookTypesDev = null;
  12520. hookTypesUpdateIndexDev = -1;
  12521. currentHookNameInDev = null;
  12522. isUpdatingOpaqueValueInRenderPhase = false;
  12523. }
  12524. didScheduleRenderPhaseUpdateDuringThisPass = false;
  12525. }
  12526. function mountWorkInProgressHook() {
  12527. var hook = {
  12528. memoizedState: null,
  12529. baseState: null,
  12530. baseQueue: null,
  12531. queue: null,
  12532. next: null
  12533. };
  12534. if (workInProgressHook === null) {
  12535. // This is the first hook in the list
  12536. currentlyRenderingFiber$1.memoizedState = workInProgressHook = hook;
  12537. } else {
  12538. // Append to the end of the list
  12539. workInProgressHook = workInProgressHook.next = hook;
  12540. }
  12541. return workInProgressHook;
  12542. }
  12543. function updateWorkInProgressHook() {
  12544. // This function is used both for updates and for re-renders triggered by a
  12545. // render phase update. It assumes there is either a current hook we can
  12546. // clone, or a work-in-progress hook from a previous render pass that we can
  12547. // use as a base. When we reach the end of the base list, we must switch to
  12548. // the dispatcher used for mounts.
  12549. var nextCurrentHook;
  12550. if (currentHook === null) {
  12551. var current = currentlyRenderingFiber$1.alternate;
  12552. if (current !== null) {
  12553. nextCurrentHook = current.memoizedState;
  12554. } else {
  12555. nextCurrentHook = null;
  12556. }
  12557. } else {
  12558. nextCurrentHook = currentHook.next;
  12559. }
  12560. var nextWorkInProgressHook;
  12561. if (workInProgressHook === null) {
  12562. nextWorkInProgressHook = currentlyRenderingFiber$1.memoizedState;
  12563. } else {
  12564. nextWorkInProgressHook = workInProgressHook.next;
  12565. }
  12566. if (nextWorkInProgressHook !== null) {
  12567. // There's already a work-in-progress. Reuse it.
  12568. workInProgressHook = nextWorkInProgressHook;
  12569. nextWorkInProgressHook = workInProgressHook.next;
  12570. currentHook = nextCurrentHook;
  12571. } else {
  12572. // Clone from the current hook.
  12573. if (!(nextCurrentHook !== null)) {
  12574. {
  12575. throw Error( "Rendered more hooks than during the previous render." );
  12576. }
  12577. }
  12578. currentHook = nextCurrentHook;
  12579. var newHook = {
  12580. memoizedState: currentHook.memoizedState,
  12581. baseState: currentHook.baseState,
  12582. baseQueue: currentHook.baseQueue,
  12583. queue: currentHook.queue,
  12584. next: null
  12585. };
  12586. if (workInProgressHook === null) {
  12587. // This is the first hook in the list.
  12588. currentlyRenderingFiber$1.memoizedState = workInProgressHook = newHook;
  12589. } else {
  12590. // Append to the end of the list.
  12591. workInProgressHook = workInProgressHook.next = newHook;
  12592. }
  12593. }
  12594. return workInProgressHook;
  12595. }
  12596. function createFunctionComponentUpdateQueue() {
  12597. return {
  12598. lastEffect: null
  12599. };
  12600. }
  12601. function basicStateReducer(state, action) {
  12602. // $FlowFixMe: Flow doesn't like mixed types
  12603. return typeof action === 'function' ? action(state) : action;
  12604. }
  12605. function mountReducer(reducer, initialArg, init) {
  12606. var hook = mountWorkInProgressHook();
  12607. var initialState;
  12608. if (init !== undefined) {
  12609. initialState = init(initialArg);
  12610. } else {
  12611. initialState = initialArg;
  12612. }
  12613. hook.memoizedState = hook.baseState = initialState;
  12614. var queue = hook.queue = {
  12615. pending: null,
  12616. dispatch: null,
  12617. lastRenderedReducer: reducer,
  12618. lastRenderedState: initialState
  12619. };
  12620. var dispatch = queue.dispatch = dispatchAction.bind(null, currentlyRenderingFiber$1, queue);
  12621. return [hook.memoizedState, dispatch];
  12622. }
  12623. function updateReducer(reducer, initialArg, init) {
  12624. var hook = updateWorkInProgressHook();
  12625. var queue = hook.queue;
  12626. if (!(queue !== null)) {
  12627. {
  12628. throw Error( "Should have a queue. This is likely a bug in React. Please file an issue." );
  12629. }
  12630. }
  12631. queue.lastRenderedReducer = reducer;
  12632. var current = currentHook; // The last rebase update that is NOT part of the base state.
  12633. var baseQueue = current.baseQueue; // The last pending update that hasn't been processed yet.
  12634. var pendingQueue = queue.pending;
  12635. if (pendingQueue !== null) {
  12636. // We have new updates that haven't been processed yet.
  12637. // We'll add them to the base queue.
  12638. if (baseQueue !== null) {
  12639. // Merge the pending queue and the base queue.
  12640. var baseFirst = baseQueue.next;
  12641. var pendingFirst = pendingQueue.next;
  12642. baseQueue.next = pendingFirst;
  12643. pendingQueue.next = baseFirst;
  12644. }
  12645. {
  12646. if (current.baseQueue !== baseQueue) {
  12647. // Internal invariant that should never happen, but feasibly could in
  12648. // the future if we implement resuming, or some form of that.
  12649. error('Internal error: Expected work-in-progress queue to be a clone. ' + 'This is a bug in React.');
  12650. }
  12651. }
  12652. current.baseQueue = baseQueue = pendingQueue;
  12653. queue.pending = null;
  12654. }
  12655. if (baseQueue !== null) {
  12656. // We have a queue to process.
  12657. var first = baseQueue.next;
  12658. var newState = current.baseState;
  12659. var newBaseState = null;
  12660. var newBaseQueueFirst = null;
  12661. var newBaseQueueLast = null;
  12662. var update = first;
  12663. do {
  12664. var updateLane = update.lane;
  12665. if (!isSubsetOfLanes(renderLanes, updateLane)) {
  12666. // Priority is insufficient. Skip this update. If this is the first
  12667. // skipped update, the previous update/state is the new base
  12668. // update/state.
  12669. var clone = {
  12670. lane: updateLane,
  12671. action: update.action,
  12672. eagerReducer: update.eagerReducer,
  12673. eagerState: update.eagerState,
  12674. next: null
  12675. };
  12676. if (newBaseQueueLast === null) {
  12677. newBaseQueueFirst = newBaseQueueLast = clone;
  12678. newBaseState = newState;
  12679. } else {
  12680. newBaseQueueLast = newBaseQueueLast.next = clone;
  12681. } // Update the remaining priority in the queue.
  12682. // TODO: Don't need to accumulate this. Instead, we can remove
  12683. // renderLanes from the original lanes.
  12684. currentlyRenderingFiber$1.lanes = mergeLanes(currentlyRenderingFiber$1.lanes, updateLane);
  12685. markSkippedUpdateLanes(updateLane);
  12686. } else {
  12687. // This update does have sufficient priority.
  12688. if (newBaseQueueLast !== null) {
  12689. var _clone = {
  12690. // This update is going to be committed so we never want uncommit
  12691. // it. Using NoLane works because 0 is a subset of all bitmasks, so
  12692. // this will never be skipped by the check above.
  12693. lane: NoLane,
  12694. action: update.action,
  12695. eagerReducer: update.eagerReducer,
  12696. eagerState: update.eagerState,
  12697. next: null
  12698. };
  12699. newBaseQueueLast = newBaseQueueLast.next = _clone;
  12700. } // Process this update.
  12701. if (update.eagerReducer === reducer) {
  12702. // If this update was processed eagerly, and its reducer matches the
  12703. // current reducer, we can use the eagerly computed state.
  12704. newState = update.eagerState;
  12705. } else {
  12706. var action = update.action;
  12707. newState = reducer(newState, action);
  12708. }
  12709. }
  12710. update = update.next;
  12711. } while (update !== null && update !== first);
  12712. if (newBaseQueueLast === null) {
  12713. newBaseState = newState;
  12714. } else {
  12715. newBaseQueueLast.next = newBaseQueueFirst;
  12716. } // Mark that the fiber performed work, but only if the new state is
  12717. // different from the current state.
  12718. if (!objectIs(newState, hook.memoizedState)) {
  12719. markWorkInProgressReceivedUpdate();
  12720. }
  12721. hook.memoizedState = newState;
  12722. hook.baseState = newBaseState;
  12723. hook.baseQueue = newBaseQueueLast;
  12724. queue.lastRenderedState = newState;
  12725. }
  12726. var dispatch = queue.dispatch;
  12727. return [hook.memoizedState, dispatch];
  12728. }
  12729. function rerenderReducer(reducer, initialArg, init) {
  12730. var hook = updateWorkInProgressHook();
  12731. var queue = hook.queue;
  12732. if (!(queue !== null)) {
  12733. {
  12734. throw Error( "Should have a queue. This is likely a bug in React. Please file an issue." );
  12735. }
  12736. }
  12737. queue.lastRenderedReducer = reducer; // This is a re-render. Apply the new render phase updates to the previous
  12738. // work-in-progress hook.
  12739. var dispatch = queue.dispatch;
  12740. var lastRenderPhaseUpdate = queue.pending;
  12741. var newState = hook.memoizedState;
  12742. if (lastRenderPhaseUpdate !== null) {
  12743. // The queue doesn't persist past this render pass.
  12744. queue.pending = null;
  12745. var firstRenderPhaseUpdate = lastRenderPhaseUpdate.next;
  12746. var update = firstRenderPhaseUpdate;
  12747. do {
  12748. // Process this render phase update. We don't have to check the
  12749. // priority because it will always be the same as the current
  12750. // render's.
  12751. var action = update.action;
  12752. newState = reducer(newState, action);
  12753. update = update.next;
  12754. } while (update !== firstRenderPhaseUpdate); // Mark that the fiber performed work, but only if the new state is
  12755. // different from the current state.
  12756. if (!objectIs(newState, hook.memoizedState)) {
  12757. markWorkInProgressReceivedUpdate();
  12758. }
  12759. hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
  12760. // the base state unless the queue is empty.
  12761. // TODO: Not sure if this is the desired semantics, but it's what we
  12762. // do for gDSFP. I can't remember why.
  12763. if (hook.baseQueue === null) {
  12764. hook.baseState = newState;
  12765. }
  12766. queue.lastRenderedState = newState;
  12767. }
  12768. return [newState, dispatch];
  12769. }
  12770. function readFromUnsubcribedMutableSource(root, source, getSnapshot) {
  12771. {
  12772. warnAboutMultipleRenderersDEV(source);
  12773. }
  12774. var getVersion = source._getVersion;
  12775. var version = getVersion(source._source); // Is it safe for this component to read from this source during the current render?
  12776. var isSafeToReadFromSource = false; // Check the version first.
  12777. // If this render has already been started with a specific version,
  12778. // we can use it alone to determine if we can safely read from the source.
  12779. var currentRenderVersion = getWorkInProgressVersion(source);
  12780. if (currentRenderVersion !== null) {
  12781. // It's safe to read if the store hasn't been mutated since the last time
  12782. // we read something.
  12783. isSafeToReadFromSource = currentRenderVersion === version;
  12784. } else {
  12785. // If there's no version, then this is the first time we've read from the
  12786. // source during the current render pass, so we need to do a bit more work.
  12787. // What we need to determine is if there are any hooks that already
  12788. // subscribed to the source, and if so, whether there are any pending
  12789. // mutations that haven't been synchronized yet.
  12790. //
  12791. // If there are no pending mutations, then `root.mutableReadLanes` will be
  12792. // empty, and we know we can safely read.
  12793. //
  12794. // If there *are* pending mutations, we may still be able to safely read
  12795. // if the currently rendering lanes are inclusive of the pending mutation
  12796. // lanes, since that guarantees that the value we're about to read from
  12797. // the source is consistent with the values that we read during the most
  12798. // recent mutation.
  12799. isSafeToReadFromSource = isSubsetOfLanes(renderLanes, root.mutableReadLanes);
  12800. if (isSafeToReadFromSource) {
  12801. // If it's safe to read from this source during the current render,
  12802. // store the version in case other components read from it.
  12803. // A changed version number will let those components know to throw and restart the render.
  12804. setWorkInProgressVersion(source, version);
  12805. }
  12806. }
  12807. if (isSafeToReadFromSource) {
  12808. var snapshot = getSnapshot(source._source);
  12809. {
  12810. if (typeof snapshot === 'function') {
  12811. error('Mutable source should not return a function as the snapshot value. ' + 'Functions may close over mutable values and cause tearing.');
  12812. }
  12813. }
  12814. return snapshot;
  12815. } else {
  12816. // This handles the special case of a mutable source being shared between renderers.
  12817. // In that case, if the source is mutated between the first and second renderer,
  12818. // The second renderer don't know that it needs to reset the WIP version during unwind,
  12819. // (because the hook only marks sources as dirty if it's written to their WIP version).
  12820. // That would cause this tear check to throw again and eventually be visible to the user.
  12821. // We can avoid this infinite loop by explicitly marking the source as dirty.
  12822. //
  12823. // This can lead to tearing in the first renderer when it resumes,
  12824. // but there's nothing we can do about that (short of throwing here and refusing to continue the render).
  12825. markSourceAsDirty(source);
  12826. {
  12827. {
  12828. throw Error( "Cannot read from mutable source during the current render without tearing. This is a bug in React. Please file an issue." );
  12829. }
  12830. }
  12831. }
  12832. }
  12833. function useMutableSource(hook, source, getSnapshot, subscribe) {
  12834. var root = getWorkInProgressRoot();
  12835. if (!(root !== null)) {
  12836. {
  12837. throw Error( "Expected a work-in-progress root. This is a bug in React. Please file an issue." );
  12838. }
  12839. }
  12840. var getVersion = source._getVersion;
  12841. var version = getVersion(source._source);
  12842. var dispatcher = ReactCurrentDispatcher$1.current; // eslint-disable-next-line prefer-const
  12843. var _dispatcher$useState = dispatcher.useState(function () {
  12844. return readFromUnsubcribedMutableSource(root, source, getSnapshot);
  12845. }),
  12846. currentSnapshot = _dispatcher$useState[0],
  12847. setSnapshot = _dispatcher$useState[1];
  12848. var snapshot = currentSnapshot; // Grab a handle to the state hook as well.
  12849. // We use it to clear the pending update queue if we have a new source.
  12850. var stateHook = workInProgressHook;
  12851. var memoizedState = hook.memoizedState;
  12852. var refs = memoizedState.refs;
  12853. var prevGetSnapshot = refs.getSnapshot;
  12854. var prevSource = memoizedState.source;
  12855. var prevSubscribe = memoizedState.subscribe;
  12856. var fiber = currentlyRenderingFiber$1;
  12857. hook.memoizedState = {
  12858. refs: refs,
  12859. source: source,
  12860. subscribe: subscribe
  12861. }; // Sync the values needed by our subscription handler after each commit.
  12862. dispatcher.useEffect(function () {
  12863. refs.getSnapshot = getSnapshot; // Normally the dispatch function for a state hook never changes,
  12864. // but this hook recreates the queue in certain cases to avoid updates from stale sources.
  12865. // handleChange() below needs to reference the dispatch function without re-subscribing,
  12866. // so we use a ref to ensure that it always has the latest version.
  12867. refs.setSnapshot = setSnapshot; // Check for a possible change between when we last rendered now.
  12868. var maybeNewVersion = getVersion(source._source);
  12869. if (!objectIs(version, maybeNewVersion)) {
  12870. var maybeNewSnapshot = getSnapshot(source._source);
  12871. {
  12872. if (typeof maybeNewSnapshot === 'function') {
  12873. error('Mutable source should not return a function as the snapshot value. ' + 'Functions may close over mutable values and cause tearing.');
  12874. }
  12875. }
  12876. if (!objectIs(snapshot, maybeNewSnapshot)) {
  12877. setSnapshot(maybeNewSnapshot);
  12878. var lane = requestUpdateLane(fiber);
  12879. markRootMutableRead(root, lane);
  12880. } // If the source mutated between render and now,
  12881. // there may be state updates already scheduled from the old source.
  12882. // Entangle the updates so that they render in the same batch.
  12883. markRootEntangled(root, root.mutableReadLanes);
  12884. }
  12885. }, [getSnapshot, source, subscribe]); // If we got a new source or subscribe function, re-subscribe in a passive effect.
  12886. dispatcher.useEffect(function () {
  12887. var handleChange = function () {
  12888. var latestGetSnapshot = refs.getSnapshot;
  12889. var latestSetSnapshot = refs.setSnapshot;
  12890. try {
  12891. latestSetSnapshot(latestGetSnapshot(source._source)); // Record a pending mutable source update with the same expiration time.
  12892. var lane = requestUpdateLane(fiber);
  12893. markRootMutableRead(root, lane);
  12894. } catch (error) {
  12895. // A selector might throw after a source mutation.
  12896. // e.g. it might try to read from a part of the store that no longer exists.
  12897. // In this case we should still schedule an update with React.
  12898. // Worst case the selector will throw again and then an error boundary will handle it.
  12899. latestSetSnapshot(function () {
  12900. throw error;
  12901. });
  12902. }
  12903. };
  12904. var unsubscribe = subscribe(source._source, handleChange);
  12905. {
  12906. if (typeof unsubscribe !== 'function') {
  12907. error('Mutable source subscribe function must return an unsubscribe function.');
  12908. }
  12909. }
  12910. return unsubscribe;
  12911. }, [source, subscribe]); // If any of the inputs to useMutableSource change, reading is potentially unsafe.
  12912. //
  12913. // If either the source or the subscription have changed we can't can't trust the update queue.
  12914. // Maybe the source changed in a way that the old subscription ignored but the new one depends on.
  12915. //
  12916. // If the getSnapshot function changed, we also shouldn't rely on the update queue.
  12917. // It's possible that the underlying source was mutated between the when the last "change" event fired,
  12918. // and when the current render (with the new getSnapshot function) is processed.
  12919. //
  12920. // In both cases, we need to throw away pending updates (since they are no longer relevant)
  12921. // and treat reading from the source as we do in the mount case.
  12922. if (!objectIs(prevGetSnapshot, getSnapshot) || !objectIs(prevSource, source) || !objectIs(prevSubscribe, subscribe)) {
  12923. // Create a new queue and setState method,
  12924. // So if there are interleaved updates, they get pushed to the older queue.
  12925. // When this becomes current, the previous queue and dispatch method will be discarded,
  12926. // including any interleaving updates that occur.
  12927. var newQueue = {
  12928. pending: null,
  12929. dispatch: null,
  12930. lastRenderedReducer: basicStateReducer,
  12931. lastRenderedState: snapshot
  12932. };
  12933. newQueue.dispatch = setSnapshot = dispatchAction.bind(null, currentlyRenderingFiber$1, newQueue);
  12934. stateHook.queue = newQueue;
  12935. stateHook.baseQueue = null;
  12936. snapshot = readFromUnsubcribedMutableSource(root, source, getSnapshot);
  12937. stateHook.memoizedState = stateHook.baseState = snapshot;
  12938. }
  12939. return snapshot;
  12940. }
  12941. function mountMutableSource(source, getSnapshot, subscribe) {
  12942. var hook = mountWorkInProgressHook();
  12943. hook.memoizedState = {
  12944. refs: {
  12945. getSnapshot: getSnapshot,
  12946. setSnapshot: null
  12947. },
  12948. source: source,
  12949. subscribe: subscribe
  12950. };
  12951. return useMutableSource(hook, source, getSnapshot, subscribe);
  12952. }
  12953. function updateMutableSource(source, getSnapshot, subscribe) {
  12954. var hook = updateWorkInProgressHook();
  12955. return useMutableSource(hook, source, getSnapshot, subscribe);
  12956. }
  12957. function mountState(initialState) {
  12958. var hook = mountWorkInProgressHook();
  12959. if (typeof initialState === 'function') {
  12960. // $FlowFixMe: Flow doesn't like mixed types
  12961. initialState = initialState();
  12962. }
  12963. hook.memoizedState = hook.baseState = initialState;
  12964. var queue = hook.queue = {
  12965. pending: null,
  12966. dispatch: null,
  12967. lastRenderedReducer: basicStateReducer,
  12968. lastRenderedState: initialState
  12969. };
  12970. var dispatch = queue.dispatch = dispatchAction.bind(null, currentlyRenderingFiber$1, queue);
  12971. return [hook.memoizedState, dispatch];
  12972. }
  12973. function updateState(initialState) {
  12974. return updateReducer(basicStateReducer);
  12975. }
  12976. function rerenderState(initialState) {
  12977. return rerenderReducer(basicStateReducer);
  12978. }
  12979. function pushEffect(tag, create, destroy, deps) {
  12980. var effect = {
  12981. tag: tag,
  12982. create: create,
  12983. destroy: destroy,
  12984. deps: deps,
  12985. // Circular
  12986. next: null
  12987. };
  12988. var componentUpdateQueue = currentlyRenderingFiber$1.updateQueue;
  12989. if (componentUpdateQueue === null) {
  12990. componentUpdateQueue = createFunctionComponentUpdateQueue();
  12991. currentlyRenderingFiber$1.updateQueue = componentUpdateQueue;
  12992. componentUpdateQueue.lastEffect = effect.next = effect;
  12993. } else {
  12994. var lastEffect = componentUpdateQueue.lastEffect;
  12995. if (lastEffect === null) {
  12996. componentUpdateQueue.lastEffect = effect.next = effect;
  12997. } else {
  12998. var firstEffect = lastEffect.next;
  12999. lastEffect.next = effect;
  13000. effect.next = firstEffect;
  13001. componentUpdateQueue.lastEffect = effect;
  13002. }
  13003. }
  13004. return effect;
  13005. }
  13006. function mountRef(initialValue) {
  13007. var hook = mountWorkInProgressHook();
  13008. var ref = {
  13009. current: initialValue
  13010. };
  13011. {
  13012. Object.seal(ref);
  13013. }
  13014. hook.memoizedState = ref;
  13015. return ref;
  13016. }
  13017. function updateRef(initialValue) {
  13018. var hook = updateWorkInProgressHook();
  13019. return hook.memoizedState;
  13020. }
  13021. function mountEffectImpl(fiberFlags, hookFlags, create, deps) {
  13022. var hook = mountWorkInProgressHook();
  13023. var nextDeps = deps === undefined ? null : deps;
  13024. currentlyRenderingFiber$1.flags |= fiberFlags;
  13025. hook.memoizedState = pushEffect(HasEffect | hookFlags, create, undefined, nextDeps);
  13026. }
  13027. function updateEffectImpl(fiberFlags, hookFlags, create, deps) {
  13028. var hook = updateWorkInProgressHook();
  13029. var nextDeps = deps === undefined ? null : deps;
  13030. var destroy = undefined;
  13031. if (currentHook !== null) {
  13032. var prevEffect = currentHook.memoizedState;
  13033. destroy = prevEffect.destroy;
  13034. if (nextDeps !== null) {
  13035. var prevDeps = prevEffect.deps;
  13036. if (areHookInputsEqual(nextDeps, prevDeps)) {
  13037. pushEffect(hookFlags, create, destroy, nextDeps);
  13038. return;
  13039. }
  13040. }
  13041. }
  13042. currentlyRenderingFiber$1.flags |= fiberFlags;
  13043. hook.memoizedState = pushEffect(HasEffect | hookFlags, create, destroy, nextDeps);
  13044. }
  13045. function mountEffect(create, deps) {
  13046. {
  13047. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  13048. if ('undefined' !== typeof jest) {
  13049. warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
  13050. }
  13051. }
  13052. return mountEffectImpl(Update | Passive, Passive$1, create, deps);
  13053. }
  13054. function updateEffect(create, deps) {
  13055. {
  13056. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  13057. if ('undefined' !== typeof jest) {
  13058. warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber$1);
  13059. }
  13060. }
  13061. return updateEffectImpl(Update | Passive, Passive$1, create, deps);
  13062. }
  13063. function mountLayoutEffect(create, deps) {
  13064. return mountEffectImpl(Update, Layout, create, deps);
  13065. }
  13066. function updateLayoutEffect(create, deps) {
  13067. return updateEffectImpl(Update, Layout, create, deps);
  13068. }
  13069. function imperativeHandleEffect(create, ref) {
  13070. if (typeof ref === 'function') {
  13071. var refCallback = ref;
  13072. var _inst = create();
  13073. refCallback(_inst);
  13074. return function () {
  13075. refCallback(null);
  13076. };
  13077. } else if (ref !== null && ref !== undefined) {
  13078. var refObject = ref;
  13079. {
  13080. if (!refObject.hasOwnProperty('current')) {
  13081. error('Expected useImperativeHandle() first argument to either be a ' + 'ref callback or React.createRef() object. Instead received: %s.', 'an object with keys {' + Object.keys(refObject).join(', ') + '}');
  13082. }
  13083. }
  13084. var _inst2 = create();
  13085. refObject.current = _inst2;
  13086. return function () {
  13087. refObject.current = null;
  13088. };
  13089. }
  13090. }
  13091. function mountImperativeHandle(ref, create, deps) {
  13092. {
  13093. if (typeof create !== 'function') {
  13094. error('Expected useImperativeHandle() second argument to be a function ' + 'that creates a handle. Instead received: %s.', create !== null ? typeof create : 'null');
  13095. }
  13096. } // TODO: If deps are provided, should we skip comparing the ref itself?
  13097. var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  13098. return mountEffectImpl(Update, Layout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
  13099. }
  13100. function updateImperativeHandle(ref, create, deps) {
  13101. {
  13102. if (typeof create !== 'function') {
  13103. error('Expected useImperativeHandle() second argument to be a function ' + 'that creates a handle. Instead received: %s.', create !== null ? typeof create : 'null');
  13104. }
  13105. } // TODO: If deps are provided, should we skip comparing the ref itself?
  13106. var effectDeps = deps !== null && deps !== undefined ? deps.concat([ref]) : null;
  13107. return updateEffectImpl(Update, Layout, imperativeHandleEffect.bind(null, create, ref), effectDeps);
  13108. }
  13109. function mountDebugValue(value, formatterFn) {// This hook is normally a no-op.
  13110. // The react-debug-hooks package injects its own implementation
  13111. // so that e.g. DevTools can display custom hook values.
  13112. }
  13113. var updateDebugValue = mountDebugValue;
  13114. function mountCallback(callback, deps) {
  13115. var hook = mountWorkInProgressHook();
  13116. var nextDeps = deps === undefined ? null : deps;
  13117. hook.memoizedState = [callback, nextDeps];
  13118. return callback;
  13119. }
  13120. function updateCallback(callback, deps) {
  13121. var hook = updateWorkInProgressHook();
  13122. var nextDeps = deps === undefined ? null : deps;
  13123. var prevState = hook.memoizedState;
  13124. if (prevState !== null) {
  13125. if (nextDeps !== null) {
  13126. var prevDeps = prevState[1];
  13127. if (areHookInputsEqual(nextDeps, prevDeps)) {
  13128. return prevState[0];
  13129. }
  13130. }
  13131. }
  13132. hook.memoizedState = [callback, nextDeps];
  13133. return callback;
  13134. }
  13135. function mountMemo(nextCreate, deps) {
  13136. var hook = mountWorkInProgressHook();
  13137. var nextDeps = deps === undefined ? null : deps;
  13138. var nextValue = nextCreate();
  13139. hook.memoizedState = [nextValue, nextDeps];
  13140. return nextValue;
  13141. }
  13142. function updateMemo(nextCreate, deps) {
  13143. var hook = updateWorkInProgressHook();
  13144. var nextDeps = deps === undefined ? null : deps;
  13145. var prevState = hook.memoizedState;
  13146. if (prevState !== null) {
  13147. // Assume these are defined. If they're not, areHookInputsEqual will warn.
  13148. if (nextDeps !== null) {
  13149. var prevDeps = prevState[1];
  13150. if (areHookInputsEqual(nextDeps, prevDeps)) {
  13151. return prevState[0];
  13152. }
  13153. }
  13154. }
  13155. var nextValue = nextCreate();
  13156. hook.memoizedState = [nextValue, nextDeps];
  13157. return nextValue;
  13158. }
  13159. function mountDeferredValue(value) {
  13160. var _mountState = mountState(value),
  13161. prevValue = _mountState[0],
  13162. setValue = _mountState[1];
  13163. mountEffect(function () {
  13164. var prevTransition = ReactCurrentBatchConfig$1.transition;
  13165. ReactCurrentBatchConfig$1.transition = 1;
  13166. try {
  13167. setValue(value);
  13168. } finally {
  13169. ReactCurrentBatchConfig$1.transition = prevTransition;
  13170. }
  13171. }, [value]);
  13172. return prevValue;
  13173. }
  13174. function updateDeferredValue(value) {
  13175. var _updateState = updateState(),
  13176. prevValue = _updateState[0],
  13177. setValue = _updateState[1];
  13178. updateEffect(function () {
  13179. var prevTransition = ReactCurrentBatchConfig$1.transition;
  13180. ReactCurrentBatchConfig$1.transition = 1;
  13181. try {
  13182. setValue(value);
  13183. } finally {
  13184. ReactCurrentBatchConfig$1.transition = prevTransition;
  13185. }
  13186. }, [value]);
  13187. return prevValue;
  13188. }
  13189. function rerenderDeferredValue(value) {
  13190. var _rerenderState = rerenderState(),
  13191. prevValue = _rerenderState[0],
  13192. setValue = _rerenderState[1];
  13193. updateEffect(function () {
  13194. var prevTransition = ReactCurrentBatchConfig$1.transition;
  13195. ReactCurrentBatchConfig$1.transition = 1;
  13196. try {
  13197. setValue(value);
  13198. } finally {
  13199. ReactCurrentBatchConfig$1.transition = prevTransition;
  13200. }
  13201. }, [value]);
  13202. return prevValue;
  13203. }
  13204. function startTransition(setPending, callback) {
  13205. var priorityLevel = getCurrentPriorityLevel();
  13206. {
  13207. runWithPriority$1(priorityLevel < UserBlockingPriority$2 ? UserBlockingPriority$2 : priorityLevel, function () {
  13208. setPending(true);
  13209. });
  13210. runWithPriority$1(priorityLevel > NormalPriority$1 ? NormalPriority$1 : priorityLevel, function () {
  13211. var prevTransition = ReactCurrentBatchConfig$1.transition;
  13212. ReactCurrentBatchConfig$1.transition = 1;
  13213. try {
  13214. setPending(false);
  13215. callback();
  13216. } finally {
  13217. ReactCurrentBatchConfig$1.transition = prevTransition;
  13218. }
  13219. });
  13220. }
  13221. }
  13222. function mountTransition() {
  13223. var _mountState2 = mountState(false),
  13224. isPending = _mountState2[0],
  13225. setPending = _mountState2[1]; // The `start` method can be stored on a ref, since `setPending`
  13226. // never changes.
  13227. var start = startTransition.bind(null, setPending);
  13228. mountRef(start);
  13229. return [start, isPending];
  13230. }
  13231. function updateTransition() {
  13232. var _updateState2 = updateState(),
  13233. isPending = _updateState2[0];
  13234. var startRef = updateRef();
  13235. var start = startRef.current;
  13236. return [start, isPending];
  13237. }
  13238. function rerenderTransition() {
  13239. var _rerenderState2 = rerenderState(),
  13240. isPending = _rerenderState2[0];
  13241. var startRef = updateRef();
  13242. var start = startRef.current;
  13243. return [start, isPending];
  13244. }
  13245. var isUpdatingOpaqueValueInRenderPhase = false;
  13246. function getIsUpdatingOpaqueValueInRenderPhaseInDEV() {
  13247. {
  13248. return isUpdatingOpaqueValueInRenderPhase;
  13249. }
  13250. }
  13251. function warnOnOpaqueIdentifierAccessInDEV(fiber) {
  13252. {
  13253. // TODO: Should warn in effects and callbacks, too
  13254. var name = getComponentName(fiber.type) || 'Unknown';
  13255. if (getIsRendering() && !didWarnAboutUseOpaqueIdentifier[name]) {
  13256. error('The object passed back from useOpaqueIdentifier is meant to be ' + 'passed through to attributes only. Do not read the ' + 'value directly.');
  13257. didWarnAboutUseOpaqueIdentifier[name] = true;
  13258. }
  13259. }
  13260. }
  13261. function mountOpaqueIdentifier() {
  13262. var makeId = makeClientIdInDEV.bind(null, warnOnOpaqueIdentifierAccessInDEV.bind(null, currentlyRenderingFiber$1)) ;
  13263. if (getIsHydrating()) {
  13264. var didUpgrade = false;
  13265. var fiber = currentlyRenderingFiber$1;
  13266. var readValue = function () {
  13267. if (!didUpgrade) {
  13268. // Only upgrade once. This works even inside the render phase because
  13269. // the update is added to a shared queue, which outlasts the
  13270. // in-progress render.
  13271. didUpgrade = true;
  13272. {
  13273. isUpdatingOpaqueValueInRenderPhase = true;
  13274. setId(makeId());
  13275. isUpdatingOpaqueValueInRenderPhase = false;
  13276. warnOnOpaqueIdentifierAccessInDEV(fiber);
  13277. }
  13278. }
  13279. {
  13280. {
  13281. throw Error( "The object passed back from useOpaqueIdentifier is meant to be passed through to attributes only. Do not read the value directly." );
  13282. }
  13283. }
  13284. };
  13285. var id = makeOpaqueHydratingObject(readValue);
  13286. var setId = mountState(id)[1];
  13287. if ((currentlyRenderingFiber$1.mode & BlockingMode) === NoMode) {
  13288. currentlyRenderingFiber$1.flags |= Update | Passive;
  13289. pushEffect(HasEffect | Passive$1, function () {
  13290. setId(makeId());
  13291. }, undefined, null);
  13292. }
  13293. return id;
  13294. } else {
  13295. var _id = makeId();
  13296. mountState(_id);
  13297. return _id;
  13298. }
  13299. }
  13300. function updateOpaqueIdentifier() {
  13301. var id = updateState()[0];
  13302. return id;
  13303. }
  13304. function rerenderOpaqueIdentifier() {
  13305. var id = rerenderState()[0];
  13306. return id;
  13307. }
  13308. function dispatchAction(fiber, queue, action) {
  13309. {
  13310. if (typeof arguments[3] === 'function') {
  13311. error("State updates from the useState() and useReducer() Hooks don't support the " + 'second callback argument. To execute a side effect after ' + 'rendering, declare it in the component body with useEffect().');
  13312. }
  13313. }
  13314. var eventTime = requestEventTime();
  13315. var lane = requestUpdateLane(fiber);
  13316. var update = {
  13317. lane: lane,
  13318. action: action,
  13319. eagerReducer: null,
  13320. eagerState: null,
  13321. next: null
  13322. }; // Append the update to the end of the list.
  13323. var pending = queue.pending;
  13324. if (pending === null) {
  13325. // This is the first update. Create a circular list.
  13326. update.next = update;
  13327. } else {
  13328. update.next = pending.next;
  13329. pending.next = update;
  13330. }
  13331. queue.pending = update;
  13332. var alternate = fiber.alternate;
  13333. if (fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1) {
  13334. // This is a render phase update. Stash it in a lazily-created map of
  13335. // queue -> linked list of updates. After this render pass, we'll restart
  13336. // and apply the stashed updates on top of the work-in-progress hook.
  13337. didScheduleRenderPhaseUpdateDuringThisPass = didScheduleRenderPhaseUpdate = true;
  13338. } else {
  13339. if (fiber.lanes === NoLanes && (alternate === null || alternate.lanes === NoLanes)) {
  13340. // The queue is currently empty, which means we can eagerly compute the
  13341. // next state before entering the render phase. If the new state is the
  13342. // same as the current state, we may be able to bail out entirely.
  13343. var lastRenderedReducer = queue.lastRenderedReducer;
  13344. if (lastRenderedReducer !== null) {
  13345. var prevDispatcher;
  13346. {
  13347. prevDispatcher = ReactCurrentDispatcher$1.current;
  13348. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13349. }
  13350. try {
  13351. var currentState = queue.lastRenderedState;
  13352. var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
  13353. // it, on the update object. If the reducer hasn't changed by the
  13354. // time we enter the render phase, then the eager state can be used
  13355. // without calling the reducer again.
  13356. update.eagerReducer = lastRenderedReducer;
  13357. update.eagerState = eagerState;
  13358. if (objectIs(eagerState, currentState)) {
  13359. // Fast path. We can bail out without scheduling React to re-render.
  13360. // It's still possible that we'll need to rebase this update later,
  13361. // if the component re-renders for a different reason and by that
  13362. // time the reducer has changed.
  13363. return;
  13364. }
  13365. } catch (error) {// Suppress the error. It will throw again in the render phase.
  13366. } finally {
  13367. {
  13368. ReactCurrentDispatcher$1.current = prevDispatcher;
  13369. }
  13370. }
  13371. }
  13372. }
  13373. {
  13374. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  13375. if ('undefined' !== typeof jest) {
  13376. warnIfNotScopedWithMatchingAct(fiber);
  13377. warnIfNotCurrentlyActingUpdatesInDev(fiber);
  13378. }
  13379. }
  13380. scheduleUpdateOnFiber(fiber, lane, eventTime);
  13381. }
  13382. }
  13383. var ContextOnlyDispatcher = {
  13384. readContext: readContext,
  13385. useCallback: throwInvalidHookError,
  13386. useContext: throwInvalidHookError,
  13387. useEffect: throwInvalidHookError,
  13388. useImperativeHandle: throwInvalidHookError,
  13389. useLayoutEffect: throwInvalidHookError,
  13390. useMemo: throwInvalidHookError,
  13391. useReducer: throwInvalidHookError,
  13392. useRef: throwInvalidHookError,
  13393. useState: throwInvalidHookError,
  13394. useDebugValue: throwInvalidHookError,
  13395. useDeferredValue: throwInvalidHookError,
  13396. useTransition: throwInvalidHookError,
  13397. useMutableSource: throwInvalidHookError,
  13398. useOpaqueIdentifier: throwInvalidHookError,
  13399. unstable_isNewReconciler: enableNewReconciler
  13400. };
  13401. var HooksDispatcherOnMountInDEV = null;
  13402. var HooksDispatcherOnMountWithHookTypesInDEV = null;
  13403. var HooksDispatcherOnUpdateInDEV = null;
  13404. var HooksDispatcherOnRerenderInDEV = null;
  13405. var InvalidNestedHooksDispatcherOnMountInDEV = null;
  13406. var InvalidNestedHooksDispatcherOnUpdateInDEV = null;
  13407. var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
  13408. {
  13409. var warnInvalidContextAccess = function () {
  13410. error('Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().');
  13411. };
  13412. var warnInvalidHookAccess = function () {
  13413. error('Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. ' + 'You can only call Hooks at the top level of your React function. ' + 'For more information, see ' + 'https://reactjs.org/link/rules-of-hooks');
  13414. };
  13415. HooksDispatcherOnMountInDEV = {
  13416. readContext: function (context, observedBits) {
  13417. return readContext(context, observedBits);
  13418. },
  13419. useCallback: function (callback, deps) {
  13420. currentHookNameInDev = 'useCallback';
  13421. mountHookTypesDev();
  13422. checkDepsAreArrayDev(deps);
  13423. return mountCallback(callback, deps);
  13424. },
  13425. useContext: function (context, observedBits) {
  13426. currentHookNameInDev = 'useContext';
  13427. mountHookTypesDev();
  13428. return readContext(context, observedBits);
  13429. },
  13430. useEffect: function (create, deps) {
  13431. currentHookNameInDev = 'useEffect';
  13432. mountHookTypesDev();
  13433. checkDepsAreArrayDev(deps);
  13434. return mountEffect(create, deps);
  13435. },
  13436. useImperativeHandle: function (ref, create, deps) {
  13437. currentHookNameInDev = 'useImperativeHandle';
  13438. mountHookTypesDev();
  13439. checkDepsAreArrayDev(deps);
  13440. return mountImperativeHandle(ref, create, deps);
  13441. },
  13442. useLayoutEffect: function (create, deps) {
  13443. currentHookNameInDev = 'useLayoutEffect';
  13444. mountHookTypesDev();
  13445. checkDepsAreArrayDev(deps);
  13446. return mountLayoutEffect(create, deps);
  13447. },
  13448. useMemo: function (create, deps) {
  13449. currentHookNameInDev = 'useMemo';
  13450. mountHookTypesDev();
  13451. checkDepsAreArrayDev(deps);
  13452. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13453. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13454. try {
  13455. return mountMemo(create, deps);
  13456. } finally {
  13457. ReactCurrentDispatcher$1.current = prevDispatcher;
  13458. }
  13459. },
  13460. useReducer: function (reducer, initialArg, init) {
  13461. currentHookNameInDev = 'useReducer';
  13462. mountHookTypesDev();
  13463. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13464. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13465. try {
  13466. return mountReducer(reducer, initialArg, init);
  13467. } finally {
  13468. ReactCurrentDispatcher$1.current = prevDispatcher;
  13469. }
  13470. },
  13471. useRef: function (initialValue) {
  13472. currentHookNameInDev = 'useRef';
  13473. mountHookTypesDev();
  13474. return mountRef(initialValue);
  13475. },
  13476. useState: function (initialState) {
  13477. currentHookNameInDev = 'useState';
  13478. mountHookTypesDev();
  13479. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13480. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13481. try {
  13482. return mountState(initialState);
  13483. } finally {
  13484. ReactCurrentDispatcher$1.current = prevDispatcher;
  13485. }
  13486. },
  13487. useDebugValue: function (value, formatterFn) {
  13488. currentHookNameInDev = 'useDebugValue';
  13489. mountHookTypesDev();
  13490. return mountDebugValue();
  13491. },
  13492. useDeferredValue: function (value) {
  13493. currentHookNameInDev = 'useDeferredValue';
  13494. mountHookTypesDev();
  13495. return mountDeferredValue(value);
  13496. },
  13497. useTransition: function () {
  13498. currentHookNameInDev = 'useTransition';
  13499. mountHookTypesDev();
  13500. return mountTransition();
  13501. },
  13502. useMutableSource: function (source, getSnapshot, subscribe) {
  13503. currentHookNameInDev = 'useMutableSource';
  13504. mountHookTypesDev();
  13505. return mountMutableSource(source, getSnapshot, subscribe);
  13506. },
  13507. useOpaqueIdentifier: function () {
  13508. currentHookNameInDev = 'useOpaqueIdentifier';
  13509. mountHookTypesDev();
  13510. return mountOpaqueIdentifier();
  13511. },
  13512. unstable_isNewReconciler: enableNewReconciler
  13513. };
  13514. HooksDispatcherOnMountWithHookTypesInDEV = {
  13515. readContext: function (context, observedBits) {
  13516. return readContext(context, observedBits);
  13517. },
  13518. useCallback: function (callback, deps) {
  13519. currentHookNameInDev = 'useCallback';
  13520. updateHookTypesDev();
  13521. return mountCallback(callback, deps);
  13522. },
  13523. useContext: function (context, observedBits) {
  13524. currentHookNameInDev = 'useContext';
  13525. updateHookTypesDev();
  13526. return readContext(context, observedBits);
  13527. },
  13528. useEffect: function (create, deps) {
  13529. currentHookNameInDev = 'useEffect';
  13530. updateHookTypesDev();
  13531. return mountEffect(create, deps);
  13532. },
  13533. useImperativeHandle: function (ref, create, deps) {
  13534. currentHookNameInDev = 'useImperativeHandle';
  13535. updateHookTypesDev();
  13536. return mountImperativeHandle(ref, create, deps);
  13537. },
  13538. useLayoutEffect: function (create, deps) {
  13539. currentHookNameInDev = 'useLayoutEffect';
  13540. updateHookTypesDev();
  13541. return mountLayoutEffect(create, deps);
  13542. },
  13543. useMemo: function (create, deps) {
  13544. currentHookNameInDev = 'useMemo';
  13545. updateHookTypesDev();
  13546. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13547. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13548. try {
  13549. return mountMemo(create, deps);
  13550. } finally {
  13551. ReactCurrentDispatcher$1.current = prevDispatcher;
  13552. }
  13553. },
  13554. useReducer: function (reducer, initialArg, init) {
  13555. currentHookNameInDev = 'useReducer';
  13556. updateHookTypesDev();
  13557. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13558. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13559. try {
  13560. return mountReducer(reducer, initialArg, init);
  13561. } finally {
  13562. ReactCurrentDispatcher$1.current = prevDispatcher;
  13563. }
  13564. },
  13565. useRef: function (initialValue) {
  13566. currentHookNameInDev = 'useRef';
  13567. updateHookTypesDev();
  13568. return mountRef(initialValue);
  13569. },
  13570. useState: function (initialState) {
  13571. currentHookNameInDev = 'useState';
  13572. updateHookTypesDev();
  13573. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13574. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13575. try {
  13576. return mountState(initialState);
  13577. } finally {
  13578. ReactCurrentDispatcher$1.current = prevDispatcher;
  13579. }
  13580. },
  13581. useDebugValue: function (value, formatterFn) {
  13582. currentHookNameInDev = 'useDebugValue';
  13583. updateHookTypesDev();
  13584. return mountDebugValue();
  13585. },
  13586. useDeferredValue: function (value) {
  13587. currentHookNameInDev = 'useDeferredValue';
  13588. updateHookTypesDev();
  13589. return mountDeferredValue(value);
  13590. },
  13591. useTransition: function () {
  13592. currentHookNameInDev = 'useTransition';
  13593. updateHookTypesDev();
  13594. return mountTransition();
  13595. },
  13596. useMutableSource: function (source, getSnapshot, subscribe) {
  13597. currentHookNameInDev = 'useMutableSource';
  13598. updateHookTypesDev();
  13599. return mountMutableSource(source, getSnapshot, subscribe);
  13600. },
  13601. useOpaqueIdentifier: function () {
  13602. currentHookNameInDev = 'useOpaqueIdentifier';
  13603. updateHookTypesDev();
  13604. return mountOpaqueIdentifier();
  13605. },
  13606. unstable_isNewReconciler: enableNewReconciler
  13607. };
  13608. HooksDispatcherOnUpdateInDEV = {
  13609. readContext: function (context, observedBits) {
  13610. return readContext(context, observedBits);
  13611. },
  13612. useCallback: function (callback, deps) {
  13613. currentHookNameInDev = 'useCallback';
  13614. updateHookTypesDev();
  13615. return updateCallback(callback, deps);
  13616. },
  13617. useContext: function (context, observedBits) {
  13618. currentHookNameInDev = 'useContext';
  13619. updateHookTypesDev();
  13620. return readContext(context, observedBits);
  13621. },
  13622. useEffect: function (create, deps) {
  13623. currentHookNameInDev = 'useEffect';
  13624. updateHookTypesDev();
  13625. return updateEffect(create, deps);
  13626. },
  13627. useImperativeHandle: function (ref, create, deps) {
  13628. currentHookNameInDev = 'useImperativeHandle';
  13629. updateHookTypesDev();
  13630. return updateImperativeHandle(ref, create, deps);
  13631. },
  13632. useLayoutEffect: function (create, deps) {
  13633. currentHookNameInDev = 'useLayoutEffect';
  13634. updateHookTypesDev();
  13635. return updateLayoutEffect(create, deps);
  13636. },
  13637. useMemo: function (create, deps) {
  13638. currentHookNameInDev = 'useMemo';
  13639. updateHookTypesDev();
  13640. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13641. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13642. try {
  13643. return updateMemo(create, deps);
  13644. } finally {
  13645. ReactCurrentDispatcher$1.current = prevDispatcher;
  13646. }
  13647. },
  13648. useReducer: function (reducer, initialArg, init) {
  13649. currentHookNameInDev = 'useReducer';
  13650. updateHookTypesDev();
  13651. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13652. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13653. try {
  13654. return updateReducer(reducer, initialArg, init);
  13655. } finally {
  13656. ReactCurrentDispatcher$1.current = prevDispatcher;
  13657. }
  13658. },
  13659. useRef: function (initialValue) {
  13660. currentHookNameInDev = 'useRef';
  13661. updateHookTypesDev();
  13662. return updateRef();
  13663. },
  13664. useState: function (initialState) {
  13665. currentHookNameInDev = 'useState';
  13666. updateHookTypesDev();
  13667. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13668. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13669. try {
  13670. return updateState(initialState);
  13671. } finally {
  13672. ReactCurrentDispatcher$1.current = prevDispatcher;
  13673. }
  13674. },
  13675. useDebugValue: function (value, formatterFn) {
  13676. currentHookNameInDev = 'useDebugValue';
  13677. updateHookTypesDev();
  13678. return updateDebugValue();
  13679. },
  13680. useDeferredValue: function (value) {
  13681. currentHookNameInDev = 'useDeferredValue';
  13682. updateHookTypesDev();
  13683. return updateDeferredValue(value);
  13684. },
  13685. useTransition: function () {
  13686. currentHookNameInDev = 'useTransition';
  13687. updateHookTypesDev();
  13688. return updateTransition();
  13689. },
  13690. useMutableSource: function (source, getSnapshot, subscribe) {
  13691. currentHookNameInDev = 'useMutableSource';
  13692. updateHookTypesDev();
  13693. return updateMutableSource(source, getSnapshot, subscribe);
  13694. },
  13695. useOpaqueIdentifier: function () {
  13696. currentHookNameInDev = 'useOpaqueIdentifier';
  13697. updateHookTypesDev();
  13698. return updateOpaqueIdentifier();
  13699. },
  13700. unstable_isNewReconciler: enableNewReconciler
  13701. };
  13702. HooksDispatcherOnRerenderInDEV = {
  13703. readContext: function (context, observedBits) {
  13704. return readContext(context, observedBits);
  13705. },
  13706. useCallback: function (callback, deps) {
  13707. currentHookNameInDev = 'useCallback';
  13708. updateHookTypesDev();
  13709. return updateCallback(callback, deps);
  13710. },
  13711. useContext: function (context, observedBits) {
  13712. currentHookNameInDev = 'useContext';
  13713. updateHookTypesDev();
  13714. return readContext(context, observedBits);
  13715. },
  13716. useEffect: function (create, deps) {
  13717. currentHookNameInDev = 'useEffect';
  13718. updateHookTypesDev();
  13719. return updateEffect(create, deps);
  13720. },
  13721. useImperativeHandle: function (ref, create, deps) {
  13722. currentHookNameInDev = 'useImperativeHandle';
  13723. updateHookTypesDev();
  13724. return updateImperativeHandle(ref, create, deps);
  13725. },
  13726. useLayoutEffect: function (create, deps) {
  13727. currentHookNameInDev = 'useLayoutEffect';
  13728. updateHookTypesDev();
  13729. return updateLayoutEffect(create, deps);
  13730. },
  13731. useMemo: function (create, deps) {
  13732. currentHookNameInDev = 'useMemo';
  13733. updateHookTypesDev();
  13734. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13735. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  13736. try {
  13737. return updateMemo(create, deps);
  13738. } finally {
  13739. ReactCurrentDispatcher$1.current = prevDispatcher;
  13740. }
  13741. },
  13742. useReducer: function (reducer, initialArg, init) {
  13743. currentHookNameInDev = 'useReducer';
  13744. updateHookTypesDev();
  13745. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13746. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  13747. try {
  13748. return rerenderReducer(reducer, initialArg, init);
  13749. } finally {
  13750. ReactCurrentDispatcher$1.current = prevDispatcher;
  13751. }
  13752. },
  13753. useRef: function (initialValue) {
  13754. currentHookNameInDev = 'useRef';
  13755. updateHookTypesDev();
  13756. return updateRef();
  13757. },
  13758. useState: function (initialState) {
  13759. currentHookNameInDev = 'useState';
  13760. updateHookTypesDev();
  13761. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13762. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnRerenderInDEV;
  13763. try {
  13764. return rerenderState(initialState);
  13765. } finally {
  13766. ReactCurrentDispatcher$1.current = prevDispatcher;
  13767. }
  13768. },
  13769. useDebugValue: function (value, formatterFn) {
  13770. currentHookNameInDev = 'useDebugValue';
  13771. updateHookTypesDev();
  13772. return updateDebugValue();
  13773. },
  13774. useDeferredValue: function (value) {
  13775. currentHookNameInDev = 'useDeferredValue';
  13776. updateHookTypesDev();
  13777. return rerenderDeferredValue(value);
  13778. },
  13779. useTransition: function () {
  13780. currentHookNameInDev = 'useTransition';
  13781. updateHookTypesDev();
  13782. return rerenderTransition();
  13783. },
  13784. useMutableSource: function (source, getSnapshot, subscribe) {
  13785. currentHookNameInDev = 'useMutableSource';
  13786. updateHookTypesDev();
  13787. return updateMutableSource(source, getSnapshot, subscribe);
  13788. },
  13789. useOpaqueIdentifier: function () {
  13790. currentHookNameInDev = 'useOpaqueIdentifier';
  13791. updateHookTypesDev();
  13792. return rerenderOpaqueIdentifier();
  13793. },
  13794. unstable_isNewReconciler: enableNewReconciler
  13795. };
  13796. InvalidNestedHooksDispatcherOnMountInDEV = {
  13797. readContext: function (context, observedBits) {
  13798. warnInvalidContextAccess();
  13799. return readContext(context, observedBits);
  13800. },
  13801. useCallback: function (callback, deps) {
  13802. currentHookNameInDev = 'useCallback';
  13803. warnInvalidHookAccess();
  13804. mountHookTypesDev();
  13805. return mountCallback(callback, deps);
  13806. },
  13807. useContext: function (context, observedBits) {
  13808. currentHookNameInDev = 'useContext';
  13809. warnInvalidHookAccess();
  13810. mountHookTypesDev();
  13811. return readContext(context, observedBits);
  13812. },
  13813. useEffect: function (create, deps) {
  13814. currentHookNameInDev = 'useEffect';
  13815. warnInvalidHookAccess();
  13816. mountHookTypesDev();
  13817. return mountEffect(create, deps);
  13818. },
  13819. useImperativeHandle: function (ref, create, deps) {
  13820. currentHookNameInDev = 'useImperativeHandle';
  13821. warnInvalidHookAccess();
  13822. mountHookTypesDev();
  13823. return mountImperativeHandle(ref, create, deps);
  13824. },
  13825. useLayoutEffect: function (create, deps) {
  13826. currentHookNameInDev = 'useLayoutEffect';
  13827. warnInvalidHookAccess();
  13828. mountHookTypesDev();
  13829. return mountLayoutEffect(create, deps);
  13830. },
  13831. useMemo: function (create, deps) {
  13832. currentHookNameInDev = 'useMemo';
  13833. warnInvalidHookAccess();
  13834. mountHookTypesDev();
  13835. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13836. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13837. try {
  13838. return mountMemo(create, deps);
  13839. } finally {
  13840. ReactCurrentDispatcher$1.current = prevDispatcher;
  13841. }
  13842. },
  13843. useReducer: function (reducer, initialArg, init) {
  13844. currentHookNameInDev = 'useReducer';
  13845. warnInvalidHookAccess();
  13846. mountHookTypesDev();
  13847. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13848. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13849. try {
  13850. return mountReducer(reducer, initialArg, init);
  13851. } finally {
  13852. ReactCurrentDispatcher$1.current = prevDispatcher;
  13853. }
  13854. },
  13855. useRef: function (initialValue) {
  13856. currentHookNameInDev = 'useRef';
  13857. warnInvalidHookAccess();
  13858. mountHookTypesDev();
  13859. return mountRef(initialValue);
  13860. },
  13861. useState: function (initialState) {
  13862. currentHookNameInDev = 'useState';
  13863. warnInvalidHookAccess();
  13864. mountHookTypesDev();
  13865. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13866. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnMountInDEV;
  13867. try {
  13868. return mountState(initialState);
  13869. } finally {
  13870. ReactCurrentDispatcher$1.current = prevDispatcher;
  13871. }
  13872. },
  13873. useDebugValue: function (value, formatterFn) {
  13874. currentHookNameInDev = 'useDebugValue';
  13875. warnInvalidHookAccess();
  13876. mountHookTypesDev();
  13877. return mountDebugValue();
  13878. },
  13879. useDeferredValue: function (value) {
  13880. currentHookNameInDev = 'useDeferredValue';
  13881. warnInvalidHookAccess();
  13882. mountHookTypesDev();
  13883. return mountDeferredValue(value);
  13884. },
  13885. useTransition: function () {
  13886. currentHookNameInDev = 'useTransition';
  13887. warnInvalidHookAccess();
  13888. mountHookTypesDev();
  13889. return mountTransition();
  13890. },
  13891. useMutableSource: function (source, getSnapshot, subscribe) {
  13892. currentHookNameInDev = 'useMutableSource';
  13893. warnInvalidHookAccess();
  13894. mountHookTypesDev();
  13895. return mountMutableSource(source, getSnapshot, subscribe);
  13896. },
  13897. useOpaqueIdentifier: function () {
  13898. currentHookNameInDev = 'useOpaqueIdentifier';
  13899. warnInvalidHookAccess();
  13900. mountHookTypesDev();
  13901. return mountOpaqueIdentifier();
  13902. },
  13903. unstable_isNewReconciler: enableNewReconciler
  13904. };
  13905. InvalidNestedHooksDispatcherOnUpdateInDEV = {
  13906. readContext: function (context, observedBits) {
  13907. warnInvalidContextAccess();
  13908. return readContext(context, observedBits);
  13909. },
  13910. useCallback: function (callback, deps) {
  13911. currentHookNameInDev = 'useCallback';
  13912. warnInvalidHookAccess();
  13913. updateHookTypesDev();
  13914. return updateCallback(callback, deps);
  13915. },
  13916. useContext: function (context, observedBits) {
  13917. currentHookNameInDev = 'useContext';
  13918. warnInvalidHookAccess();
  13919. updateHookTypesDev();
  13920. return readContext(context, observedBits);
  13921. },
  13922. useEffect: function (create, deps) {
  13923. currentHookNameInDev = 'useEffect';
  13924. warnInvalidHookAccess();
  13925. updateHookTypesDev();
  13926. return updateEffect(create, deps);
  13927. },
  13928. useImperativeHandle: function (ref, create, deps) {
  13929. currentHookNameInDev = 'useImperativeHandle';
  13930. warnInvalidHookAccess();
  13931. updateHookTypesDev();
  13932. return updateImperativeHandle(ref, create, deps);
  13933. },
  13934. useLayoutEffect: function (create, deps) {
  13935. currentHookNameInDev = 'useLayoutEffect';
  13936. warnInvalidHookAccess();
  13937. updateHookTypesDev();
  13938. return updateLayoutEffect(create, deps);
  13939. },
  13940. useMemo: function (create, deps) {
  13941. currentHookNameInDev = 'useMemo';
  13942. warnInvalidHookAccess();
  13943. updateHookTypesDev();
  13944. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13945. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13946. try {
  13947. return updateMemo(create, deps);
  13948. } finally {
  13949. ReactCurrentDispatcher$1.current = prevDispatcher;
  13950. }
  13951. },
  13952. useReducer: function (reducer, initialArg, init) {
  13953. currentHookNameInDev = 'useReducer';
  13954. warnInvalidHookAccess();
  13955. updateHookTypesDev();
  13956. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13957. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13958. try {
  13959. return updateReducer(reducer, initialArg, init);
  13960. } finally {
  13961. ReactCurrentDispatcher$1.current = prevDispatcher;
  13962. }
  13963. },
  13964. useRef: function (initialValue) {
  13965. currentHookNameInDev = 'useRef';
  13966. warnInvalidHookAccess();
  13967. updateHookTypesDev();
  13968. return updateRef();
  13969. },
  13970. useState: function (initialState) {
  13971. currentHookNameInDev = 'useState';
  13972. warnInvalidHookAccess();
  13973. updateHookTypesDev();
  13974. var prevDispatcher = ReactCurrentDispatcher$1.current;
  13975. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  13976. try {
  13977. return updateState(initialState);
  13978. } finally {
  13979. ReactCurrentDispatcher$1.current = prevDispatcher;
  13980. }
  13981. },
  13982. useDebugValue: function (value, formatterFn) {
  13983. currentHookNameInDev = 'useDebugValue';
  13984. warnInvalidHookAccess();
  13985. updateHookTypesDev();
  13986. return updateDebugValue();
  13987. },
  13988. useDeferredValue: function (value) {
  13989. currentHookNameInDev = 'useDeferredValue';
  13990. warnInvalidHookAccess();
  13991. updateHookTypesDev();
  13992. return updateDeferredValue(value);
  13993. },
  13994. useTransition: function () {
  13995. currentHookNameInDev = 'useTransition';
  13996. warnInvalidHookAccess();
  13997. updateHookTypesDev();
  13998. return updateTransition();
  13999. },
  14000. useMutableSource: function (source, getSnapshot, subscribe) {
  14001. currentHookNameInDev = 'useMutableSource';
  14002. warnInvalidHookAccess();
  14003. updateHookTypesDev();
  14004. return updateMutableSource(source, getSnapshot, subscribe);
  14005. },
  14006. useOpaqueIdentifier: function () {
  14007. currentHookNameInDev = 'useOpaqueIdentifier';
  14008. warnInvalidHookAccess();
  14009. updateHookTypesDev();
  14010. return updateOpaqueIdentifier();
  14011. },
  14012. unstable_isNewReconciler: enableNewReconciler
  14013. };
  14014. InvalidNestedHooksDispatcherOnRerenderInDEV = {
  14015. readContext: function (context, observedBits) {
  14016. warnInvalidContextAccess();
  14017. return readContext(context, observedBits);
  14018. },
  14019. useCallback: function (callback, deps) {
  14020. currentHookNameInDev = 'useCallback';
  14021. warnInvalidHookAccess();
  14022. updateHookTypesDev();
  14023. return updateCallback(callback, deps);
  14024. },
  14025. useContext: function (context, observedBits) {
  14026. currentHookNameInDev = 'useContext';
  14027. warnInvalidHookAccess();
  14028. updateHookTypesDev();
  14029. return readContext(context, observedBits);
  14030. },
  14031. useEffect: function (create, deps) {
  14032. currentHookNameInDev = 'useEffect';
  14033. warnInvalidHookAccess();
  14034. updateHookTypesDev();
  14035. return updateEffect(create, deps);
  14036. },
  14037. useImperativeHandle: function (ref, create, deps) {
  14038. currentHookNameInDev = 'useImperativeHandle';
  14039. warnInvalidHookAccess();
  14040. updateHookTypesDev();
  14041. return updateImperativeHandle(ref, create, deps);
  14042. },
  14043. useLayoutEffect: function (create, deps) {
  14044. currentHookNameInDev = 'useLayoutEffect';
  14045. warnInvalidHookAccess();
  14046. updateHookTypesDev();
  14047. return updateLayoutEffect(create, deps);
  14048. },
  14049. useMemo: function (create, deps) {
  14050. currentHookNameInDev = 'useMemo';
  14051. warnInvalidHookAccess();
  14052. updateHookTypesDev();
  14053. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14054. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  14055. try {
  14056. return updateMemo(create, deps);
  14057. } finally {
  14058. ReactCurrentDispatcher$1.current = prevDispatcher;
  14059. }
  14060. },
  14061. useReducer: function (reducer, initialArg, init) {
  14062. currentHookNameInDev = 'useReducer';
  14063. warnInvalidHookAccess();
  14064. updateHookTypesDev();
  14065. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14066. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  14067. try {
  14068. return rerenderReducer(reducer, initialArg, init);
  14069. } finally {
  14070. ReactCurrentDispatcher$1.current = prevDispatcher;
  14071. }
  14072. },
  14073. useRef: function (initialValue) {
  14074. currentHookNameInDev = 'useRef';
  14075. warnInvalidHookAccess();
  14076. updateHookTypesDev();
  14077. return updateRef();
  14078. },
  14079. useState: function (initialState) {
  14080. currentHookNameInDev = 'useState';
  14081. warnInvalidHookAccess();
  14082. updateHookTypesDev();
  14083. var prevDispatcher = ReactCurrentDispatcher$1.current;
  14084. ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
  14085. try {
  14086. return rerenderState(initialState);
  14087. } finally {
  14088. ReactCurrentDispatcher$1.current = prevDispatcher;
  14089. }
  14090. },
  14091. useDebugValue: function (value, formatterFn) {
  14092. currentHookNameInDev = 'useDebugValue';
  14093. warnInvalidHookAccess();
  14094. updateHookTypesDev();
  14095. return updateDebugValue();
  14096. },
  14097. useDeferredValue: function (value) {
  14098. currentHookNameInDev = 'useDeferredValue';
  14099. warnInvalidHookAccess();
  14100. updateHookTypesDev();
  14101. return rerenderDeferredValue(value);
  14102. },
  14103. useTransition: function () {
  14104. currentHookNameInDev = 'useTransition';
  14105. warnInvalidHookAccess();
  14106. updateHookTypesDev();
  14107. return rerenderTransition();
  14108. },
  14109. useMutableSource: function (source, getSnapshot, subscribe) {
  14110. currentHookNameInDev = 'useMutableSource';
  14111. warnInvalidHookAccess();
  14112. updateHookTypesDev();
  14113. return updateMutableSource(source, getSnapshot, subscribe);
  14114. },
  14115. useOpaqueIdentifier: function () {
  14116. currentHookNameInDev = 'useOpaqueIdentifier';
  14117. warnInvalidHookAccess();
  14118. updateHookTypesDev();
  14119. return rerenderOpaqueIdentifier();
  14120. },
  14121. unstable_isNewReconciler: enableNewReconciler
  14122. };
  14123. }
  14124. var now$1 = unstable_now;
  14125. var commitTime = 0;
  14126. var profilerStartTime = -1;
  14127. function getCommitTime() {
  14128. return commitTime;
  14129. }
  14130. function recordCommitTime() {
  14131. commitTime = now$1();
  14132. }
  14133. function startProfilerTimer(fiber) {
  14134. profilerStartTime = now$1();
  14135. if (fiber.actualStartTime < 0) {
  14136. fiber.actualStartTime = now$1();
  14137. }
  14138. }
  14139. function stopProfilerTimerIfRunning(fiber) {
  14140. profilerStartTime = -1;
  14141. }
  14142. function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
  14143. if (profilerStartTime >= 0) {
  14144. var elapsedTime = now$1() - profilerStartTime;
  14145. fiber.actualDuration += elapsedTime;
  14146. if (overrideBaseTime) {
  14147. fiber.selfBaseDuration = elapsedTime;
  14148. }
  14149. profilerStartTime = -1;
  14150. }
  14151. }
  14152. function transferActualDuration(fiber) {
  14153. // Transfer time spent rendering these children so we don't lose it
  14154. // after we rerender. This is used as a helper in special cases
  14155. // where we should count the work of multiple passes.
  14156. var child = fiber.child;
  14157. while (child) {
  14158. fiber.actualDuration += child.actualDuration;
  14159. child = child.sibling;
  14160. }
  14161. }
  14162. var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
  14163. var didReceiveUpdate = false;
  14164. var didWarnAboutBadClass;
  14165. var didWarnAboutModulePatternComponent;
  14166. var didWarnAboutContextTypeOnFunctionComponent;
  14167. var didWarnAboutGetDerivedStateOnFunctionComponent;
  14168. var didWarnAboutFunctionRefs;
  14169. var didWarnAboutReassigningProps;
  14170. var didWarnAboutRevealOrder;
  14171. var didWarnAboutTailOptions;
  14172. {
  14173. didWarnAboutBadClass = {};
  14174. didWarnAboutModulePatternComponent = {};
  14175. didWarnAboutContextTypeOnFunctionComponent = {};
  14176. didWarnAboutGetDerivedStateOnFunctionComponent = {};
  14177. didWarnAboutFunctionRefs = {};
  14178. didWarnAboutReassigningProps = false;
  14179. didWarnAboutRevealOrder = {};
  14180. didWarnAboutTailOptions = {};
  14181. }
  14182. function reconcileChildren(current, workInProgress, nextChildren, renderLanes) {
  14183. if (current === null) {
  14184. // If this is a fresh new component that hasn't been rendered yet, we
  14185. // won't update its child set by applying minimal side-effects. Instead,
  14186. // we will add them all to the child before it gets rendered. That means
  14187. // we can optimize this reconciliation pass by not tracking side-effects.
  14188. workInProgress.child = mountChildFibers(workInProgress, null, nextChildren, renderLanes);
  14189. } else {
  14190. // If the current child is the same as the work in progress, it means that
  14191. // we haven't yet started any work on these children. Therefore, we use
  14192. // the clone algorithm to create a copy of all the current children.
  14193. // If we had any progressed work already, that is invalid at this point so
  14194. // let's throw it out.
  14195. workInProgress.child = reconcileChildFibers(workInProgress, current.child, nextChildren, renderLanes);
  14196. }
  14197. }
  14198. function forceUnmountCurrentAndReconcile(current, workInProgress, nextChildren, renderLanes) {
  14199. // This function is fork of reconcileChildren. It's used in cases where we
  14200. // want to reconcile without matching against the existing set. This has the
  14201. // effect of all current children being unmounted; even if the type and key
  14202. // are the same, the old child is unmounted and a new child is created.
  14203. //
  14204. // To do this, we're going to go through the reconcile algorithm twice. In
  14205. // the first pass, we schedule a deletion for all the current children by
  14206. // passing null.
  14207. workInProgress.child = reconcileChildFibers(workInProgress, current.child, null, renderLanes); // In the second pass, we mount the new children. The trick here is that we
  14208. // pass null in place of where we usually pass the current child set. This has
  14209. // the effect of remounting all children regardless of whether their
  14210. // identities match.
  14211. workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderLanes);
  14212. }
  14213. function updateForwardRef(current, workInProgress, Component, nextProps, renderLanes) {
  14214. // TODO: current can be non-null here even if the component
  14215. // hasn't yet mounted. This happens after the first render suspends.
  14216. // We'll need to figure out if this is fine or can cause issues.
  14217. {
  14218. if (workInProgress.type !== workInProgress.elementType) {
  14219. // Lazy component props can't be validated in createElement
  14220. // because they're only guaranteed to be resolved here.
  14221. var innerPropTypes = Component.propTypes;
  14222. if (innerPropTypes) {
  14223. checkPropTypes(innerPropTypes, nextProps, // Resolved props
  14224. 'prop', getComponentName(Component));
  14225. }
  14226. }
  14227. }
  14228. var render = Component.render;
  14229. var ref = workInProgress.ref; // The rest is a fork of updateFunctionComponent
  14230. var nextChildren;
  14231. prepareToReadContext(workInProgress, renderLanes);
  14232. {
  14233. ReactCurrentOwner$1.current = workInProgress;
  14234. setIsRendering(true);
  14235. nextChildren = renderWithHooks(current, workInProgress, render, nextProps, ref, renderLanes);
  14236. if ( workInProgress.mode & StrictMode) {
  14237. disableLogs();
  14238. try {
  14239. nextChildren = renderWithHooks(current, workInProgress, render, nextProps, ref, renderLanes);
  14240. } finally {
  14241. reenableLogs();
  14242. }
  14243. }
  14244. setIsRendering(false);
  14245. }
  14246. if (current !== null && !didReceiveUpdate) {
  14247. bailoutHooks(current, workInProgress, renderLanes);
  14248. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  14249. } // React DevTools reads this flag.
  14250. workInProgress.flags |= PerformedWork;
  14251. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  14252. return workInProgress.child;
  14253. }
  14254. function updateMemoComponent(current, workInProgress, Component, nextProps, updateLanes, renderLanes) {
  14255. if (current === null) {
  14256. var type = Component.type;
  14257. if (isSimpleFunctionComponent(type) && Component.compare === null && // SimpleMemoComponent codepath doesn't resolve outer props either.
  14258. Component.defaultProps === undefined) {
  14259. var resolvedType = type;
  14260. {
  14261. resolvedType = resolveFunctionForHotReloading(type);
  14262. } // If this is a plain function component without default props,
  14263. // and with only the default shallow comparison, we upgrade it
  14264. // to a SimpleMemoComponent to allow fast path updates.
  14265. workInProgress.tag = SimpleMemoComponent;
  14266. workInProgress.type = resolvedType;
  14267. {
  14268. validateFunctionComponentInDev(workInProgress, type);
  14269. }
  14270. return updateSimpleMemoComponent(current, workInProgress, resolvedType, nextProps, updateLanes, renderLanes);
  14271. }
  14272. {
  14273. var innerPropTypes = type.propTypes;
  14274. if (innerPropTypes) {
  14275. // Inner memo component props aren't currently validated in createElement.
  14276. // We could move it there, but we'd still need this for lazy code path.
  14277. checkPropTypes(innerPropTypes, nextProps, // Resolved props
  14278. 'prop', getComponentName(type));
  14279. }
  14280. }
  14281. var child = createFiberFromTypeAndProps(Component.type, null, nextProps, workInProgress, workInProgress.mode, renderLanes);
  14282. child.ref = workInProgress.ref;
  14283. child.return = workInProgress;
  14284. workInProgress.child = child;
  14285. return child;
  14286. }
  14287. {
  14288. var _type = Component.type;
  14289. var _innerPropTypes = _type.propTypes;
  14290. if (_innerPropTypes) {
  14291. // Inner memo component props aren't currently validated in createElement.
  14292. // We could move it there, but we'd still need this for lazy code path.
  14293. checkPropTypes(_innerPropTypes, nextProps, // Resolved props
  14294. 'prop', getComponentName(_type));
  14295. }
  14296. }
  14297. var currentChild = current.child; // This is always exactly one child
  14298. if (!includesSomeLane(updateLanes, renderLanes)) {
  14299. // This will be the props with resolved defaultProps,
  14300. // unlike current.memoizedProps which will be the unresolved ones.
  14301. var prevProps = currentChild.memoizedProps; // Default to shallow comparison
  14302. var compare = Component.compare;
  14303. compare = compare !== null ? compare : shallowEqual;
  14304. if (compare(prevProps, nextProps) && current.ref === workInProgress.ref) {
  14305. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  14306. }
  14307. } // React DevTools reads this flag.
  14308. workInProgress.flags |= PerformedWork;
  14309. var newChild = createWorkInProgress(currentChild, nextProps);
  14310. newChild.ref = workInProgress.ref;
  14311. newChild.return = workInProgress;
  14312. workInProgress.child = newChild;
  14313. return newChild;
  14314. }
  14315. function updateSimpleMemoComponent(current, workInProgress, Component, nextProps, updateLanes, renderLanes) {
  14316. // TODO: current can be non-null here even if the component
  14317. // hasn't yet mounted. This happens when the inner render suspends.
  14318. // We'll need to figure out if this is fine or can cause issues.
  14319. {
  14320. if (workInProgress.type !== workInProgress.elementType) {
  14321. // Lazy component props can't be validated in createElement
  14322. // because they're only guaranteed to be resolved here.
  14323. var outerMemoType = workInProgress.elementType;
  14324. if (outerMemoType.$$typeof === REACT_LAZY_TYPE) {
  14325. // We warn when you define propTypes on lazy()
  14326. // so let's just skip over it to find memo() outer wrapper.
  14327. // Inner props for memo are validated later.
  14328. var lazyComponent = outerMemoType;
  14329. var payload = lazyComponent._payload;
  14330. var init = lazyComponent._init;
  14331. try {
  14332. outerMemoType = init(payload);
  14333. } catch (x) {
  14334. outerMemoType = null;
  14335. } // Inner propTypes will be validated in the function component path.
  14336. var outerPropTypes = outerMemoType && outerMemoType.propTypes;
  14337. if (outerPropTypes) {
  14338. checkPropTypes(outerPropTypes, nextProps, // Resolved (SimpleMemoComponent has no defaultProps)
  14339. 'prop', getComponentName(outerMemoType));
  14340. }
  14341. }
  14342. }
  14343. }
  14344. if (current !== null) {
  14345. var prevProps = current.memoizedProps;
  14346. if (shallowEqual(prevProps, nextProps) && current.ref === workInProgress.ref && ( // Prevent bailout if the implementation changed due to hot reload.
  14347. workInProgress.type === current.type )) {
  14348. didReceiveUpdate = false;
  14349. if (!includesSomeLane(renderLanes, updateLanes)) {
  14350. // The pending lanes were cleared at the beginning of beginWork. We're
  14351. // about to bail out, but there might be other lanes that weren't
  14352. // included in the current render. Usually, the priority level of the
  14353. // remaining updates is accumlated during the evaluation of the
  14354. // component (i.e. when processing the update queue). But since since
  14355. // we're bailing out early *without* evaluating the component, we need
  14356. // to account for it here, too. Reset to the value of the current fiber.
  14357. // NOTE: This only applies to SimpleMemoComponent, not MemoComponent,
  14358. // because a MemoComponent fiber does not have hooks or an update queue;
  14359. // rather, it wraps around an inner component, which may or may not
  14360. // contains hooks.
  14361. // TODO: Move the reset at in beginWork out of the common path so that
  14362. // this is no longer necessary.
  14363. workInProgress.lanes = current.lanes;
  14364. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  14365. } else if ((current.flags & ForceUpdateForLegacySuspense) !== NoFlags) {
  14366. // This is a special case that only exists for legacy mode.
  14367. // See https://github.com/facebook/react/pull/19216.
  14368. didReceiveUpdate = true;
  14369. }
  14370. }
  14371. }
  14372. return updateFunctionComponent(current, workInProgress, Component, nextProps, renderLanes);
  14373. }
  14374. function updateOffscreenComponent(current, workInProgress, renderLanes) {
  14375. var nextProps = workInProgress.pendingProps;
  14376. var nextChildren = nextProps.children;
  14377. var prevState = current !== null ? current.memoizedState : null;
  14378. if (nextProps.mode === 'hidden' || nextProps.mode === 'unstable-defer-without-hiding') {
  14379. if ((workInProgress.mode & ConcurrentMode) === NoMode) {
  14380. // In legacy sync mode, don't defer the subtree. Render it now.
  14381. // TODO: Figure out what we should do in Blocking mode.
  14382. var nextState = {
  14383. baseLanes: NoLanes
  14384. };
  14385. workInProgress.memoizedState = nextState;
  14386. pushRenderLanes(workInProgress, renderLanes);
  14387. } else if (!includesSomeLane(renderLanes, OffscreenLane)) {
  14388. var nextBaseLanes;
  14389. if (prevState !== null) {
  14390. var prevBaseLanes = prevState.baseLanes;
  14391. nextBaseLanes = mergeLanes(prevBaseLanes, renderLanes);
  14392. } else {
  14393. nextBaseLanes = renderLanes;
  14394. } // Schedule this fiber to re-render at offscreen priority. Then bailout.
  14395. {
  14396. markSpawnedWork(OffscreenLane);
  14397. }
  14398. workInProgress.lanes = workInProgress.childLanes = laneToLanes(OffscreenLane);
  14399. var _nextState = {
  14400. baseLanes: nextBaseLanes
  14401. };
  14402. workInProgress.memoizedState = _nextState; // We're about to bail out, but we need to push this to the stack anyway
  14403. // to avoid a push/pop misalignment.
  14404. pushRenderLanes(workInProgress, nextBaseLanes);
  14405. return null;
  14406. } else {
  14407. // Rendering at offscreen, so we can clear the base lanes.
  14408. var _nextState2 = {
  14409. baseLanes: NoLanes
  14410. };
  14411. workInProgress.memoizedState = _nextState2; // Push the lanes that were skipped when we bailed out.
  14412. var subtreeRenderLanes = prevState !== null ? prevState.baseLanes : renderLanes;
  14413. pushRenderLanes(workInProgress, subtreeRenderLanes);
  14414. }
  14415. } else {
  14416. var _subtreeRenderLanes;
  14417. if (prevState !== null) {
  14418. _subtreeRenderLanes = mergeLanes(prevState.baseLanes, renderLanes); // Since we're not hidden anymore, reset the state
  14419. workInProgress.memoizedState = null;
  14420. } else {
  14421. // We weren't previously hidden, and we still aren't, so there's nothing
  14422. // special to do. Need to push to the stack regardless, though, to avoid
  14423. // a push/pop misalignment.
  14424. _subtreeRenderLanes = renderLanes;
  14425. }
  14426. pushRenderLanes(workInProgress, _subtreeRenderLanes);
  14427. }
  14428. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  14429. return workInProgress.child;
  14430. } // Note: These happen to have identical begin phases, for now. We shouldn't hold
  14431. // ourselves to this constraint, though. If the behavior diverges, we should
  14432. // fork the function.
  14433. var updateLegacyHiddenComponent = updateOffscreenComponent;
  14434. function updateFragment(current, workInProgress, renderLanes) {
  14435. var nextChildren = workInProgress.pendingProps;
  14436. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  14437. return workInProgress.child;
  14438. }
  14439. function updateMode(current, workInProgress, renderLanes) {
  14440. var nextChildren = workInProgress.pendingProps.children;
  14441. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  14442. return workInProgress.child;
  14443. }
  14444. function updateProfiler(current, workInProgress, renderLanes) {
  14445. {
  14446. workInProgress.flags |= Update; // Reset effect durations for the next eventual effect phase.
  14447. // These are reset during render to allow the DevTools commit hook a chance to read them,
  14448. var stateNode = workInProgress.stateNode;
  14449. stateNode.effectDuration = 0;
  14450. stateNode.passiveEffectDuration = 0;
  14451. }
  14452. var nextProps = workInProgress.pendingProps;
  14453. var nextChildren = nextProps.children;
  14454. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  14455. return workInProgress.child;
  14456. }
  14457. function markRef(current, workInProgress) {
  14458. var ref = workInProgress.ref;
  14459. if (current === null && ref !== null || current !== null && current.ref !== ref) {
  14460. // Schedule a Ref effect
  14461. workInProgress.flags |= Ref;
  14462. }
  14463. }
  14464. function updateFunctionComponent(current, workInProgress, Component, nextProps, renderLanes) {
  14465. {
  14466. if (workInProgress.type !== workInProgress.elementType) {
  14467. // Lazy component props can't be validated in createElement
  14468. // because they're only guaranteed to be resolved here.
  14469. var innerPropTypes = Component.propTypes;
  14470. if (innerPropTypes) {
  14471. checkPropTypes(innerPropTypes, nextProps, // Resolved props
  14472. 'prop', getComponentName(Component));
  14473. }
  14474. }
  14475. }
  14476. var context;
  14477. {
  14478. var unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
  14479. context = getMaskedContext(workInProgress, unmaskedContext);
  14480. }
  14481. var nextChildren;
  14482. prepareToReadContext(workInProgress, renderLanes);
  14483. {
  14484. ReactCurrentOwner$1.current = workInProgress;
  14485. setIsRendering(true);
  14486. nextChildren = renderWithHooks(current, workInProgress, Component, nextProps, context, renderLanes);
  14487. if ( workInProgress.mode & StrictMode) {
  14488. disableLogs();
  14489. try {
  14490. nextChildren = renderWithHooks(current, workInProgress, Component, nextProps, context, renderLanes);
  14491. } finally {
  14492. reenableLogs();
  14493. }
  14494. }
  14495. setIsRendering(false);
  14496. }
  14497. if (current !== null && !didReceiveUpdate) {
  14498. bailoutHooks(current, workInProgress, renderLanes);
  14499. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  14500. } // React DevTools reads this flag.
  14501. workInProgress.flags |= PerformedWork;
  14502. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  14503. return workInProgress.child;
  14504. }
  14505. function updateClassComponent(current, workInProgress, Component, nextProps, renderLanes) {
  14506. {
  14507. if (workInProgress.type !== workInProgress.elementType) {
  14508. // Lazy component props can't be validated in createElement
  14509. // because they're only guaranteed to be resolved here.
  14510. var innerPropTypes = Component.propTypes;
  14511. if (innerPropTypes) {
  14512. checkPropTypes(innerPropTypes, nextProps, // Resolved props
  14513. 'prop', getComponentName(Component));
  14514. }
  14515. }
  14516. } // Push context providers early to prevent context stack mismatches.
  14517. // During mounting we don't know the child context yet as the instance doesn't exist.
  14518. // We will invalidate the child context in finishClassComponent() right after rendering.
  14519. var hasContext;
  14520. if (isContextProvider(Component)) {
  14521. hasContext = true;
  14522. pushContextProvider(workInProgress);
  14523. } else {
  14524. hasContext = false;
  14525. }
  14526. prepareToReadContext(workInProgress, renderLanes);
  14527. var instance = workInProgress.stateNode;
  14528. var shouldUpdate;
  14529. if (instance === null) {
  14530. if (current !== null) {
  14531. // A class component without an instance only mounts if it suspended
  14532. // inside a non-concurrent tree, in an inconsistent state. We want to
  14533. // treat it like a new mount, even though an empty version of it already
  14534. // committed. Disconnect the alternate pointers.
  14535. current.alternate = null;
  14536. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  14537. workInProgress.flags |= Placement;
  14538. } // In the initial pass we might need to construct the instance.
  14539. constructClassInstance(workInProgress, Component, nextProps);
  14540. mountClassInstance(workInProgress, Component, nextProps, renderLanes);
  14541. shouldUpdate = true;
  14542. } else if (current === null) {
  14543. // In a resume, we'll already have an instance we can reuse.
  14544. shouldUpdate = resumeMountClassInstance(workInProgress, Component, nextProps, renderLanes);
  14545. } else {
  14546. shouldUpdate = updateClassInstance(current, workInProgress, Component, nextProps, renderLanes);
  14547. }
  14548. var nextUnitOfWork = finishClassComponent(current, workInProgress, Component, shouldUpdate, hasContext, renderLanes);
  14549. {
  14550. var inst = workInProgress.stateNode;
  14551. if (shouldUpdate && inst.props !== nextProps) {
  14552. if (!didWarnAboutReassigningProps) {
  14553. error('It looks like %s is reassigning its own `this.props` while rendering. ' + 'This is not supported and can lead to confusing bugs.', getComponentName(workInProgress.type) || 'a component');
  14554. }
  14555. didWarnAboutReassigningProps = true;
  14556. }
  14557. }
  14558. return nextUnitOfWork;
  14559. }
  14560. function finishClassComponent(current, workInProgress, Component, shouldUpdate, hasContext, renderLanes) {
  14561. // Refs should update even if shouldComponentUpdate returns false
  14562. markRef(current, workInProgress);
  14563. var didCaptureError = (workInProgress.flags & DidCapture) !== NoFlags;
  14564. if (!shouldUpdate && !didCaptureError) {
  14565. // Context providers should defer to sCU for rendering
  14566. if (hasContext) {
  14567. invalidateContextProvider(workInProgress, Component, false);
  14568. }
  14569. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  14570. }
  14571. var instance = workInProgress.stateNode; // Rerender
  14572. ReactCurrentOwner$1.current = workInProgress;
  14573. var nextChildren;
  14574. if (didCaptureError && typeof Component.getDerivedStateFromError !== 'function') {
  14575. // If we captured an error, but getDerivedStateFromError is not defined,
  14576. // unmount all the children. componentDidCatch will schedule an update to
  14577. // re-render a fallback. This is temporary until we migrate everyone to
  14578. // the new API.
  14579. // TODO: Warn in a future release.
  14580. nextChildren = null;
  14581. {
  14582. stopProfilerTimerIfRunning();
  14583. }
  14584. } else {
  14585. {
  14586. setIsRendering(true);
  14587. nextChildren = instance.render();
  14588. if ( workInProgress.mode & StrictMode) {
  14589. disableLogs();
  14590. try {
  14591. instance.render();
  14592. } finally {
  14593. reenableLogs();
  14594. }
  14595. }
  14596. setIsRendering(false);
  14597. }
  14598. } // React DevTools reads this flag.
  14599. workInProgress.flags |= PerformedWork;
  14600. if (current !== null && didCaptureError) {
  14601. // If we're recovering from an error, reconcile without reusing any of
  14602. // the existing children. Conceptually, the normal children and the children
  14603. // that are shown on error are two different sets, so we shouldn't reuse
  14604. // normal children even if their identities match.
  14605. forceUnmountCurrentAndReconcile(current, workInProgress, nextChildren, renderLanes);
  14606. } else {
  14607. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  14608. } // Memoize state using the values we just used to render.
  14609. // TODO: Restructure so we never read values from the instance.
  14610. workInProgress.memoizedState = instance.state; // The context might have changed so we need to recalculate it.
  14611. if (hasContext) {
  14612. invalidateContextProvider(workInProgress, Component, true);
  14613. }
  14614. return workInProgress.child;
  14615. }
  14616. function pushHostRootContext(workInProgress) {
  14617. var root = workInProgress.stateNode;
  14618. if (root.pendingContext) {
  14619. pushTopLevelContextObject(workInProgress, root.pendingContext, root.pendingContext !== root.context);
  14620. } else if (root.context) {
  14621. // Should always be set
  14622. pushTopLevelContextObject(workInProgress, root.context, false);
  14623. }
  14624. pushHostContainer(workInProgress, root.containerInfo);
  14625. }
  14626. function updateHostRoot(current, workInProgress, renderLanes) {
  14627. pushHostRootContext(workInProgress);
  14628. var updateQueue = workInProgress.updateQueue;
  14629. if (!(current !== null && updateQueue !== null)) {
  14630. {
  14631. throw Error( "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." );
  14632. }
  14633. }
  14634. var nextProps = workInProgress.pendingProps;
  14635. var prevState = workInProgress.memoizedState;
  14636. var prevChildren = prevState !== null ? prevState.element : null;
  14637. cloneUpdateQueue(current, workInProgress);
  14638. processUpdateQueue(workInProgress, nextProps, null, renderLanes);
  14639. var nextState = workInProgress.memoizedState; // Caution: React DevTools currently depends on this property
  14640. // being called "element".
  14641. var nextChildren = nextState.element;
  14642. if (nextChildren === prevChildren) {
  14643. resetHydrationState();
  14644. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  14645. }
  14646. var root = workInProgress.stateNode;
  14647. if (root.hydrate && enterHydrationState(workInProgress)) {
  14648. // If we don't have any current children this might be the first pass.
  14649. // We always try to hydrate. If this isn't a hydration pass there won't
  14650. // be any children to hydrate which is effectively the same thing as
  14651. // not hydrating.
  14652. {
  14653. var mutableSourceEagerHydrationData = root.mutableSourceEagerHydrationData;
  14654. if (mutableSourceEagerHydrationData != null) {
  14655. for (var i = 0; i < mutableSourceEagerHydrationData.length; i += 2) {
  14656. var mutableSource = mutableSourceEagerHydrationData[i];
  14657. var version = mutableSourceEagerHydrationData[i + 1];
  14658. setWorkInProgressVersion(mutableSource, version);
  14659. }
  14660. }
  14661. }
  14662. var child = mountChildFibers(workInProgress, null, nextChildren, renderLanes);
  14663. workInProgress.child = child;
  14664. var node = child;
  14665. while (node) {
  14666. // Mark each child as hydrating. This is a fast path to know whether this
  14667. // tree is part of a hydrating tree. This is used to determine if a child
  14668. // node has fully mounted yet, and for scheduling event replaying.
  14669. // Conceptually this is similar to Placement in that a new subtree is
  14670. // inserted into the React tree here. It just happens to not need DOM
  14671. // mutations because it already exists.
  14672. node.flags = node.flags & ~Placement | Hydrating;
  14673. node = node.sibling;
  14674. }
  14675. } else {
  14676. // Otherwise reset hydration state in case we aborted and resumed another
  14677. // root.
  14678. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  14679. resetHydrationState();
  14680. }
  14681. return workInProgress.child;
  14682. }
  14683. function updateHostComponent(current, workInProgress, renderLanes) {
  14684. pushHostContext(workInProgress);
  14685. if (current === null) {
  14686. tryToClaimNextHydratableInstance(workInProgress);
  14687. }
  14688. var type = workInProgress.type;
  14689. var nextProps = workInProgress.pendingProps;
  14690. var prevProps = current !== null ? current.memoizedProps : null;
  14691. var nextChildren = nextProps.children;
  14692. var isDirectTextChild = shouldSetTextContent(type, nextProps);
  14693. if (isDirectTextChild) {
  14694. // We special case a direct text child of a host node. This is a common
  14695. // case. We won't handle it as a reified child. We will instead handle
  14696. // this in the host environment that also has access to this prop. That
  14697. // avoids allocating another HostText fiber and traversing it.
  14698. nextChildren = null;
  14699. } else if (prevProps !== null && shouldSetTextContent(type, prevProps)) {
  14700. // If we're switching from a direct text child to a normal child, or to
  14701. // empty, we need to schedule the text content to be reset.
  14702. workInProgress.flags |= ContentReset;
  14703. }
  14704. markRef(current, workInProgress);
  14705. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  14706. return workInProgress.child;
  14707. }
  14708. function updateHostText(current, workInProgress) {
  14709. if (current === null) {
  14710. tryToClaimNextHydratableInstance(workInProgress);
  14711. } // Nothing to do here. This is terminal. We'll do the completion step
  14712. // immediately after.
  14713. return null;
  14714. }
  14715. function mountLazyComponent(_current, workInProgress, elementType, updateLanes, renderLanes) {
  14716. if (_current !== null) {
  14717. // A lazy component only mounts if it suspended inside a non-
  14718. // concurrent tree, in an inconsistent state. We want to treat it like
  14719. // a new mount, even though an empty version of it already committed.
  14720. // Disconnect the alternate pointers.
  14721. _current.alternate = null;
  14722. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  14723. workInProgress.flags |= Placement;
  14724. }
  14725. var props = workInProgress.pendingProps;
  14726. var lazyComponent = elementType;
  14727. var payload = lazyComponent._payload;
  14728. var init = lazyComponent._init;
  14729. var Component = init(payload); // Store the unwrapped component in the type.
  14730. workInProgress.type = Component;
  14731. var resolvedTag = workInProgress.tag = resolveLazyComponentTag(Component);
  14732. var resolvedProps = resolveDefaultProps(Component, props);
  14733. var child;
  14734. switch (resolvedTag) {
  14735. case FunctionComponent:
  14736. {
  14737. {
  14738. validateFunctionComponentInDev(workInProgress, Component);
  14739. workInProgress.type = Component = resolveFunctionForHotReloading(Component);
  14740. }
  14741. child = updateFunctionComponent(null, workInProgress, Component, resolvedProps, renderLanes);
  14742. return child;
  14743. }
  14744. case ClassComponent:
  14745. {
  14746. {
  14747. workInProgress.type = Component = resolveClassForHotReloading(Component);
  14748. }
  14749. child = updateClassComponent(null, workInProgress, Component, resolvedProps, renderLanes);
  14750. return child;
  14751. }
  14752. case ForwardRef:
  14753. {
  14754. {
  14755. workInProgress.type = Component = resolveForwardRefForHotReloading(Component);
  14756. }
  14757. child = updateForwardRef(null, workInProgress, Component, resolvedProps, renderLanes);
  14758. return child;
  14759. }
  14760. case MemoComponent:
  14761. {
  14762. {
  14763. if (workInProgress.type !== workInProgress.elementType) {
  14764. var outerPropTypes = Component.propTypes;
  14765. if (outerPropTypes) {
  14766. checkPropTypes(outerPropTypes, resolvedProps, // Resolved for outer only
  14767. 'prop', getComponentName(Component));
  14768. }
  14769. }
  14770. }
  14771. child = updateMemoComponent(null, workInProgress, Component, resolveDefaultProps(Component.type, resolvedProps), // The inner type can have defaults too
  14772. updateLanes, renderLanes);
  14773. return child;
  14774. }
  14775. }
  14776. var hint = '';
  14777. {
  14778. if (Component !== null && typeof Component === 'object' && Component.$$typeof === REACT_LAZY_TYPE) {
  14779. hint = ' Did you wrap a component in React.lazy() more than once?';
  14780. }
  14781. } // This message intentionally doesn't mention ForwardRef or MemoComponent
  14782. // because the fact that it's a separate type of work is an
  14783. // implementation detail.
  14784. {
  14785. {
  14786. throw Error( "Element type is invalid. Received a promise that resolves to: " + Component + ". Lazy element type must resolve to a class or function." + hint );
  14787. }
  14788. }
  14789. }
  14790. function mountIncompleteClassComponent(_current, workInProgress, Component, nextProps, renderLanes) {
  14791. if (_current !== null) {
  14792. // An incomplete component only mounts if it suspended inside a non-
  14793. // concurrent tree, in an inconsistent state. We want to treat it like
  14794. // a new mount, even though an empty version of it already committed.
  14795. // Disconnect the alternate pointers.
  14796. _current.alternate = null;
  14797. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  14798. workInProgress.flags |= Placement;
  14799. } // Promote the fiber to a class and try rendering again.
  14800. workInProgress.tag = ClassComponent; // The rest of this function is a fork of `updateClassComponent`
  14801. // Push context providers early to prevent context stack mismatches.
  14802. // During mounting we don't know the child context yet as the instance doesn't exist.
  14803. // We will invalidate the child context in finishClassComponent() right after rendering.
  14804. var hasContext;
  14805. if (isContextProvider(Component)) {
  14806. hasContext = true;
  14807. pushContextProvider(workInProgress);
  14808. } else {
  14809. hasContext = false;
  14810. }
  14811. prepareToReadContext(workInProgress, renderLanes);
  14812. constructClassInstance(workInProgress, Component, nextProps);
  14813. mountClassInstance(workInProgress, Component, nextProps, renderLanes);
  14814. return finishClassComponent(null, workInProgress, Component, true, hasContext, renderLanes);
  14815. }
  14816. function mountIndeterminateComponent(_current, workInProgress, Component, renderLanes) {
  14817. if (_current !== null) {
  14818. // An indeterminate component only mounts if it suspended inside a non-
  14819. // concurrent tree, in an inconsistent state. We want to treat it like
  14820. // a new mount, even though an empty version of it already committed.
  14821. // Disconnect the alternate pointers.
  14822. _current.alternate = null;
  14823. workInProgress.alternate = null; // Since this is conceptually a new fiber, schedule a Placement effect
  14824. workInProgress.flags |= Placement;
  14825. }
  14826. var props = workInProgress.pendingProps;
  14827. var context;
  14828. {
  14829. var unmaskedContext = getUnmaskedContext(workInProgress, Component, false);
  14830. context = getMaskedContext(workInProgress, unmaskedContext);
  14831. }
  14832. prepareToReadContext(workInProgress, renderLanes);
  14833. var value;
  14834. {
  14835. if (Component.prototype && typeof Component.prototype.render === 'function') {
  14836. var componentName = getComponentName(Component) || 'Unknown';
  14837. if (!didWarnAboutBadClass[componentName]) {
  14838. error("The <%s /> component appears to have a render method, but doesn't extend React.Component. " + 'This is likely to cause errors. Change %s to extend React.Component instead.', componentName, componentName);
  14839. didWarnAboutBadClass[componentName] = true;
  14840. }
  14841. }
  14842. if (workInProgress.mode & StrictMode) {
  14843. ReactStrictModeWarnings.recordLegacyContextWarning(workInProgress, null);
  14844. }
  14845. setIsRendering(true);
  14846. ReactCurrentOwner$1.current = workInProgress;
  14847. value = renderWithHooks(null, workInProgress, Component, props, context, renderLanes);
  14848. setIsRendering(false);
  14849. } // React DevTools reads this flag.
  14850. workInProgress.flags |= PerformedWork;
  14851. {
  14852. // Support for module components is deprecated and is removed behind a flag.
  14853. // Whether or not it would crash later, we want to show a good message in DEV first.
  14854. if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
  14855. var _componentName = getComponentName(Component) || 'Unknown';
  14856. if (!didWarnAboutModulePatternComponent[_componentName]) {
  14857. error('The <%s /> component appears to be a function component that returns a class instance. ' + 'Change %s to a class that extends React.Component instead. ' + "If you can't use a class try assigning the prototype on the function as a workaround. " + "`%s.prototype = React.Component.prototype`. Don't use an arrow function since it " + 'cannot be called with `new` by React.', _componentName, _componentName, _componentName);
  14858. didWarnAboutModulePatternComponent[_componentName] = true;
  14859. }
  14860. }
  14861. }
  14862. if ( // Run these checks in production only if the flag is off.
  14863. // Eventually we'll delete this branch altogether.
  14864. typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
  14865. {
  14866. var _componentName2 = getComponentName(Component) || 'Unknown';
  14867. if (!didWarnAboutModulePatternComponent[_componentName2]) {
  14868. error('The <%s /> component appears to be a function component that returns a class instance. ' + 'Change %s to a class that extends React.Component instead. ' + "If you can't use a class try assigning the prototype on the function as a workaround. " + "`%s.prototype = React.Component.prototype`. Don't use an arrow function since it " + 'cannot be called with `new` by React.', _componentName2, _componentName2, _componentName2);
  14869. didWarnAboutModulePatternComponent[_componentName2] = true;
  14870. }
  14871. } // Proceed under the assumption that this is a class instance
  14872. workInProgress.tag = ClassComponent; // Throw out any hooks that were used.
  14873. workInProgress.memoizedState = null;
  14874. workInProgress.updateQueue = null; // Push context providers early to prevent context stack mismatches.
  14875. // During mounting we don't know the child context yet as the instance doesn't exist.
  14876. // We will invalidate the child context in finishClassComponent() right after rendering.
  14877. var hasContext = false;
  14878. if (isContextProvider(Component)) {
  14879. hasContext = true;
  14880. pushContextProvider(workInProgress);
  14881. } else {
  14882. hasContext = false;
  14883. }
  14884. workInProgress.memoizedState = value.state !== null && value.state !== undefined ? value.state : null;
  14885. initializeUpdateQueue(workInProgress);
  14886. var getDerivedStateFromProps = Component.getDerivedStateFromProps;
  14887. if (typeof getDerivedStateFromProps === 'function') {
  14888. applyDerivedStateFromProps(workInProgress, Component, getDerivedStateFromProps, props);
  14889. }
  14890. adoptClassInstance(workInProgress, value);
  14891. mountClassInstance(workInProgress, Component, props, renderLanes);
  14892. return finishClassComponent(null, workInProgress, Component, true, hasContext, renderLanes);
  14893. } else {
  14894. // Proceed under the assumption that this is a function component
  14895. workInProgress.tag = FunctionComponent;
  14896. {
  14897. if ( workInProgress.mode & StrictMode) {
  14898. disableLogs();
  14899. try {
  14900. value = renderWithHooks(null, workInProgress, Component, props, context, renderLanes);
  14901. } finally {
  14902. reenableLogs();
  14903. }
  14904. }
  14905. }
  14906. reconcileChildren(null, workInProgress, value, renderLanes);
  14907. {
  14908. validateFunctionComponentInDev(workInProgress, Component);
  14909. }
  14910. return workInProgress.child;
  14911. }
  14912. }
  14913. function validateFunctionComponentInDev(workInProgress, Component) {
  14914. {
  14915. if (Component) {
  14916. if (Component.childContextTypes) {
  14917. error('%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component');
  14918. }
  14919. }
  14920. if (workInProgress.ref !== null) {
  14921. var info = '';
  14922. var ownerName = getCurrentFiberOwnerNameInDevOrNull();
  14923. if (ownerName) {
  14924. info += '\n\nCheck the render method of `' + ownerName + '`.';
  14925. }
  14926. var warningKey = ownerName || workInProgress._debugID || '';
  14927. var debugSource = workInProgress._debugSource;
  14928. if (debugSource) {
  14929. warningKey = debugSource.fileName + ':' + debugSource.lineNumber;
  14930. }
  14931. if (!didWarnAboutFunctionRefs[warningKey]) {
  14932. didWarnAboutFunctionRefs[warningKey] = true;
  14933. error('Function components cannot be given refs. ' + 'Attempts to access this ref will fail. ' + 'Did you mean to use React.forwardRef()?%s', info);
  14934. }
  14935. }
  14936. if (typeof Component.getDerivedStateFromProps === 'function') {
  14937. var _componentName3 = getComponentName(Component) || 'Unknown';
  14938. if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName3]) {
  14939. error('%s: Function components do not support getDerivedStateFromProps.', _componentName3);
  14940. didWarnAboutGetDerivedStateOnFunctionComponent[_componentName3] = true;
  14941. }
  14942. }
  14943. if (typeof Component.contextType === 'object' && Component.contextType !== null) {
  14944. var _componentName4 = getComponentName(Component) || 'Unknown';
  14945. if (!didWarnAboutContextTypeOnFunctionComponent[_componentName4]) {
  14946. error('%s: Function components do not support contextType.', _componentName4);
  14947. didWarnAboutContextTypeOnFunctionComponent[_componentName4] = true;
  14948. }
  14949. }
  14950. }
  14951. }
  14952. var SUSPENDED_MARKER = {
  14953. dehydrated: null,
  14954. retryLane: NoLane
  14955. };
  14956. function mountSuspenseOffscreenState(renderLanes) {
  14957. return {
  14958. baseLanes: renderLanes
  14959. };
  14960. }
  14961. function updateSuspenseOffscreenState(prevOffscreenState, renderLanes) {
  14962. return {
  14963. baseLanes: mergeLanes(prevOffscreenState.baseLanes, renderLanes)
  14964. };
  14965. } // TODO: Probably should inline this back
  14966. function shouldRemainOnFallback(suspenseContext, current, workInProgress, renderLanes) {
  14967. // If we're already showing a fallback, there are cases where we need to
  14968. // remain on that fallback regardless of whether the content has resolved.
  14969. // For example, SuspenseList coordinates when nested content appears.
  14970. if (current !== null) {
  14971. var suspenseState = current.memoizedState;
  14972. if (suspenseState === null) {
  14973. // Currently showing content. Don't hide it, even if ForceSuspenseFallack
  14974. // is true. More precise name might be "ForceRemainSuspenseFallback".
  14975. // Note: This is a factoring smell. Can't remain on a fallback if there's
  14976. // no fallback to remain on.
  14977. return false;
  14978. }
  14979. } // Not currently showing content. Consult the Suspense context.
  14980. return hasSuspenseContext(suspenseContext, ForceSuspenseFallback);
  14981. }
  14982. function getRemainingWorkInPrimaryTree(current, renderLanes) {
  14983. // TODO: Should not remove render lanes that were pinged during this render
  14984. return removeLanes(current.childLanes, renderLanes);
  14985. }
  14986. function updateSuspenseComponent(current, workInProgress, renderLanes) {
  14987. var nextProps = workInProgress.pendingProps; // This is used by DevTools to force a boundary to suspend.
  14988. {
  14989. if (shouldSuspend(workInProgress)) {
  14990. workInProgress.flags |= DidCapture;
  14991. }
  14992. }
  14993. var suspenseContext = suspenseStackCursor.current;
  14994. var showFallback = false;
  14995. var didSuspend = (workInProgress.flags & DidCapture) !== NoFlags;
  14996. if (didSuspend || shouldRemainOnFallback(suspenseContext, current)) {
  14997. // Something in this boundary's subtree already suspended. Switch to
  14998. // rendering the fallback children.
  14999. showFallback = true;
  15000. workInProgress.flags &= ~DidCapture;
  15001. } else {
  15002. // Attempting the main content
  15003. if (current === null || current.memoizedState !== null) {
  15004. // This is a new mount or this boundary is already showing a fallback state.
  15005. // Mark this subtree context as having at least one invisible parent that could
  15006. // handle the fallback state.
  15007. // Boundaries without fallbacks or should be avoided are not considered since
  15008. // they cannot handle preferred fallback states.
  15009. if (nextProps.fallback !== undefined && nextProps.unstable_avoidThisFallback !== true) {
  15010. suspenseContext = addSubtreeSuspenseContext(suspenseContext, InvisibleParentSuspenseContext);
  15011. }
  15012. }
  15013. }
  15014. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  15015. pushSuspenseContext(workInProgress, suspenseContext); // OK, the next part is confusing. We're about to reconcile the Suspense
  15016. // boundary's children. This involves some custom reconcilation logic. Two
  15017. // main reasons this is so complicated.
  15018. //
  15019. // First, Legacy Mode has different semantics for backwards compatibility. The
  15020. // primary tree will commit in an inconsistent state, so when we do the
  15021. // second pass to render the fallback, we do some exceedingly, uh, clever
  15022. // hacks to make that not totally break. Like transferring effects and
  15023. // deletions from hidden tree. In Concurrent Mode, it's much simpler,
  15024. // because we bailout on the primary tree completely and leave it in its old
  15025. // state, no effects. Same as what we do for Offscreen (except that
  15026. // Offscreen doesn't have the first render pass).
  15027. //
  15028. // Second is hydration. During hydration, the Suspense fiber has a slightly
  15029. // different layout, where the child points to a dehydrated fragment, which
  15030. // contains the DOM rendered by the server.
  15031. //
  15032. // Third, even if you set all that aside, Suspense is like error boundaries in
  15033. // that we first we try to render one tree, and if that fails, we render again
  15034. // and switch to a different tree. Like a try/catch block. So we have to track
  15035. // which branch we're currently rendering. Ideally we would model this using
  15036. // a stack.
  15037. if (current === null) {
  15038. // Initial mount
  15039. // If we're currently hydrating, try to hydrate this boundary.
  15040. // But only if this has a fallback.
  15041. if (nextProps.fallback !== undefined) {
  15042. tryToClaimNextHydratableInstance(workInProgress); // This could've been a dehydrated suspense component.
  15043. }
  15044. var nextPrimaryChildren = nextProps.children;
  15045. var nextFallbackChildren = nextProps.fallback;
  15046. if (showFallback) {
  15047. var fallbackFragment = mountSuspenseFallbackChildren(workInProgress, nextPrimaryChildren, nextFallbackChildren, renderLanes);
  15048. var primaryChildFragment = workInProgress.child;
  15049. primaryChildFragment.memoizedState = mountSuspenseOffscreenState(renderLanes);
  15050. workInProgress.memoizedState = SUSPENDED_MARKER;
  15051. return fallbackFragment;
  15052. } else if (typeof nextProps.unstable_expectedLoadTime === 'number') {
  15053. // This is a CPU-bound tree. Skip this tree and show a placeholder to
  15054. // unblock the surrounding content. Then immediately retry after the
  15055. // initial commit.
  15056. var _fallbackFragment = mountSuspenseFallbackChildren(workInProgress, nextPrimaryChildren, nextFallbackChildren, renderLanes);
  15057. var _primaryChildFragment = workInProgress.child;
  15058. _primaryChildFragment.memoizedState = mountSuspenseOffscreenState(renderLanes);
  15059. workInProgress.memoizedState = SUSPENDED_MARKER; // Since nothing actually suspended, there will nothing to ping this to
  15060. // get it started back up to attempt the next item. While in terms of
  15061. // priority this work has the same priority as this current render, it's
  15062. // not part of the same transition once the transition has committed. If
  15063. // it's sync, we still want to yield so that it can be painted.
  15064. // Conceptually, this is really the same as pinging. We can use any
  15065. // RetryLane even if it's the one currently rendering since we're leaving
  15066. // it behind on this node.
  15067. workInProgress.lanes = SomeRetryLane;
  15068. {
  15069. markSpawnedWork(SomeRetryLane);
  15070. }
  15071. return _fallbackFragment;
  15072. } else {
  15073. return mountSuspensePrimaryChildren(workInProgress, nextPrimaryChildren, renderLanes);
  15074. }
  15075. } else {
  15076. // This is an update.
  15077. // If the current fiber has a SuspenseState, that means it's already showing
  15078. // a fallback.
  15079. var prevState = current.memoizedState;
  15080. if (prevState !== null) {
  15081. if (showFallback) {
  15082. var _nextFallbackChildren2 = nextProps.fallback;
  15083. var _nextPrimaryChildren2 = nextProps.children;
  15084. var _fallbackChildFragment = updateSuspenseFallbackChildren(current, workInProgress, _nextPrimaryChildren2, _nextFallbackChildren2, renderLanes);
  15085. var _primaryChildFragment3 = workInProgress.child;
  15086. var prevOffscreenState = current.child.memoizedState;
  15087. _primaryChildFragment3.memoizedState = prevOffscreenState === null ? mountSuspenseOffscreenState(renderLanes) : updateSuspenseOffscreenState(prevOffscreenState, renderLanes);
  15088. _primaryChildFragment3.childLanes = getRemainingWorkInPrimaryTree(current, renderLanes);
  15089. workInProgress.memoizedState = SUSPENDED_MARKER;
  15090. return _fallbackChildFragment;
  15091. } else {
  15092. var _nextPrimaryChildren3 = nextProps.children;
  15093. var _primaryChildFragment4 = updateSuspensePrimaryChildren(current, workInProgress, _nextPrimaryChildren3, renderLanes);
  15094. workInProgress.memoizedState = null;
  15095. return _primaryChildFragment4;
  15096. }
  15097. } else {
  15098. // The current tree is not already showing a fallback.
  15099. if (showFallback) {
  15100. // Timed out.
  15101. var _nextFallbackChildren3 = nextProps.fallback;
  15102. var _nextPrimaryChildren4 = nextProps.children;
  15103. var _fallbackChildFragment2 = updateSuspenseFallbackChildren(current, workInProgress, _nextPrimaryChildren4, _nextFallbackChildren3, renderLanes);
  15104. var _primaryChildFragment5 = workInProgress.child;
  15105. var _prevOffscreenState = current.child.memoizedState;
  15106. _primaryChildFragment5.memoizedState = _prevOffscreenState === null ? mountSuspenseOffscreenState(renderLanes) : updateSuspenseOffscreenState(_prevOffscreenState, renderLanes);
  15107. _primaryChildFragment5.childLanes = getRemainingWorkInPrimaryTree(current, renderLanes); // Skip the primary children, and continue working on the
  15108. // fallback children.
  15109. workInProgress.memoizedState = SUSPENDED_MARKER;
  15110. return _fallbackChildFragment2;
  15111. } else {
  15112. // Still haven't timed out. Continue rendering the children, like we
  15113. // normally do.
  15114. var _nextPrimaryChildren5 = nextProps.children;
  15115. var _primaryChildFragment6 = updateSuspensePrimaryChildren(current, workInProgress, _nextPrimaryChildren5, renderLanes);
  15116. workInProgress.memoizedState = null;
  15117. return _primaryChildFragment6;
  15118. }
  15119. }
  15120. }
  15121. }
  15122. function mountSuspensePrimaryChildren(workInProgress, primaryChildren, renderLanes) {
  15123. var mode = workInProgress.mode;
  15124. var primaryChildProps = {
  15125. mode: 'visible',
  15126. children: primaryChildren
  15127. };
  15128. var primaryChildFragment = createFiberFromOffscreen(primaryChildProps, mode, renderLanes, null);
  15129. primaryChildFragment.return = workInProgress;
  15130. workInProgress.child = primaryChildFragment;
  15131. return primaryChildFragment;
  15132. }
  15133. function mountSuspenseFallbackChildren(workInProgress, primaryChildren, fallbackChildren, renderLanes) {
  15134. var mode = workInProgress.mode;
  15135. var progressedPrimaryFragment = workInProgress.child;
  15136. var primaryChildProps = {
  15137. mode: 'hidden',
  15138. children: primaryChildren
  15139. };
  15140. var primaryChildFragment;
  15141. var fallbackChildFragment;
  15142. if ((mode & BlockingMode) === NoMode && progressedPrimaryFragment !== null) {
  15143. // In legacy mode, we commit the primary tree as if it successfully
  15144. // completed, even though it's in an inconsistent state.
  15145. primaryChildFragment = progressedPrimaryFragment;
  15146. primaryChildFragment.childLanes = NoLanes;
  15147. primaryChildFragment.pendingProps = primaryChildProps;
  15148. if ( workInProgress.mode & ProfileMode) {
  15149. // Reset the durations from the first pass so they aren't included in the
  15150. // final amounts. This seems counterintuitive, since we're intentionally
  15151. // not measuring part of the render phase, but this makes it match what we
  15152. // do in Concurrent Mode.
  15153. primaryChildFragment.actualDuration = 0;
  15154. primaryChildFragment.actualStartTime = -1;
  15155. primaryChildFragment.selfBaseDuration = 0;
  15156. primaryChildFragment.treeBaseDuration = 0;
  15157. }
  15158. fallbackChildFragment = createFiberFromFragment(fallbackChildren, mode, renderLanes, null);
  15159. } else {
  15160. primaryChildFragment = createFiberFromOffscreen(primaryChildProps, mode, NoLanes, null);
  15161. fallbackChildFragment = createFiberFromFragment(fallbackChildren, mode, renderLanes, null);
  15162. }
  15163. primaryChildFragment.return = workInProgress;
  15164. fallbackChildFragment.return = workInProgress;
  15165. primaryChildFragment.sibling = fallbackChildFragment;
  15166. workInProgress.child = primaryChildFragment;
  15167. return fallbackChildFragment;
  15168. }
  15169. function createWorkInProgressOffscreenFiber(current, offscreenProps) {
  15170. // The props argument to `createWorkInProgress` is `any` typed, so we use this
  15171. // wrapper function to constrain it.
  15172. return createWorkInProgress(current, offscreenProps);
  15173. }
  15174. function updateSuspensePrimaryChildren(current, workInProgress, primaryChildren, renderLanes) {
  15175. var currentPrimaryChildFragment = current.child;
  15176. var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
  15177. var primaryChildFragment = createWorkInProgressOffscreenFiber(currentPrimaryChildFragment, {
  15178. mode: 'visible',
  15179. children: primaryChildren
  15180. });
  15181. if ((workInProgress.mode & BlockingMode) === NoMode) {
  15182. primaryChildFragment.lanes = renderLanes;
  15183. }
  15184. primaryChildFragment.return = workInProgress;
  15185. primaryChildFragment.sibling = null;
  15186. if (currentFallbackChildFragment !== null) {
  15187. // Delete the fallback child fragment
  15188. currentFallbackChildFragment.nextEffect = null;
  15189. currentFallbackChildFragment.flags = Deletion;
  15190. workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChildFragment;
  15191. }
  15192. workInProgress.child = primaryChildFragment;
  15193. return primaryChildFragment;
  15194. }
  15195. function updateSuspenseFallbackChildren(current, workInProgress, primaryChildren, fallbackChildren, renderLanes) {
  15196. var mode = workInProgress.mode;
  15197. var currentPrimaryChildFragment = current.child;
  15198. var currentFallbackChildFragment = currentPrimaryChildFragment.sibling;
  15199. var primaryChildProps = {
  15200. mode: 'hidden',
  15201. children: primaryChildren
  15202. };
  15203. var primaryChildFragment;
  15204. if ( // In legacy mode, we commit the primary tree as if it successfully
  15205. // completed, even though it's in an inconsistent state.
  15206. (mode & BlockingMode) === NoMode && // Make sure we're on the second pass, i.e. the primary child fragment was
  15207. // already cloned. In legacy mode, the only case where this isn't true is
  15208. // when DevTools forces us to display a fallback; we skip the first render
  15209. // pass entirely and go straight to rendering the fallback. (In Concurrent
  15210. // Mode, SuspenseList can also trigger this scenario, but this is a legacy-
  15211. // only codepath.)
  15212. workInProgress.child !== currentPrimaryChildFragment) {
  15213. var progressedPrimaryFragment = workInProgress.child;
  15214. primaryChildFragment = progressedPrimaryFragment;
  15215. primaryChildFragment.childLanes = NoLanes;
  15216. primaryChildFragment.pendingProps = primaryChildProps;
  15217. if ( workInProgress.mode & ProfileMode) {
  15218. // Reset the durations from the first pass so they aren't included in the
  15219. // final amounts. This seems counterintuitive, since we're intentionally
  15220. // not measuring part of the render phase, but this makes it match what we
  15221. // do in Concurrent Mode.
  15222. primaryChildFragment.actualDuration = 0;
  15223. primaryChildFragment.actualStartTime = -1;
  15224. primaryChildFragment.selfBaseDuration = currentPrimaryChildFragment.selfBaseDuration;
  15225. primaryChildFragment.treeBaseDuration = currentPrimaryChildFragment.treeBaseDuration;
  15226. } // The fallback fiber was added as a deletion effect during the first pass.
  15227. // However, since we're going to remain on the fallback, we no longer want
  15228. // to delete it. So we need to remove it from the list. Deletions are stored
  15229. // on the same list as effects. We want to keep the effects from the primary
  15230. // tree. So we copy the primary child fragment's effect list, which does not
  15231. // include the fallback deletion effect.
  15232. var progressedLastEffect = primaryChildFragment.lastEffect;
  15233. if (progressedLastEffect !== null) {
  15234. workInProgress.firstEffect = primaryChildFragment.firstEffect;
  15235. workInProgress.lastEffect = progressedLastEffect;
  15236. progressedLastEffect.nextEffect = null;
  15237. } else {
  15238. // TODO: Reset this somewhere else? Lol legacy mode is so weird.
  15239. workInProgress.firstEffect = workInProgress.lastEffect = null;
  15240. }
  15241. } else {
  15242. primaryChildFragment = createWorkInProgressOffscreenFiber(currentPrimaryChildFragment, primaryChildProps);
  15243. }
  15244. var fallbackChildFragment;
  15245. if (currentFallbackChildFragment !== null) {
  15246. fallbackChildFragment = createWorkInProgress(currentFallbackChildFragment, fallbackChildren);
  15247. } else {
  15248. fallbackChildFragment = createFiberFromFragment(fallbackChildren, mode, renderLanes, null); // Needs a placement effect because the parent (the Suspense boundary) already
  15249. // mounted but this is a new fiber.
  15250. fallbackChildFragment.flags |= Placement;
  15251. }
  15252. fallbackChildFragment.return = workInProgress;
  15253. primaryChildFragment.return = workInProgress;
  15254. primaryChildFragment.sibling = fallbackChildFragment;
  15255. workInProgress.child = primaryChildFragment;
  15256. return fallbackChildFragment;
  15257. }
  15258. function scheduleWorkOnFiber(fiber, renderLanes) {
  15259. fiber.lanes = mergeLanes(fiber.lanes, renderLanes);
  15260. var alternate = fiber.alternate;
  15261. if (alternate !== null) {
  15262. alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
  15263. }
  15264. scheduleWorkOnParentPath(fiber.return, renderLanes);
  15265. }
  15266. function propagateSuspenseContextChange(workInProgress, firstChild, renderLanes) {
  15267. // Mark any Suspense boundaries with fallbacks as having work to do.
  15268. // If they were previously forced into fallbacks, they may now be able
  15269. // to unblock.
  15270. var node = firstChild;
  15271. while (node !== null) {
  15272. if (node.tag === SuspenseComponent) {
  15273. var state = node.memoizedState;
  15274. if (state !== null) {
  15275. scheduleWorkOnFiber(node, renderLanes);
  15276. }
  15277. } else if (node.tag === SuspenseListComponent) {
  15278. // If the tail is hidden there might not be an Suspense boundaries
  15279. // to schedule work on. In this case we have to schedule it on the
  15280. // list itself.
  15281. // We don't have to traverse to the children of the list since
  15282. // the list will propagate the change when it rerenders.
  15283. scheduleWorkOnFiber(node, renderLanes);
  15284. } else if (node.child !== null) {
  15285. node.child.return = node;
  15286. node = node.child;
  15287. continue;
  15288. }
  15289. if (node === workInProgress) {
  15290. return;
  15291. }
  15292. while (node.sibling === null) {
  15293. if (node.return === null || node.return === workInProgress) {
  15294. return;
  15295. }
  15296. node = node.return;
  15297. }
  15298. node.sibling.return = node.return;
  15299. node = node.sibling;
  15300. }
  15301. }
  15302. function findLastContentRow(firstChild) {
  15303. // This is going to find the last row among these children that is already
  15304. // showing content on the screen, as opposed to being in fallback state or
  15305. // new. If a row has multiple Suspense boundaries, any of them being in the
  15306. // fallback state, counts as the whole row being in a fallback state.
  15307. // Note that the "rows" will be workInProgress, but any nested children
  15308. // will still be current since we haven't rendered them yet. The mounted
  15309. // order may not be the same as the new order. We use the new order.
  15310. var row = firstChild;
  15311. var lastContentRow = null;
  15312. while (row !== null) {
  15313. var currentRow = row.alternate; // New rows can't be content rows.
  15314. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  15315. lastContentRow = row;
  15316. }
  15317. row = row.sibling;
  15318. }
  15319. return lastContentRow;
  15320. }
  15321. function validateRevealOrder(revealOrder) {
  15322. {
  15323. if (revealOrder !== undefined && revealOrder !== 'forwards' && revealOrder !== 'backwards' && revealOrder !== 'together' && !didWarnAboutRevealOrder[revealOrder]) {
  15324. didWarnAboutRevealOrder[revealOrder] = true;
  15325. if (typeof revealOrder === 'string') {
  15326. switch (revealOrder.toLowerCase()) {
  15327. case 'together':
  15328. case 'forwards':
  15329. case 'backwards':
  15330. {
  15331. error('"%s" is not a valid value for revealOrder on <SuspenseList />. ' + 'Use lowercase "%s" instead.', revealOrder, revealOrder.toLowerCase());
  15332. break;
  15333. }
  15334. case 'forward':
  15335. case 'backward':
  15336. {
  15337. error('"%s" is not a valid value for revealOrder on <SuspenseList />. ' + 'React uses the -s suffix in the spelling. Use "%ss" instead.', revealOrder, revealOrder.toLowerCase());
  15338. break;
  15339. }
  15340. default:
  15341. error('"%s" is not a supported revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
  15342. break;
  15343. }
  15344. } else {
  15345. error('%s is not a supported value for revealOrder on <SuspenseList />. ' + 'Did you mean "together", "forwards" or "backwards"?', revealOrder);
  15346. }
  15347. }
  15348. }
  15349. }
  15350. function validateTailOptions(tailMode, revealOrder) {
  15351. {
  15352. if (tailMode !== undefined && !didWarnAboutTailOptions[tailMode]) {
  15353. if (tailMode !== 'collapsed' && tailMode !== 'hidden') {
  15354. didWarnAboutTailOptions[tailMode] = true;
  15355. error('"%s" is not a supported value for tail on <SuspenseList />. ' + 'Did you mean "collapsed" or "hidden"?', tailMode);
  15356. } else if (revealOrder !== 'forwards' && revealOrder !== 'backwards') {
  15357. didWarnAboutTailOptions[tailMode] = true;
  15358. error('<SuspenseList tail="%s" /> is only valid if revealOrder is ' + '"forwards" or "backwards". ' + 'Did you mean to specify revealOrder="forwards"?', tailMode);
  15359. }
  15360. }
  15361. }
  15362. }
  15363. function validateSuspenseListNestedChild(childSlot, index) {
  15364. {
  15365. var isArray = Array.isArray(childSlot);
  15366. var isIterable = !isArray && typeof getIteratorFn(childSlot) === 'function';
  15367. if (isArray || isIterable) {
  15368. var type = isArray ? 'array' : 'iterable';
  15369. error('A nested %s was passed to row #%s in <SuspenseList />. Wrap it in ' + 'an additional SuspenseList to configure its revealOrder: ' + '<SuspenseList revealOrder=...> ... ' + '<SuspenseList revealOrder=...>{%s}</SuspenseList> ... ' + '</SuspenseList>', type, index, type);
  15370. return false;
  15371. }
  15372. }
  15373. return true;
  15374. }
  15375. function validateSuspenseListChildren(children, revealOrder) {
  15376. {
  15377. if ((revealOrder === 'forwards' || revealOrder === 'backwards') && children !== undefined && children !== null && children !== false) {
  15378. if (Array.isArray(children)) {
  15379. for (var i = 0; i < children.length; i++) {
  15380. if (!validateSuspenseListNestedChild(children[i], i)) {
  15381. return;
  15382. }
  15383. }
  15384. } else {
  15385. var iteratorFn = getIteratorFn(children);
  15386. if (typeof iteratorFn === 'function') {
  15387. var childrenIterator = iteratorFn.call(children);
  15388. if (childrenIterator) {
  15389. var step = childrenIterator.next();
  15390. var _i = 0;
  15391. for (; !step.done; step = childrenIterator.next()) {
  15392. if (!validateSuspenseListNestedChild(step.value, _i)) {
  15393. return;
  15394. }
  15395. _i++;
  15396. }
  15397. }
  15398. } else {
  15399. error('A single row was passed to a <SuspenseList revealOrder="%s" />. ' + 'This is not useful since it needs multiple rows. ' + 'Did you mean to pass multiple children or an array?', revealOrder);
  15400. }
  15401. }
  15402. }
  15403. }
  15404. }
  15405. function initSuspenseListRenderState(workInProgress, isBackwards, tail, lastContentRow, tailMode, lastEffectBeforeRendering) {
  15406. var renderState = workInProgress.memoizedState;
  15407. if (renderState === null) {
  15408. workInProgress.memoizedState = {
  15409. isBackwards: isBackwards,
  15410. rendering: null,
  15411. renderingStartTime: 0,
  15412. last: lastContentRow,
  15413. tail: tail,
  15414. tailMode: tailMode,
  15415. lastEffect: lastEffectBeforeRendering
  15416. };
  15417. } else {
  15418. // We can reuse the existing object from previous renders.
  15419. renderState.isBackwards = isBackwards;
  15420. renderState.rendering = null;
  15421. renderState.renderingStartTime = 0;
  15422. renderState.last = lastContentRow;
  15423. renderState.tail = tail;
  15424. renderState.tailMode = tailMode;
  15425. renderState.lastEffect = lastEffectBeforeRendering;
  15426. }
  15427. } // This can end up rendering this component multiple passes.
  15428. // The first pass splits the children fibers into two sets. A head and tail.
  15429. // We first render the head. If anything is in fallback state, we do another
  15430. // pass through beginWork to rerender all children (including the tail) with
  15431. // the force suspend context. If the first render didn't have anything in
  15432. // in fallback state. Then we render each row in the tail one-by-one.
  15433. // That happens in the completeWork phase without going back to beginWork.
  15434. function updateSuspenseListComponent(current, workInProgress, renderLanes) {
  15435. var nextProps = workInProgress.pendingProps;
  15436. var revealOrder = nextProps.revealOrder;
  15437. var tailMode = nextProps.tail;
  15438. var newChildren = nextProps.children;
  15439. validateRevealOrder(revealOrder);
  15440. validateTailOptions(tailMode, revealOrder);
  15441. validateSuspenseListChildren(newChildren, revealOrder);
  15442. reconcileChildren(current, workInProgress, newChildren, renderLanes);
  15443. var suspenseContext = suspenseStackCursor.current;
  15444. var shouldForceFallback = hasSuspenseContext(suspenseContext, ForceSuspenseFallback);
  15445. if (shouldForceFallback) {
  15446. suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
  15447. workInProgress.flags |= DidCapture;
  15448. } else {
  15449. var didSuspendBefore = current !== null && (current.flags & DidCapture) !== NoFlags;
  15450. if (didSuspendBefore) {
  15451. // If we previously forced a fallback, we need to schedule work
  15452. // on any nested boundaries to let them know to try to render
  15453. // again. This is the same as context updating.
  15454. propagateSuspenseContextChange(workInProgress, workInProgress.child, renderLanes);
  15455. }
  15456. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  15457. }
  15458. pushSuspenseContext(workInProgress, suspenseContext);
  15459. if ((workInProgress.mode & BlockingMode) === NoMode) {
  15460. // In legacy mode, SuspenseList doesn't work so we just
  15461. // use make it a noop by treating it as the default revealOrder.
  15462. workInProgress.memoizedState = null;
  15463. } else {
  15464. switch (revealOrder) {
  15465. case 'forwards':
  15466. {
  15467. var lastContentRow = findLastContentRow(workInProgress.child);
  15468. var tail;
  15469. if (lastContentRow === null) {
  15470. // The whole list is part of the tail.
  15471. // TODO: We could fast path by just rendering the tail now.
  15472. tail = workInProgress.child;
  15473. workInProgress.child = null;
  15474. } else {
  15475. // Disconnect the tail rows after the content row.
  15476. // We're going to render them separately later.
  15477. tail = lastContentRow.sibling;
  15478. lastContentRow.sibling = null;
  15479. }
  15480. initSuspenseListRenderState(workInProgress, false, // isBackwards
  15481. tail, lastContentRow, tailMode, workInProgress.lastEffect);
  15482. break;
  15483. }
  15484. case 'backwards':
  15485. {
  15486. // We're going to find the first row that has existing content.
  15487. // At the same time we're going to reverse the list of everything
  15488. // we pass in the meantime. That's going to be our tail in reverse
  15489. // order.
  15490. var _tail = null;
  15491. var row = workInProgress.child;
  15492. workInProgress.child = null;
  15493. while (row !== null) {
  15494. var currentRow = row.alternate; // New rows can't be content rows.
  15495. if (currentRow !== null && findFirstSuspended(currentRow) === null) {
  15496. // This is the beginning of the main content.
  15497. workInProgress.child = row;
  15498. break;
  15499. }
  15500. var nextRow = row.sibling;
  15501. row.sibling = _tail;
  15502. _tail = row;
  15503. row = nextRow;
  15504. } // TODO: If workInProgress.child is null, we can continue on the tail immediately.
  15505. initSuspenseListRenderState(workInProgress, true, // isBackwards
  15506. _tail, null, // last
  15507. tailMode, workInProgress.lastEffect);
  15508. break;
  15509. }
  15510. case 'together':
  15511. {
  15512. initSuspenseListRenderState(workInProgress, false, // isBackwards
  15513. null, // tail
  15514. null, // last
  15515. undefined, workInProgress.lastEffect);
  15516. break;
  15517. }
  15518. default:
  15519. {
  15520. // The default reveal order is the same as not having
  15521. // a boundary.
  15522. workInProgress.memoizedState = null;
  15523. }
  15524. }
  15525. }
  15526. return workInProgress.child;
  15527. }
  15528. function updatePortalComponent(current, workInProgress, renderLanes) {
  15529. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  15530. var nextChildren = workInProgress.pendingProps;
  15531. if (current === null) {
  15532. // Portals are special because we don't append the children during mount
  15533. // but at commit. Therefore we need to track insertions which the normal
  15534. // flow doesn't do during mount. This doesn't happen at the root because
  15535. // the root always starts with a "current" with a null child.
  15536. // TODO: Consider unifying this with how the root works.
  15537. workInProgress.child = reconcileChildFibers(workInProgress, null, nextChildren, renderLanes);
  15538. } else {
  15539. reconcileChildren(current, workInProgress, nextChildren, renderLanes);
  15540. }
  15541. return workInProgress.child;
  15542. }
  15543. var hasWarnedAboutUsingNoValuePropOnContextProvider = false;
  15544. function updateContextProvider(current, workInProgress, renderLanes) {
  15545. var providerType = workInProgress.type;
  15546. var context = providerType._context;
  15547. var newProps = workInProgress.pendingProps;
  15548. var oldProps = workInProgress.memoizedProps;
  15549. var newValue = newProps.value;
  15550. {
  15551. if (!('value' in newProps)) {
  15552. if (!hasWarnedAboutUsingNoValuePropOnContextProvider) {
  15553. hasWarnedAboutUsingNoValuePropOnContextProvider = true;
  15554. error('The `value` prop is required for the `<Context.Provider>`. Did you misspell it or forget to pass it?');
  15555. }
  15556. }
  15557. var providerPropTypes = workInProgress.type.propTypes;
  15558. if (providerPropTypes) {
  15559. checkPropTypes(providerPropTypes, newProps, 'prop', 'Context.Provider');
  15560. }
  15561. }
  15562. pushProvider(workInProgress, newValue);
  15563. if (oldProps !== null) {
  15564. var oldValue = oldProps.value;
  15565. var changedBits = calculateChangedBits(context, newValue, oldValue);
  15566. if (changedBits === 0) {
  15567. // No change. Bailout early if children are the same.
  15568. if (oldProps.children === newProps.children && !hasContextChanged()) {
  15569. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  15570. }
  15571. } else {
  15572. // The context value changed. Search for matching consumers and schedule
  15573. // them to update.
  15574. propagateContextChange(workInProgress, context, changedBits, renderLanes);
  15575. }
  15576. }
  15577. var newChildren = newProps.children;
  15578. reconcileChildren(current, workInProgress, newChildren, renderLanes);
  15579. return workInProgress.child;
  15580. }
  15581. var hasWarnedAboutUsingContextAsConsumer = false;
  15582. function updateContextConsumer(current, workInProgress, renderLanes) {
  15583. var context = workInProgress.type; // The logic below for Context differs depending on PROD or DEV mode. In
  15584. // DEV mode, we create a separate object for Context.Consumer that acts
  15585. // like a proxy to Context. This proxy object adds unnecessary code in PROD
  15586. // so we use the old behaviour (Context.Consumer references Context) to
  15587. // reduce size and overhead. The separate object references context via
  15588. // a property called "_context", which also gives us the ability to check
  15589. // in DEV mode if this property exists or not and warn if it does not.
  15590. {
  15591. if (context._context === undefined) {
  15592. // This may be because it's a Context (rather than a Consumer).
  15593. // Or it may be because it's older React where they're the same thing.
  15594. // We only want to warn if we're sure it's a new React.
  15595. if (context !== context.Consumer) {
  15596. if (!hasWarnedAboutUsingContextAsConsumer) {
  15597. hasWarnedAboutUsingContextAsConsumer = true;
  15598. error('Rendering <Context> directly is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Consumer> instead?');
  15599. }
  15600. }
  15601. } else {
  15602. context = context._context;
  15603. }
  15604. }
  15605. var newProps = workInProgress.pendingProps;
  15606. var render = newProps.children;
  15607. {
  15608. if (typeof render !== 'function') {
  15609. error('A context consumer was rendered with multiple children, or a child ' + "that isn't a function. A context consumer expects a single child " + 'that is a function. If you did pass a function, make sure there ' + 'is no trailing or leading whitespace around it.');
  15610. }
  15611. }
  15612. prepareToReadContext(workInProgress, renderLanes);
  15613. var newValue = readContext(context, newProps.unstable_observedBits);
  15614. var newChildren;
  15615. {
  15616. ReactCurrentOwner$1.current = workInProgress;
  15617. setIsRendering(true);
  15618. newChildren = render(newValue);
  15619. setIsRendering(false);
  15620. } // React DevTools reads this flag.
  15621. workInProgress.flags |= PerformedWork;
  15622. reconcileChildren(current, workInProgress, newChildren, renderLanes);
  15623. return workInProgress.child;
  15624. }
  15625. function markWorkInProgressReceivedUpdate() {
  15626. didReceiveUpdate = true;
  15627. }
  15628. function bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes) {
  15629. if (current !== null) {
  15630. // Reuse previous dependencies
  15631. workInProgress.dependencies = current.dependencies;
  15632. }
  15633. {
  15634. // Don't update "base" render times for bailouts.
  15635. stopProfilerTimerIfRunning();
  15636. }
  15637. markSkippedUpdateLanes(workInProgress.lanes); // Check if the children have any pending work.
  15638. if (!includesSomeLane(renderLanes, workInProgress.childLanes)) {
  15639. // The children don't have any work either. We can skip them.
  15640. // TODO: Once we add back resuming, we should check if the children are
  15641. // a work-in-progress set. If so, we need to transfer their effects.
  15642. return null;
  15643. } else {
  15644. // This fiber doesn't have work, but its subtree does. Clone the child
  15645. // fibers and continue.
  15646. cloneChildFibers(current, workInProgress);
  15647. return workInProgress.child;
  15648. }
  15649. }
  15650. function remountFiber(current, oldWorkInProgress, newWorkInProgress) {
  15651. {
  15652. var returnFiber = oldWorkInProgress.return;
  15653. if (returnFiber === null) {
  15654. throw new Error('Cannot swap the root fiber.');
  15655. } // Disconnect from the old current.
  15656. // It will get deleted.
  15657. current.alternate = null;
  15658. oldWorkInProgress.alternate = null; // Connect to the new tree.
  15659. newWorkInProgress.index = oldWorkInProgress.index;
  15660. newWorkInProgress.sibling = oldWorkInProgress.sibling;
  15661. newWorkInProgress.return = oldWorkInProgress.return;
  15662. newWorkInProgress.ref = oldWorkInProgress.ref; // Replace the child/sibling pointers above it.
  15663. if (oldWorkInProgress === returnFiber.child) {
  15664. returnFiber.child = newWorkInProgress;
  15665. } else {
  15666. var prevSibling = returnFiber.child;
  15667. if (prevSibling === null) {
  15668. throw new Error('Expected parent to have a child.');
  15669. }
  15670. while (prevSibling.sibling !== oldWorkInProgress) {
  15671. prevSibling = prevSibling.sibling;
  15672. if (prevSibling === null) {
  15673. throw new Error('Expected to find the previous sibling.');
  15674. }
  15675. }
  15676. prevSibling.sibling = newWorkInProgress;
  15677. } // Delete the old fiber and place the new one.
  15678. // Since the old fiber is disconnected, we have to schedule it manually.
  15679. var last = returnFiber.lastEffect;
  15680. if (last !== null) {
  15681. last.nextEffect = current;
  15682. returnFiber.lastEffect = current;
  15683. } else {
  15684. returnFiber.firstEffect = returnFiber.lastEffect = current;
  15685. }
  15686. current.nextEffect = null;
  15687. current.flags = Deletion;
  15688. newWorkInProgress.flags |= Placement; // Restart work from the new fiber.
  15689. return newWorkInProgress;
  15690. }
  15691. }
  15692. function beginWork(current, workInProgress, renderLanes) {
  15693. var updateLanes = workInProgress.lanes;
  15694. {
  15695. if (workInProgress._debugNeedsRemount && current !== null) {
  15696. // This will restart the begin phase with a new fiber.
  15697. return remountFiber(current, workInProgress, createFiberFromTypeAndProps(workInProgress.type, workInProgress.key, workInProgress.pendingProps, workInProgress._debugOwner || null, workInProgress.mode, workInProgress.lanes));
  15698. }
  15699. }
  15700. if (current !== null) {
  15701. var oldProps = current.memoizedProps;
  15702. var newProps = workInProgress.pendingProps;
  15703. if (oldProps !== newProps || hasContextChanged() || ( // Force a re-render if the implementation changed due to hot reload:
  15704. workInProgress.type !== current.type )) {
  15705. // If props or context changed, mark the fiber as having performed work.
  15706. // This may be unset if the props are determined to be equal later (memo).
  15707. didReceiveUpdate = true;
  15708. } else if (!includesSomeLane(renderLanes, updateLanes)) {
  15709. didReceiveUpdate = false; // This fiber does not have any pending work. Bailout without entering
  15710. // the begin phase. There's still some bookkeeping we that needs to be done
  15711. // in this optimized path, mostly pushing stuff onto the stack.
  15712. switch (workInProgress.tag) {
  15713. case HostRoot:
  15714. pushHostRootContext(workInProgress);
  15715. resetHydrationState();
  15716. break;
  15717. case HostComponent:
  15718. pushHostContext(workInProgress);
  15719. break;
  15720. case ClassComponent:
  15721. {
  15722. var Component = workInProgress.type;
  15723. if (isContextProvider(Component)) {
  15724. pushContextProvider(workInProgress);
  15725. }
  15726. break;
  15727. }
  15728. case HostPortal:
  15729. pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);
  15730. break;
  15731. case ContextProvider:
  15732. {
  15733. var newValue = workInProgress.memoizedProps.value;
  15734. pushProvider(workInProgress, newValue);
  15735. break;
  15736. }
  15737. case Profiler:
  15738. {
  15739. // Profiler should only call onRender when one of its descendants actually rendered.
  15740. var hasChildWork = includesSomeLane(renderLanes, workInProgress.childLanes);
  15741. if (hasChildWork) {
  15742. workInProgress.flags |= Update;
  15743. } // Reset effect durations for the next eventual effect phase.
  15744. // These are reset during render to allow the DevTools commit hook a chance to read them,
  15745. var stateNode = workInProgress.stateNode;
  15746. stateNode.effectDuration = 0;
  15747. stateNode.passiveEffectDuration = 0;
  15748. }
  15749. break;
  15750. case SuspenseComponent:
  15751. {
  15752. var state = workInProgress.memoizedState;
  15753. if (state !== null) {
  15754. // whether to retry the primary children, or to skip over it and
  15755. // go straight to the fallback. Check the priority of the primary
  15756. // child fragment.
  15757. var primaryChildFragment = workInProgress.child;
  15758. var primaryChildLanes = primaryChildFragment.childLanes;
  15759. if (includesSomeLane(renderLanes, primaryChildLanes)) {
  15760. // The primary children have pending work. Use the normal path
  15761. // to attempt to render the primary children again.
  15762. return updateSuspenseComponent(current, workInProgress, renderLanes);
  15763. } else {
  15764. // The primary child fragment does not have pending work marked
  15765. // on it
  15766. pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current)); // The primary children do not have pending work with sufficient
  15767. // priority. Bailout.
  15768. var child = bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  15769. if (child !== null) {
  15770. // The fallback children have pending work. Skip over the
  15771. // primary children and work on the fallback.
  15772. return child.sibling;
  15773. } else {
  15774. return null;
  15775. }
  15776. }
  15777. } else {
  15778. pushSuspenseContext(workInProgress, setDefaultShallowSuspenseContext(suspenseStackCursor.current));
  15779. }
  15780. break;
  15781. }
  15782. case SuspenseListComponent:
  15783. {
  15784. var didSuspendBefore = (current.flags & DidCapture) !== NoFlags;
  15785. var _hasChildWork = includesSomeLane(renderLanes, workInProgress.childLanes);
  15786. if (didSuspendBefore) {
  15787. if (_hasChildWork) {
  15788. // If something was in fallback state last time, and we have all the
  15789. // same children then we're still in progressive loading state.
  15790. // Something might get unblocked by state updates or retries in the
  15791. // tree which will affect the tail. So we need to use the normal
  15792. // path to compute the correct tail.
  15793. return updateSuspenseListComponent(current, workInProgress, renderLanes);
  15794. } // If none of the children had any work, that means that none of
  15795. // them got retried so they'll still be blocked in the same way
  15796. // as before. We can fast bail out.
  15797. workInProgress.flags |= DidCapture;
  15798. } // If nothing suspended before and we're rendering the same children,
  15799. // then the tail doesn't matter. Anything new that suspends will work
  15800. // in the "together" mode, so we can continue from the state we had.
  15801. var renderState = workInProgress.memoizedState;
  15802. if (renderState !== null) {
  15803. // Reset to the "together" mode in case we've started a different
  15804. // update in the past but didn't complete it.
  15805. renderState.rendering = null;
  15806. renderState.tail = null;
  15807. renderState.lastEffect = null;
  15808. }
  15809. pushSuspenseContext(workInProgress, suspenseStackCursor.current);
  15810. if (_hasChildWork) {
  15811. break;
  15812. } else {
  15813. // If none of the children had any work, that means that none of
  15814. // them got retried so they'll still be blocked in the same way
  15815. // as before. We can fast bail out.
  15816. return null;
  15817. }
  15818. }
  15819. case OffscreenComponent:
  15820. case LegacyHiddenComponent:
  15821. {
  15822. // Need to check if the tree still needs to be deferred. This is
  15823. // almost identical to the logic used in the normal update path,
  15824. // so we'll just enter that. The only difference is we'll bail out
  15825. // at the next level instead of this one, because the child props
  15826. // have not changed. Which is fine.
  15827. // TODO: Probably should refactor `beginWork` to split the bailout
  15828. // path from the normal path. I'm tempted to do a labeled break here
  15829. // but I won't :)
  15830. workInProgress.lanes = NoLanes;
  15831. return updateOffscreenComponent(current, workInProgress, renderLanes);
  15832. }
  15833. }
  15834. return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
  15835. } else {
  15836. if ((current.flags & ForceUpdateForLegacySuspense) !== NoFlags) {
  15837. // This is a special case that only exists for legacy mode.
  15838. // See https://github.com/facebook/react/pull/19216.
  15839. didReceiveUpdate = true;
  15840. } else {
  15841. // An update was scheduled on this fiber, but there are no new props
  15842. // nor legacy context. Set this to false. If an update queue or context
  15843. // consumer produces a changed value, it will set this to true. Otherwise,
  15844. // the component will assume the children have not changed and bail out.
  15845. didReceiveUpdate = false;
  15846. }
  15847. }
  15848. } else {
  15849. didReceiveUpdate = false;
  15850. } // Before entering the begin phase, clear pending update priority.
  15851. // TODO: This assumes that we're about to evaluate the component and process
  15852. // the update queue. However, there's an exception: SimpleMemoComponent
  15853. // sometimes bails out later in the begin phase. This indicates that we should
  15854. // move this assignment out of the common path and into each branch.
  15855. workInProgress.lanes = NoLanes;
  15856. switch (workInProgress.tag) {
  15857. case IndeterminateComponent:
  15858. {
  15859. return mountIndeterminateComponent(current, workInProgress, workInProgress.type, renderLanes);
  15860. }
  15861. case LazyComponent:
  15862. {
  15863. var elementType = workInProgress.elementType;
  15864. return mountLazyComponent(current, workInProgress, elementType, updateLanes, renderLanes);
  15865. }
  15866. case FunctionComponent:
  15867. {
  15868. var _Component = workInProgress.type;
  15869. var unresolvedProps = workInProgress.pendingProps;
  15870. var resolvedProps = workInProgress.elementType === _Component ? unresolvedProps : resolveDefaultProps(_Component, unresolvedProps);
  15871. return updateFunctionComponent(current, workInProgress, _Component, resolvedProps, renderLanes);
  15872. }
  15873. case ClassComponent:
  15874. {
  15875. var _Component2 = workInProgress.type;
  15876. var _unresolvedProps = workInProgress.pendingProps;
  15877. var _resolvedProps = workInProgress.elementType === _Component2 ? _unresolvedProps : resolveDefaultProps(_Component2, _unresolvedProps);
  15878. return updateClassComponent(current, workInProgress, _Component2, _resolvedProps, renderLanes);
  15879. }
  15880. case HostRoot:
  15881. return updateHostRoot(current, workInProgress, renderLanes);
  15882. case HostComponent:
  15883. return updateHostComponent(current, workInProgress, renderLanes);
  15884. case HostText:
  15885. return updateHostText(current, workInProgress);
  15886. case SuspenseComponent:
  15887. return updateSuspenseComponent(current, workInProgress, renderLanes);
  15888. case HostPortal:
  15889. return updatePortalComponent(current, workInProgress, renderLanes);
  15890. case ForwardRef:
  15891. {
  15892. var type = workInProgress.type;
  15893. var _unresolvedProps2 = workInProgress.pendingProps;
  15894. var _resolvedProps2 = workInProgress.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
  15895. return updateForwardRef(current, workInProgress, type, _resolvedProps2, renderLanes);
  15896. }
  15897. case Fragment:
  15898. return updateFragment(current, workInProgress, renderLanes);
  15899. case Mode:
  15900. return updateMode(current, workInProgress, renderLanes);
  15901. case Profiler:
  15902. return updateProfiler(current, workInProgress, renderLanes);
  15903. case ContextProvider:
  15904. return updateContextProvider(current, workInProgress, renderLanes);
  15905. case ContextConsumer:
  15906. return updateContextConsumer(current, workInProgress, renderLanes);
  15907. case MemoComponent:
  15908. {
  15909. var _type2 = workInProgress.type;
  15910. var _unresolvedProps3 = workInProgress.pendingProps; // Resolve outer props first, then resolve inner props.
  15911. var _resolvedProps3 = resolveDefaultProps(_type2, _unresolvedProps3);
  15912. {
  15913. if (workInProgress.type !== workInProgress.elementType) {
  15914. var outerPropTypes = _type2.propTypes;
  15915. if (outerPropTypes) {
  15916. checkPropTypes(outerPropTypes, _resolvedProps3, // Resolved for outer only
  15917. 'prop', getComponentName(_type2));
  15918. }
  15919. }
  15920. }
  15921. _resolvedProps3 = resolveDefaultProps(_type2.type, _resolvedProps3);
  15922. return updateMemoComponent(current, workInProgress, _type2, _resolvedProps3, updateLanes, renderLanes);
  15923. }
  15924. case SimpleMemoComponent:
  15925. {
  15926. return updateSimpleMemoComponent(current, workInProgress, workInProgress.type, workInProgress.pendingProps, updateLanes, renderLanes);
  15927. }
  15928. case IncompleteClassComponent:
  15929. {
  15930. var _Component3 = workInProgress.type;
  15931. var _unresolvedProps4 = workInProgress.pendingProps;
  15932. var _resolvedProps4 = workInProgress.elementType === _Component3 ? _unresolvedProps4 : resolveDefaultProps(_Component3, _unresolvedProps4);
  15933. return mountIncompleteClassComponent(current, workInProgress, _Component3, _resolvedProps4, renderLanes);
  15934. }
  15935. case SuspenseListComponent:
  15936. {
  15937. return updateSuspenseListComponent(current, workInProgress, renderLanes);
  15938. }
  15939. case FundamentalComponent:
  15940. {
  15941. break;
  15942. }
  15943. case ScopeComponent:
  15944. {
  15945. break;
  15946. }
  15947. case Block:
  15948. {
  15949. break;
  15950. }
  15951. case OffscreenComponent:
  15952. {
  15953. return updateOffscreenComponent(current, workInProgress, renderLanes);
  15954. }
  15955. case LegacyHiddenComponent:
  15956. {
  15957. return updateLegacyHiddenComponent(current, workInProgress, renderLanes);
  15958. }
  15959. }
  15960. {
  15961. {
  15962. throw Error( "Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue." );
  15963. }
  15964. }
  15965. }
  15966. function markUpdate(workInProgress) {
  15967. // Tag the fiber with an update effect. This turns a Placement into
  15968. // a PlacementAndUpdate.
  15969. workInProgress.flags |= Update;
  15970. }
  15971. function markRef$1(workInProgress) {
  15972. workInProgress.flags |= Ref;
  15973. }
  15974. var appendAllChildren;
  15975. var updateHostContainer;
  15976. var updateHostComponent$1;
  15977. var updateHostText$1;
  15978. {
  15979. // Mutation mode
  15980. appendAllChildren = function (parent, workInProgress, needsVisibilityToggle, isHidden) {
  15981. // We only have the top Fiber that was created but we need recurse down its
  15982. // children to find all the terminal nodes.
  15983. var node = workInProgress.child;
  15984. while (node !== null) {
  15985. if (node.tag === HostComponent || node.tag === HostText) {
  15986. appendInitialChild(parent, node.stateNode);
  15987. } else if (node.tag === HostPortal) ; else if (node.child !== null) {
  15988. node.child.return = node;
  15989. node = node.child;
  15990. continue;
  15991. }
  15992. if (node === workInProgress) {
  15993. return;
  15994. }
  15995. while (node.sibling === null) {
  15996. if (node.return === null || node.return === workInProgress) {
  15997. return;
  15998. }
  15999. node = node.return;
  16000. }
  16001. node.sibling.return = node.return;
  16002. node = node.sibling;
  16003. }
  16004. };
  16005. updateHostContainer = function (workInProgress) {// Noop
  16006. };
  16007. updateHostComponent$1 = function (current, workInProgress, type, newProps, rootContainerInstance) {
  16008. // If we have an alternate, that means this is an update and we need to
  16009. // schedule a side-effect to do the updates.
  16010. var oldProps = current.memoizedProps;
  16011. if (oldProps === newProps) {
  16012. // In mutation mode, this is sufficient for a bailout because
  16013. // we won't touch this node even if children changed.
  16014. return;
  16015. } // If we get updated because one of our children updated, we don't
  16016. // have newProps so we'll have to reuse them.
  16017. // TODO: Split the update API as separate for the props vs. children.
  16018. // Even better would be if children weren't special cased at all tho.
  16019. var instance = workInProgress.stateNode;
  16020. var currentHostContext = getHostContext(); // TODO: Experiencing an error where oldProps is null. Suggests a host
  16021. // component is hitting the resume path. Figure out why. Possibly
  16022. // related to `hidden`.
  16023. var updatePayload = prepareUpdate(instance, type, oldProps, newProps, rootContainerInstance, currentHostContext); // TODO: Type this specific to this type of component.
  16024. workInProgress.updateQueue = updatePayload; // If the update payload indicates that there is a change or if there
  16025. // is a new ref we mark this as an update. All the work is done in commitWork.
  16026. if (updatePayload) {
  16027. markUpdate(workInProgress);
  16028. }
  16029. };
  16030. updateHostText$1 = function (current, workInProgress, oldText, newText) {
  16031. // If the text differs, mark it as an update. All the work in done in commitWork.
  16032. if (oldText !== newText) {
  16033. markUpdate(workInProgress);
  16034. }
  16035. };
  16036. }
  16037. function cutOffTailIfNeeded(renderState, hasRenderedATailFallback) {
  16038. if (getIsHydrating()) {
  16039. // If we're hydrating, we should consume as many items as we can
  16040. // so we don't leave any behind.
  16041. return;
  16042. }
  16043. switch (renderState.tailMode) {
  16044. case 'hidden':
  16045. {
  16046. // Any insertions at the end of the tail list after this point
  16047. // should be invisible. If there are already mounted boundaries
  16048. // anything before them are not considered for collapsing.
  16049. // Therefore we need to go through the whole tail to find if
  16050. // there are any.
  16051. var tailNode = renderState.tail;
  16052. var lastTailNode = null;
  16053. while (tailNode !== null) {
  16054. if (tailNode.alternate !== null) {
  16055. lastTailNode = tailNode;
  16056. }
  16057. tailNode = tailNode.sibling;
  16058. } // Next we're simply going to delete all insertions after the
  16059. // last rendered item.
  16060. if (lastTailNode === null) {
  16061. // All remaining items in the tail are insertions.
  16062. renderState.tail = null;
  16063. } else {
  16064. // Detach the insertion after the last node that was already
  16065. // inserted.
  16066. lastTailNode.sibling = null;
  16067. }
  16068. break;
  16069. }
  16070. case 'collapsed':
  16071. {
  16072. // Any insertions at the end of the tail list after this point
  16073. // should be invisible. If there are already mounted boundaries
  16074. // anything before them are not considered for collapsing.
  16075. // Therefore we need to go through the whole tail to find if
  16076. // there are any.
  16077. var _tailNode = renderState.tail;
  16078. var _lastTailNode = null;
  16079. while (_tailNode !== null) {
  16080. if (_tailNode.alternate !== null) {
  16081. _lastTailNode = _tailNode;
  16082. }
  16083. _tailNode = _tailNode.sibling;
  16084. } // Next we're simply going to delete all insertions after the
  16085. // last rendered item.
  16086. if (_lastTailNode === null) {
  16087. // All remaining items in the tail are insertions.
  16088. if (!hasRenderedATailFallback && renderState.tail !== null) {
  16089. // We suspended during the head. We want to show at least one
  16090. // row at the tail. So we'll keep on and cut off the rest.
  16091. renderState.tail.sibling = null;
  16092. } else {
  16093. renderState.tail = null;
  16094. }
  16095. } else {
  16096. // Detach the insertion after the last node that was already
  16097. // inserted.
  16098. _lastTailNode.sibling = null;
  16099. }
  16100. break;
  16101. }
  16102. }
  16103. }
  16104. function completeWork(current, workInProgress, renderLanes) {
  16105. var newProps = workInProgress.pendingProps;
  16106. switch (workInProgress.tag) {
  16107. case IndeterminateComponent:
  16108. case LazyComponent:
  16109. case SimpleMemoComponent:
  16110. case FunctionComponent:
  16111. case ForwardRef:
  16112. case Fragment:
  16113. case Mode:
  16114. case Profiler:
  16115. case ContextConsumer:
  16116. case MemoComponent:
  16117. return null;
  16118. case ClassComponent:
  16119. {
  16120. var Component = workInProgress.type;
  16121. if (isContextProvider(Component)) {
  16122. popContext(workInProgress);
  16123. }
  16124. return null;
  16125. }
  16126. case HostRoot:
  16127. {
  16128. popHostContainer(workInProgress);
  16129. popTopLevelContextObject(workInProgress);
  16130. resetWorkInProgressVersions();
  16131. var fiberRoot = workInProgress.stateNode;
  16132. if (fiberRoot.pendingContext) {
  16133. fiberRoot.context = fiberRoot.pendingContext;
  16134. fiberRoot.pendingContext = null;
  16135. }
  16136. if (current === null || current.child === null) {
  16137. // If we hydrated, pop so that we can delete any remaining children
  16138. // that weren't hydrated.
  16139. var wasHydrated = popHydrationState(workInProgress);
  16140. if (wasHydrated) {
  16141. // If we hydrated, then we'll need to schedule an update for
  16142. // the commit side-effects on the root.
  16143. markUpdate(workInProgress);
  16144. } else if (!fiberRoot.hydrate) {
  16145. // Schedule an effect to clear this container at the start of the next commit.
  16146. // This handles the case of React rendering into a container with previous children.
  16147. // It's also safe to do for updates too, because current.child would only be null
  16148. // if the previous render was null (so the the container would already be empty).
  16149. workInProgress.flags |= Snapshot;
  16150. }
  16151. }
  16152. updateHostContainer(workInProgress);
  16153. return null;
  16154. }
  16155. case HostComponent:
  16156. {
  16157. popHostContext(workInProgress);
  16158. var rootContainerInstance = getRootHostContainer();
  16159. var type = workInProgress.type;
  16160. if (current !== null && workInProgress.stateNode != null) {
  16161. updateHostComponent$1(current, workInProgress, type, newProps, rootContainerInstance);
  16162. if (current.ref !== workInProgress.ref) {
  16163. markRef$1(workInProgress);
  16164. }
  16165. } else {
  16166. if (!newProps) {
  16167. if (!(workInProgress.stateNode !== null)) {
  16168. {
  16169. throw Error( "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." );
  16170. }
  16171. } // This can happen when we abort work.
  16172. return null;
  16173. }
  16174. var currentHostContext = getHostContext(); // TODO: Move createInstance to beginWork and keep it on a context
  16175. // "stack" as the parent. Then append children as we go in beginWork
  16176. // or completeWork depending on whether we want to add them top->down or
  16177. // bottom->up. Top->down is faster in IE11.
  16178. var _wasHydrated = popHydrationState(workInProgress);
  16179. if (_wasHydrated) {
  16180. // TODO: Move this and createInstance step into the beginPhase
  16181. // to consolidate.
  16182. if (prepareToHydrateHostInstance(workInProgress, rootContainerInstance, currentHostContext)) {
  16183. // If changes to the hydrated node need to be applied at the
  16184. // commit-phase we mark this as such.
  16185. markUpdate(workInProgress);
  16186. }
  16187. } else {
  16188. var instance = createInstance(type, newProps, rootContainerInstance, currentHostContext, workInProgress);
  16189. appendAllChildren(instance, workInProgress, false, false);
  16190. workInProgress.stateNode = instance; // Certain renderers require commit-time effects for initial mount.
  16191. // (eg DOM renderer supports auto-focus for certain elements).
  16192. // Make sure such renderers get scheduled for later work.
  16193. if (finalizeInitialChildren(instance, type, newProps, rootContainerInstance)) {
  16194. markUpdate(workInProgress);
  16195. }
  16196. }
  16197. if (workInProgress.ref !== null) {
  16198. // If there is a ref on a host node we need to schedule a callback
  16199. markRef$1(workInProgress);
  16200. }
  16201. }
  16202. return null;
  16203. }
  16204. case HostText:
  16205. {
  16206. var newText = newProps;
  16207. if (current && workInProgress.stateNode != null) {
  16208. var oldText = current.memoizedProps; // If we have an alternate, that means this is an update and we need
  16209. // to schedule a side-effect to do the updates.
  16210. updateHostText$1(current, workInProgress, oldText, newText);
  16211. } else {
  16212. if (typeof newText !== 'string') {
  16213. if (!(workInProgress.stateNode !== null)) {
  16214. {
  16215. throw Error( "We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue." );
  16216. }
  16217. } // This can happen when we abort work.
  16218. }
  16219. var _rootContainerInstance = getRootHostContainer();
  16220. var _currentHostContext = getHostContext();
  16221. var _wasHydrated2 = popHydrationState(workInProgress);
  16222. if (_wasHydrated2) {
  16223. if (prepareToHydrateHostTextInstance(workInProgress)) {
  16224. markUpdate(workInProgress);
  16225. }
  16226. } else {
  16227. workInProgress.stateNode = createTextInstance(newText, _rootContainerInstance, _currentHostContext, workInProgress);
  16228. }
  16229. }
  16230. return null;
  16231. }
  16232. case SuspenseComponent:
  16233. {
  16234. popSuspenseContext(workInProgress);
  16235. var nextState = workInProgress.memoizedState;
  16236. if ((workInProgress.flags & DidCapture) !== NoFlags) {
  16237. // Something suspended. Re-render with the fallback children.
  16238. workInProgress.lanes = renderLanes; // Do not reset the effect list.
  16239. if ( (workInProgress.mode & ProfileMode) !== NoMode) {
  16240. transferActualDuration(workInProgress);
  16241. }
  16242. return workInProgress;
  16243. }
  16244. var nextDidTimeout = nextState !== null;
  16245. var prevDidTimeout = false;
  16246. if (current === null) {
  16247. if (workInProgress.memoizedProps.fallback !== undefined) {
  16248. popHydrationState(workInProgress);
  16249. }
  16250. } else {
  16251. var prevState = current.memoizedState;
  16252. prevDidTimeout = prevState !== null;
  16253. }
  16254. if (nextDidTimeout && !prevDidTimeout) {
  16255. // If this subtreee is running in blocking mode we can suspend,
  16256. // otherwise we won't suspend.
  16257. // TODO: This will still suspend a synchronous tree if anything
  16258. // in the concurrent tree already suspended during this render.
  16259. // This is a known bug.
  16260. if ((workInProgress.mode & BlockingMode) !== NoMode) {
  16261. // TODO: Move this back to throwException because this is too late
  16262. // if this is a large tree which is common for initial loads. We
  16263. // don't know if we should restart a render or not until we get
  16264. // this marker, and this is too late.
  16265. // If this render already had a ping or lower pri updates,
  16266. // and this is the first time we know we're going to suspend we
  16267. // should be able to immediately restart from within throwException.
  16268. var hasInvisibleChildContext = current === null && workInProgress.memoizedProps.unstable_avoidThisFallback !== true;
  16269. if (hasInvisibleChildContext || hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext)) {
  16270. // If this was in an invisible tree or a new render, then showing
  16271. // this boundary is ok.
  16272. renderDidSuspend();
  16273. } else {
  16274. // Otherwise, we're going to have to hide content so we should
  16275. // suspend for longer if possible.
  16276. renderDidSuspendDelayIfPossible();
  16277. }
  16278. }
  16279. }
  16280. {
  16281. // TODO: Only schedule updates if these values are non equal, i.e. it changed.
  16282. if (nextDidTimeout || prevDidTimeout) {
  16283. // If this boundary just timed out, schedule an effect to attach a
  16284. // retry listener to the promise. This flag is also used to hide the
  16285. // primary children. In mutation mode, we also need the flag to
  16286. // *unhide* children that were previously hidden, so check if this
  16287. // is currently timed out, too.
  16288. workInProgress.flags |= Update;
  16289. }
  16290. }
  16291. return null;
  16292. }
  16293. case HostPortal:
  16294. popHostContainer(workInProgress);
  16295. updateHostContainer(workInProgress);
  16296. if (current === null) {
  16297. preparePortalMount(workInProgress.stateNode.containerInfo);
  16298. }
  16299. return null;
  16300. case ContextProvider:
  16301. // Pop provider fiber
  16302. popProvider(workInProgress);
  16303. return null;
  16304. case IncompleteClassComponent:
  16305. {
  16306. // Same as class component case. I put it down here so that the tags are
  16307. // sequential to ensure this switch is compiled to a jump table.
  16308. var _Component = workInProgress.type;
  16309. if (isContextProvider(_Component)) {
  16310. popContext(workInProgress);
  16311. }
  16312. return null;
  16313. }
  16314. case SuspenseListComponent:
  16315. {
  16316. popSuspenseContext(workInProgress);
  16317. var renderState = workInProgress.memoizedState;
  16318. if (renderState === null) {
  16319. // We're running in the default, "independent" mode.
  16320. // We don't do anything in this mode.
  16321. return null;
  16322. }
  16323. var didSuspendAlready = (workInProgress.flags & DidCapture) !== NoFlags;
  16324. var renderedTail = renderState.rendering;
  16325. if (renderedTail === null) {
  16326. // We just rendered the head.
  16327. if (!didSuspendAlready) {
  16328. // This is the first pass. We need to figure out if anything is still
  16329. // suspended in the rendered set.
  16330. // If new content unsuspended, but there's still some content that
  16331. // didn't. Then we need to do a second pass that forces everything
  16332. // to keep showing their fallbacks.
  16333. // We might be suspended if something in this render pass suspended, or
  16334. // something in the previous committed pass suspended. Otherwise,
  16335. // there's no chance so we can skip the expensive call to
  16336. // findFirstSuspended.
  16337. var cannotBeSuspended = renderHasNotSuspendedYet() && (current === null || (current.flags & DidCapture) === NoFlags);
  16338. if (!cannotBeSuspended) {
  16339. var row = workInProgress.child;
  16340. while (row !== null) {
  16341. var suspended = findFirstSuspended(row);
  16342. if (suspended !== null) {
  16343. didSuspendAlready = true;
  16344. workInProgress.flags |= DidCapture;
  16345. cutOffTailIfNeeded(renderState, false); // If this is a newly suspended tree, it might not get committed as
  16346. // part of the second pass. In that case nothing will subscribe to
  16347. // its thennables. Instead, we'll transfer its thennables to the
  16348. // SuspenseList so that it can retry if they resolve.
  16349. // There might be multiple of these in the list but since we're
  16350. // going to wait for all of them anyway, it doesn't really matter
  16351. // which ones gets to ping. In theory we could get clever and keep
  16352. // track of how many dependencies remain but it gets tricky because
  16353. // in the meantime, we can add/remove/change items and dependencies.
  16354. // We might bail out of the loop before finding any but that
  16355. // doesn't matter since that means that the other boundaries that
  16356. // we did find already has their listeners attached.
  16357. var newThennables = suspended.updateQueue;
  16358. if (newThennables !== null) {
  16359. workInProgress.updateQueue = newThennables;
  16360. workInProgress.flags |= Update;
  16361. } // Rerender the whole list, but this time, we'll force fallbacks
  16362. // to stay in place.
  16363. // Reset the effect list before doing the second pass since that's now invalid.
  16364. if (renderState.lastEffect === null) {
  16365. workInProgress.firstEffect = null;
  16366. }
  16367. workInProgress.lastEffect = renderState.lastEffect; // Reset the child fibers to their original state.
  16368. resetChildFibers(workInProgress, renderLanes); // Set up the Suspense Context to force suspense and immediately
  16369. // rerender the children.
  16370. pushSuspenseContext(workInProgress, setShallowSuspenseContext(suspenseStackCursor.current, ForceSuspenseFallback));
  16371. return workInProgress.child;
  16372. }
  16373. row = row.sibling;
  16374. }
  16375. }
  16376. if (renderState.tail !== null && now() > getRenderTargetTime()) {
  16377. // We have already passed our CPU deadline but we still have rows
  16378. // left in the tail. We'll just give up further attempts to render
  16379. // the main content and only render fallbacks.
  16380. workInProgress.flags |= DidCapture;
  16381. didSuspendAlready = true;
  16382. cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
  16383. // to get it started back up to attempt the next item. While in terms
  16384. // of priority this work has the same priority as this current render,
  16385. // it's not part of the same transition once the transition has
  16386. // committed. If it's sync, we still want to yield so that it can be
  16387. // painted. Conceptually, this is really the same as pinging.
  16388. // We can use any RetryLane even if it's the one currently rendering
  16389. // since we're leaving it behind on this node.
  16390. workInProgress.lanes = SomeRetryLane;
  16391. {
  16392. markSpawnedWork(SomeRetryLane);
  16393. }
  16394. }
  16395. } else {
  16396. cutOffTailIfNeeded(renderState, false);
  16397. } // Next we're going to render the tail.
  16398. } else {
  16399. // Append the rendered row to the child list.
  16400. if (!didSuspendAlready) {
  16401. var _suspended = findFirstSuspended(renderedTail);
  16402. if (_suspended !== null) {
  16403. workInProgress.flags |= DidCapture;
  16404. didSuspendAlready = true; // Ensure we transfer the update queue to the parent so that it doesn't
  16405. // get lost if this row ends up dropped during a second pass.
  16406. var _newThennables = _suspended.updateQueue;
  16407. if (_newThennables !== null) {
  16408. workInProgress.updateQueue = _newThennables;
  16409. workInProgress.flags |= Update;
  16410. }
  16411. cutOffTailIfNeeded(renderState, true); // This might have been modified.
  16412. if (renderState.tail === null && renderState.tailMode === 'hidden' && !renderedTail.alternate && !getIsHydrating() // We don't cut it if we're hydrating.
  16413. ) {
  16414. // We need to delete the row we just rendered.
  16415. // Reset the effect list to what it was before we rendered this
  16416. // child. The nested children have already appended themselves.
  16417. var lastEffect = workInProgress.lastEffect = renderState.lastEffect; // Remove any effects that were appended after this point.
  16418. if (lastEffect !== null) {
  16419. lastEffect.nextEffect = null;
  16420. } // We're done.
  16421. return null;
  16422. }
  16423. } else if ( // The time it took to render last row is greater than the remaining
  16424. // time we have to render. So rendering one more row would likely
  16425. // exceed it.
  16426. now() * 2 - renderState.renderingStartTime > getRenderTargetTime() && renderLanes !== OffscreenLane) {
  16427. // We have now passed our CPU deadline and we'll just give up further
  16428. // attempts to render the main content and only render fallbacks.
  16429. // The assumption is that this is usually faster.
  16430. workInProgress.flags |= DidCapture;
  16431. didSuspendAlready = true;
  16432. cutOffTailIfNeeded(renderState, false); // Since nothing actually suspended, there will nothing to ping this
  16433. // to get it started back up to attempt the next item. While in terms
  16434. // of priority this work has the same priority as this current render,
  16435. // it's not part of the same transition once the transition has
  16436. // committed. If it's sync, we still want to yield so that it can be
  16437. // painted. Conceptually, this is really the same as pinging.
  16438. // We can use any RetryLane even if it's the one currently rendering
  16439. // since we're leaving it behind on this node.
  16440. workInProgress.lanes = SomeRetryLane;
  16441. {
  16442. markSpawnedWork(SomeRetryLane);
  16443. }
  16444. }
  16445. }
  16446. if (renderState.isBackwards) {
  16447. // The effect list of the backwards tail will have been added
  16448. // to the end. This breaks the guarantee that life-cycles fire in
  16449. // sibling order but that isn't a strong guarantee promised by React.
  16450. // Especially since these might also just pop in during future commits.
  16451. // Append to the beginning of the list.
  16452. renderedTail.sibling = workInProgress.child;
  16453. workInProgress.child = renderedTail;
  16454. } else {
  16455. var previousSibling = renderState.last;
  16456. if (previousSibling !== null) {
  16457. previousSibling.sibling = renderedTail;
  16458. } else {
  16459. workInProgress.child = renderedTail;
  16460. }
  16461. renderState.last = renderedTail;
  16462. }
  16463. }
  16464. if (renderState.tail !== null) {
  16465. // We still have tail rows to render.
  16466. // Pop a row.
  16467. var next = renderState.tail;
  16468. renderState.rendering = next;
  16469. renderState.tail = next.sibling;
  16470. renderState.lastEffect = workInProgress.lastEffect;
  16471. renderState.renderingStartTime = now();
  16472. next.sibling = null; // Restore the context.
  16473. // TODO: We can probably just avoid popping it instead and only
  16474. // setting it the first time we go from not suspended to suspended.
  16475. var suspenseContext = suspenseStackCursor.current;
  16476. if (didSuspendAlready) {
  16477. suspenseContext = setShallowSuspenseContext(suspenseContext, ForceSuspenseFallback);
  16478. } else {
  16479. suspenseContext = setDefaultShallowSuspenseContext(suspenseContext);
  16480. }
  16481. pushSuspenseContext(workInProgress, suspenseContext); // Do a pass over the next row.
  16482. return next;
  16483. }
  16484. return null;
  16485. }
  16486. case FundamentalComponent:
  16487. {
  16488. break;
  16489. }
  16490. case ScopeComponent:
  16491. {
  16492. break;
  16493. }
  16494. case Block:
  16495. break;
  16496. case OffscreenComponent:
  16497. case LegacyHiddenComponent:
  16498. {
  16499. popRenderLanes(workInProgress);
  16500. if (current !== null) {
  16501. var _nextState = workInProgress.memoizedState;
  16502. var _prevState = current.memoizedState;
  16503. var prevIsHidden = _prevState !== null;
  16504. var nextIsHidden = _nextState !== null;
  16505. if (prevIsHidden !== nextIsHidden && newProps.mode !== 'unstable-defer-without-hiding') {
  16506. workInProgress.flags |= Update;
  16507. }
  16508. }
  16509. return null;
  16510. }
  16511. }
  16512. {
  16513. {
  16514. throw Error( "Unknown unit of work tag (" + workInProgress.tag + "). This error is likely caused by a bug in React. Please file an issue." );
  16515. }
  16516. }
  16517. }
  16518. function unwindWork(workInProgress, renderLanes) {
  16519. switch (workInProgress.tag) {
  16520. case ClassComponent:
  16521. {
  16522. var Component = workInProgress.type;
  16523. if (isContextProvider(Component)) {
  16524. popContext(workInProgress);
  16525. }
  16526. var flags = workInProgress.flags;
  16527. if (flags & ShouldCapture) {
  16528. workInProgress.flags = flags & ~ShouldCapture | DidCapture;
  16529. if ( (workInProgress.mode & ProfileMode) !== NoMode) {
  16530. transferActualDuration(workInProgress);
  16531. }
  16532. return workInProgress;
  16533. }
  16534. return null;
  16535. }
  16536. case HostRoot:
  16537. {
  16538. popHostContainer(workInProgress);
  16539. popTopLevelContextObject(workInProgress);
  16540. resetWorkInProgressVersions();
  16541. var _flags = workInProgress.flags;
  16542. if (!((_flags & DidCapture) === NoFlags)) {
  16543. {
  16544. throw Error( "The root failed to unmount after an error. This is likely a bug in React. Please file an issue." );
  16545. }
  16546. }
  16547. workInProgress.flags = _flags & ~ShouldCapture | DidCapture;
  16548. return workInProgress;
  16549. }
  16550. case HostComponent:
  16551. {
  16552. // TODO: popHydrationState
  16553. popHostContext(workInProgress);
  16554. return null;
  16555. }
  16556. case SuspenseComponent:
  16557. {
  16558. popSuspenseContext(workInProgress);
  16559. var _flags2 = workInProgress.flags;
  16560. if (_flags2 & ShouldCapture) {
  16561. workInProgress.flags = _flags2 & ~ShouldCapture | DidCapture; // Captured a suspense effect. Re-render the boundary.
  16562. if ( (workInProgress.mode & ProfileMode) !== NoMode) {
  16563. transferActualDuration(workInProgress);
  16564. }
  16565. return workInProgress;
  16566. }
  16567. return null;
  16568. }
  16569. case SuspenseListComponent:
  16570. {
  16571. popSuspenseContext(workInProgress); // SuspenseList doesn't actually catch anything. It should've been
  16572. // caught by a nested boundary. If not, it should bubble through.
  16573. return null;
  16574. }
  16575. case HostPortal:
  16576. popHostContainer(workInProgress);
  16577. return null;
  16578. case ContextProvider:
  16579. popProvider(workInProgress);
  16580. return null;
  16581. case OffscreenComponent:
  16582. case LegacyHiddenComponent:
  16583. popRenderLanes(workInProgress);
  16584. return null;
  16585. default:
  16586. return null;
  16587. }
  16588. }
  16589. function unwindInterruptedWork(interruptedWork) {
  16590. switch (interruptedWork.tag) {
  16591. case ClassComponent:
  16592. {
  16593. var childContextTypes = interruptedWork.type.childContextTypes;
  16594. if (childContextTypes !== null && childContextTypes !== undefined) {
  16595. popContext(interruptedWork);
  16596. }
  16597. break;
  16598. }
  16599. case HostRoot:
  16600. {
  16601. popHostContainer(interruptedWork);
  16602. popTopLevelContextObject(interruptedWork);
  16603. resetWorkInProgressVersions();
  16604. break;
  16605. }
  16606. case HostComponent:
  16607. {
  16608. popHostContext(interruptedWork);
  16609. break;
  16610. }
  16611. case HostPortal:
  16612. popHostContainer(interruptedWork);
  16613. break;
  16614. case SuspenseComponent:
  16615. popSuspenseContext(interruptedWork);
  16616. break;
  16617. case SuspenseListComponent:
  16618. popSuspenseContext(interruptedWork);
  16619. break;
  16620. case ContextProvider:
  16621. popProvider(interruptedWork);
  16622. break;
  16623. case OffscreenComponent:
  16624. case LegacyHiddenComponent:
  16625. popRenderLanes(interruptedWork);
  16626. break;
  16627. }
  16628. }
  16629. function createCapturedValue(value, source) {
  16630. // If the value is an error, call this function immediately after it is thrown
  16631. // so the stack is accurate.
  16632. return {
  16633. value: value,
  16634. source: source,
  16635. stack: getStackByFiberInDevAndProd(source)
  16636. };
  16637. }
  16638. // This module is forked in different environments.
  16639. // By default, return `true` to log errors to the console.
  16640. // Forks can return `false` if this isn't desirable.
  16641. function showErrorDialog(boundary, errorInfo) {
  16642. return true;
  16643. }
  16644. function logCapturedError(boundary, errorInfo) {
  16645. try {
  16646. var logError = showErrorDialog(boundary, errorInfo); // Allow injected showErrorDialog() to prevent default console.error logging.
  16647. // This enables renderers like ReactNative to better manage redbox behavior.
  16648. if (logError === false) {
  16649. return;
  16650. }
  16651. var error = errorInfo.value;
  16652. if (true) {
  16653. var source = errorInfo.source;
  16654. var stack = errorInfo.stack;
  16655. var componentStack = stack !== null ? stack : ''; // Browsers support silencing uncaught errors by calling
  16656. // `preventDefault()` in window `error` handler.
  16657. // We record this information as an expando on the error.
  16658. if (error != null && error._suppressLogging) {
  16659. if (boundary.tag === ClassComponent) {
  16660. // The error is recoverable and was silenced.
  16661. // Ignore it and don't print the stack addendum.
  16662. // This is handy for testing error boundaries without noise.
  16663. return;
  16664. } // The error is fatal. Since the silencing might have
  16665. // been accidental, we'll surface it anyway.
  16666. // However, the browser would have silenced the original error
  16667. // so we'll print it first, and then print the stack addendum.
  16668. console['error'](error); // Don't transform to our wrapper
  16669. // For a more detailed description of this block, see:
  16670. // https://github.com/facebook/react/pull/13384
  16671. }
  16672. var componentName = source ? getComponentName(source.type) : null;
  16673. var componentNameMessage = componentName ? "The above error occurred in the <" + componentName + "> component:" : 'The above error occurred in one of your React components:';
  16674. var errorBoundaryMessage;
  16675. var errorBoundaryName = getComponentName(boundary.type);
  16676. if (errorBoundaryName) {
  16677. errorBoundaryMessage = "React will try to recreate this component tree from scratch " + ("using the error boundary you provided, " + errorBoundaryName + ".");
  16678. } else {
  16679. errorBoundaryMessage = 'Consider adding an error boundary to your tree to customize error handling behavior.\n' + 'Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.';
  16680. }
  16681. var combinedMessage = componentNameMessage + "\n" + componentStack + "\n\n" + ("" + errorBoundaryMessage); // In development, we provide our own message with just the component stack.
  16682. // We don't include the original error message and JS stack because the browser
  16683. // has already printed it. Even if the application swallows the error, it is still
  16684. // displayed by the browser thanks to the DEV-only fake event trick in ReactErrorUtils.
  16685. console['error'](combinedMessage); // Don't transform to our wrapper
  16686. } else {
  16687. // In production, we print the error directly.
  16688. // This will include the message, the JS stack, and anything the browser wants to show.
  16689. // We pass the error object instead of custom message so that the browser displays the error natively.
  16690. console['error'](error); // Don't transform to our wrapper
  16691. }
  16692. } catch (e) {
  16693. // This method must not throw, or React internal state will get messed up.
  16694. // If console.error is overridden, or logCapturedError() shows a dialog that throws,
  16695. // we want to report this error outside of the normal stack as a last resort.
  16696. // https://github.com/facebook/react/issues/13188
  16697. setTimeout(function () {
  16698. throw e;
  16699. });
  16700. }
  16701. }
  16702. var PossiblyWeakMap$1 = typeof WeakMap === 'function' ? WeakMap : Map;
  16703. function createRootErrorUpdate(fiber, errorInfo, lane) {
  16704. var update = createUpdate(NoTimestamp, lane); // Unmount the root by rendering null.
  16705. update.tag = CaptureUpdate; // Caution: React DevTools currently depends on this property
  16706. // being called "element".
  16707. update.payload = {
  16708. element: null
  16709. };
  16710. var error = errorInfo.value;
  16711. update.callback = function () {
  16712. onUncaughtError(error);
  16713. logCapturedError(fiber, errorInfo);
  16714. };
  16715. return update;
  16716. }
  16717. function createClassErrorUpdate(fiber, errorInfo, lane) {
  16718. var update = createUpdate(NoTimestamp, lane);
  16719. update.tag = CaptureUpdate;
  16720. var getDerivedStateFromError = fiber.type.getDerivedStateFromError;
  16721. if (typeof getDerivedStateFromError === 'function') {
  16722. var error$1 = errorInfo.value;
  16723. update.payload = function () {
  16724. logCapturedError(fiber, errorInfo);
  16725. return getDerivedStateFromError(error$1);
  16726. };
  16727. }
  16728. var inst = fiber.stateNode;
  16729. if (inst !== null && typeof inst.componentDidCatch === 'function') {
  16730. update.callback = function callback() {
  16731. {
  16732. markFailedErrorBoundaryForHotReloading(fiber);
  16733. }
  16734. if (typeof getDerivedStateFromError !== 'function') {
  16735. // To preserve the preexisting retry behavior of error boundaries,
  16736. // we keep track of which ones already failed during this batch.
  16737. // This gets reset before we yield back to the browser.
  16738. // TODO: Warn in strict mode if getDerivedStateFromError is
  16739. // not defined.
  16740. markLegacyErrorBoundaryAsFailed(this); // Only log here if componentDidCatch is the only error boundary method defined
  16741. logCapturedError(fiber, errorInfo);
  16742. }
  16743. var error$1 = errorInfo.value;
  16744. var stack = errorInfo.stack;
  16745. this.componentDidCatch(error$1, {
  16746. componentStack: stack !== null ? stack : ''
  16747. });
  16748. {
  16749. if (typeof getDerivedStateFromError !== 'function') {
  16750. // If componentDidCatch is the only error boundary method defined,
  16751. // then it needs to call setState to recover from errors.
  16752. // If no state update is scheduled then the boundary will swallow the error.
  16753. if (!includesSomeLane(fiber.lanes, SyncLane)) {
  16754. error('%s: Error boundaries should implement getDerivedStateFromError(). ' + 'In that method, return a state update to display an error message or fallback UI.', getComponentName(fiber.type) || 'Unknown');
  16755. }
  16756. }
  16757. }
  16758. };
  16759. } else {
  16760. update.callback = function () {
  16761. markFailedErrorBoundaryForHotReloading(fiber);
  16762. };
  16763. }
  16764. return update;
  16765. }
  16766. function attachPingListener(root, wakeable, lanes) {
  16767. // Attach a listener to the promise to "ping" the root and retry. But only if
  16768. // one does not already exist for the lanes we're currently rendering (which
  16769. // acts like a "thread ID" here).
  16770. var pingCache = root.pingCache;
  16771. var threadIDs;
  16772. if (pingCache === null) {
  16773. pingCache = root.pingCache = new PossiblyWeakMap$1();
  16774. threadIDs = new Set();
  16775. pingCache.set(wakeable, threadIDs);
  16776. } else {
  16777. threadIDs = pingCache.get(wakeable);
  16778. if (threadIDs === undefined) {
  16779. threadIDs = new Set();
  16780. pingCache.set(wakeable, threadIDs);
  16781. }
  16782. }
  16783. if (!threadIDs.has(lanes)) {
  16784. // Memoize using the thread ID to prevent redundant listeners.
  16785. threadIDs.add(lanes);
  16786. var ping = pingSuspendedRoot.bind(null, root, wakeable, lanes);
  16787. wakeable.then(ping, ping);
  16788. }
  16789. }
  16790. function throwException(root, returnFiber, sourceFiber, value, rootRenderLanes) {
  16791. // The source fiber did not complete.
  16792. sourceFiber.flags |= Incomplete; // Its effect list is no longer valid.
  16793. sourceFiber.firstEffect = sourceFiber.lastEffect = null;
  16794. if (value !== null && typeof value === 'object' && typeof value.then === 'function') {
  16795. // This is a wakeable.
  16796. var wakeable = value;
  16797. if ((sourceFiber.mode & BlockingMode) === NoMode) {
  16798. // Reset the memoizedState to what it was before we attempted
  16799. // to render it.
  16800. var currentSource = sourceFiber.alternate;
  16801. if (currentSource) {
  16802. sourceFiber.updateQueue = currentSource.updateQueue;
  16803. sourceFiber.memoizedState = currentSource.memoizedState;
  16804. sourceFiber.lanes = currentSource.lanes;
  16805. } else {
  16806. sourceFiber.updateQueue = null;
  16807. sourceFiber.memoizedState = null;
  16808. }
  16809. }
  16810. var hasInvisibleParentBoundary = hasSuspenseContext(suspenseStackCursor.current, InvisibleParentSuspenseContext); // Schedule the nearest Suspense to re-render the timed out view.
  16811. var _workInProgress = returnFiber;
  16812. do {
  16813. if (_workInProgress.tag === SuspenseComponent && shouldCaptureSuspense(_workInProgress, hasInvisibleParentBoundary)) {
  16814. // Found the nearest boundary.
  16815. // Stash the promise on the boundary fiber. If the boundary times out, we'll
  16816. // attach another listener to flip the boundary back to its normal state.
  16817. var wakeables = _workInProgress.updateQueue;
  16818. if (wakeables === null) {
  16819. var updateQueue = new Set();
  16820. updateQueue.add(wakeable);
  16821. _workInProgress.updateQueue = updateQueue;
  16822. } else {
  16823. wakeables.add(wakeable);
  16824. } // If the boundary is outside of blocking mode, we should *not*
  16825. // suspend the commit. Pretend as if the suspended component rendered
  16826. // null and keep rendering. In the commit phase, we'll schedule a
  16827. // subsequent synchronous update to re-render the Suspense.
  16828. //
  16829. // Note: It doesn't matter whether the component that suspended was
  16830. // inside a blocking mode tree. If the Suspense is outside of it, we
  16831. // should *not* suspend the commit.
  16832. if ((_workInProgress.mode & BlockingMode) === NoMode) {
  16833. _workInProgress.flags |= DidCapture;
  16834. sourceFiber.flags |= ForceUpdateForLegacySuspense; // We're going to commit this fiber even though it didn't complete.
  16835. // But we shouldn't call any lifecycle methods or callbacks. Remove
  16836. // all lifecycle effect tags.
  16837. sourceFiber.flags &= ~(LifecycleEffectMask | Incomplete);
  16838. if (sourceFiber.tag === ClassComponent) {
  16839. var currentSourceFiber = sourceFiber.alternate;
  16840. if (currentSourceFiber === null) {
  16841. // This is a new mount. Change the tag so it's not mistaken for a
  16842. // completed class component. For example, we should not call
  16843. // componentWillUnmount if it is deleted.
  16844. sourceFiber.tag = IncompleteClassComponent;
  16845. } else {
  16846. // When we try rendering again, we should not reuse the current fiber,
  16847. // since it's known to be in an inconsistent state. Use a force update to
  16848. // prevent a bail out.
  16849. var update = createUpdate(NoTimestamp, SyncLane);
  16850. update.tag = ForceUpdate;
  16851. enqueueUpdate(sourceFiber, update);
  16852. }
  16853. } // The source fiber did not complete. Mark it with Sync priority to
  16854. // indicate that it still has pending work.
  16855. sourceFiber.lanes = mergeLanes(sourceFiber.lanes, SyncLane); // Exit without suspending.
  16856. return;
  16857. } // Confirmed that the boundary is in a concurrent mode tree. Continue
  16858. // with the normal suspend path.
  16859. //
  16860. // After this we'll use a set of heuristics to determine whether this
  16861. // render pass will run to completion or restart or "suspend" the commit.
  16862. // The actual logic for this is spread out in different places.
  16863. //
  16864. // This first principle is that if we're going to suspend when we complete
  16865. // a root, then we should also restart if we get an update or ping that
  16866. // might unsuspend it, and vice versa. The only reason to suspend is
  16867. // because you think you might want to restart before committing. However,
  16868. // it doesn't make sense to restart only while in the period we're suspended.
  16869. //
  16870. // Restarting too aggressively is also not good because it starves out any
  16871. // intermediate loading state. So we use heuristics to determine when.
  16872. // Suspense Heuristics
  16873. //
  16874. // If nothing threw a Promise or all the same fallbacks are already showing,
  16875. // then don't suspend/restart.
  16876. //
  16877. // If this is an initial render of a new tree of Suspense boundaries and
  16878. // those trigger a fallback, then don't suspend/restart. We want to ensure
  16879. // that we can show the initial loading state as quickly as possible.
  16880. //
  16881. // If we hit a "Delayed" case, such as when we'd switch from content back into
  16882. // a fallback, then we should always suspend/restart. Transitions apply
  16883. // to this case. If none is defined, JND is used instead.
  16884. //
  16885. // If we're already showing a fallback and it gets "retried", allowing us to show
  16886. // another level, but there's still an inner boundary that would show a fallback,
  16887. // then we suspend/restart for 500ms since the last time we showed a fallback
  16888. // anywhere in the tree. This effectively throttles progressive loading into a
  16889. // consistent train of commits. This also gives us an opportunity to restart to
  16890. // get to the completed state slightly earlier.
  16891. //
  16892. // If there's ambiguity due to batching it's resolved in preference of:
  16893. // 1) "delayed", 2) "initial render", 3) "retry".
  16894. //
  16895. // We want to ensure that a "busy" state doesn't get force committed. We want to
  16896. // ensure that new initial loading states can commit as soon as possible.
  16897. attachPingListener(root, wakeable, rootRenderLanes);
  16898. _workInProgress.flags |= ShouldCapture;
  16899. _workInProgress.lanes = rootRenderLanes;
  16900. return;
  16901. } // This boundary already captured during this render. Continue to the next
  16902. // boundary.
  16903. _workInProgress = _workInProgress.return;
  16904. } while (_workInProgress !== null); // No boundary was found. Fallthrough to error mode.
  16905. // TODO: Use invariant so the message is stripped in prod?
  16906. value = new Error((getComponentName(sourceFiber.type) || 'A React component') + ' suspended while rendering, but no fallback UI was specified.\n' + '\n' + 'Add a <Suspense fallback=...> component higher in the tree to ' + 'provide a loading indicator or placeholder to display.');
  16907. } // We didn't find a boundary that could handle this type of exception. Start
  16908. // over and traverse parent path again, this time treating the exception
  16909. // as an error.
  16910. renderDidError();
  16911. value = createCapturedValue(value, sourceFiber);
  16912. var workInProgress = returnFiber;
  16913. do {
  16914. switch (workInProgress.tag) {
  16915. case HostRoot:
  16916. {
  16917. var _errorInfo = value;
  16918. workInProgress.flags |= ShouldCapture;
  16919. var lane = pickArbitraryLane(rootRenderLanes);
  16920. workInProgress.lanes = mergeLanes(workInProgress.lanes, lane);
  16921. var _update = createRootErrorUpdate(workInProgress, _errorInfo, lane);
  16922. enqueueCapturedUpdate(workInProgress, _update);
  16923. return;
  16924. }
  16925. case ClassComponent:
  16926. // Capture and retry
  16927. var errorInfo = value;
  16928. var ctor = workInProgress.type;
  16929. var instance = workInProgress.stateNode;
  16930. if ((workInProgress.flags & DidCapture) === NoFlags && (typeof ctor.getDerivedStateFromError === 'function' || instance !== null && typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance))) {
  16931. workInProgress.flags |= ShouldCapture;
  16932. var _lane = pickArbitraryLane(rootRenderLanes);
  16933. workInProgress.lanes = mergeLanes(workInProgress.lanes, _lane); // Schedule the error boundary to re-render using updated state
  16934. var _update2 = createClassErrorUpdate(workInProgress, errorInfo, _lane);
  16935. enqueueCapturedUpdate(workInProgress, _update2);
  16936. return;
  16937. }
  16938. break;
  16939. }
  16940. workInProgress = workInProgress.return;
  16941. } while (workInProgress !== null);
  16942. }
  16943. var didWarnAboutUndefinedSnapshotBeforeUpdate = null;
  16944. {
  16945. didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
  16946. }
  16947. var PossiblyWeakSet = typeof WeakSet === 'function' ? WeakSet : Set;
  16948. var callComponentWillUnmountWithTimer = function (current, instance) {
  16949. instance.props = current.memoizedProps;
  16950. instance.state = current.memoizedState;
  16951. {
  16952. instance.componentWillUnmount();
  16953. }
  16954. }; // Capture errors so they don't interrupt unmounting.
  16955. function safelyCallComponentWillUnmount(current, instance) {
  16956. {
  16957. invokeGuardedCallback(null, callComponentWillUnmountWithTimer, null, current, instance);
  16958. if (hasCaughtError()) {
  16959. var unmountError = clearCaughtError();
  16960. captureCommitPhaseError(current, unmountError);
  16961. }
  16962. }
  16963. }
  16964. function safelyDetachRef(current) {
  16965. var ref = current.ref;
  16966. if (ref !== null) {
  16967. if (typeof ref === 'function') {
  16968. {
  16969. invokeGuardedCallback(null, ref, null, null);
  16970. if (hasCaughtError()) {
  16971. var refError = clearCaughtError();
  16972. captureCommitPhaseError(current, refError);
  16973. }
  16974. }
  16975. } else {
  16976. ref.current = null;
  16977. }
  16978. }
  16979. }
  16980. function safelyCallDestroy(current, destroy) {
  16981. {
  16982. invokeGuardedCallback(null, destroy, null);
  16983. if (hasCaughtError()) {
  16984. var error = clearCaughtError();
  16985. captureCommitPhaseError(current, error);
  16986. }
  16987. }
  16988. }
  16989. function commitBeforeMutationLifeCycles(current, finishedWork) {
  16990. switch (finishedWork.tag) {
  16991. case FunctionComponent:
  16992. case ForwardRef:
  16993. case SimpleMemoComponent:
  16994. case Block:
  16995. {
  16996. return;
  16997. }
  16998. case ClassComponent:
  16999. {
  17000. if (finishedWork.flags & Snapshot) {
  17001. if (current !== null) {
  17002. var prevProps = current.memoizedProps;
  17003. var prevState = current.memoizedState;
  17004. var instance = finishedWork.stateNode; // We could update instance props and state here,
  17005. // but instead we rely on them being set during last render.
  17006. // TODO: revisit this when we implement resuming.
  17007. {
  17008. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  17009. if (instance.props !== finishedWork.memoizedProps) {
  17010. error('Expected %s props to match memoized props before ' + 'getSnapshotBeforeUpdate. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  17011. }
  17012. if (instance.state !== finishedWork.memoizedState) {
  17013. error('Expected %s state to match memoized state before ' + 'getSnapshotBeforeUpdate. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.state`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  17014. }
  17015. }
  17016. }
  17017. var snapshot = instance.getSnapshotBeforeUpdate(finishedWork.elementType === finishedWork.type ? prevProps : resolveDefaultProps(finishedWork.type, prevProps), prevState);
  17018. {
  17019. var didWarnSet = didWarnAboutUndefinedSnapshotBeforeUpdate;
  17020. if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
  17021. didWarnSet.add(finishedWork.type);
  17022. error('%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' + 'must be returned. You have returned undefined.', getComponentName(finishedWork.type));
  17023. }
  17024. }
  17025. instance.__reactInternalSnapshotBeforeUpdate = snapshot;
  17026. }
  17027. }
  17028. return;
  17029. }
  17030. case HostRoot:
  17031. {
  17032. {
  17033. if (finishedWork.flags & Snapshot) {
  17034. var root = finishedWork.stateNode;
  17035. clearContainer(root.containerInfo);
  17036. }
  17037. }
  17038. return;
  17039. }
  17040. case HostComponent:
  17041. case HostText:
  17042. case HostPortal:
  17043. case IncompleteClassComponent:
  17044. // Nothing to do for these component types
  17045. return;
  17046. }
  17047. {
  17048. {
  17049. throw Error( "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue." );
  17050. }
  17051. }
  17052. }
  17053. function commitHookEffectListUnmount(tag, finishedWork) {
  17054. var updateQueue = finishedWork.updateQueue;
  17055. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  17056. if (lastEffect !== null) {
  17057. var firstEffect = lastEffect.next;
  17058. var effect = firstEffect;
  17059. do {
  17060. if ((effect.tag & tag) === tag) {
  17061. // Unmount
  17062. var destroy = effect.destroy;
  17063. effect.destroy = undefined;
  17064. if (destroy !== undefined) {
  17065. destroy();
  17066. }
  17067. }
  17068. effect = effect.next;
  17069. } while (effect !== firstEffect);
  17070. }
  17071. }
  17072. function commitHookEffectListMount(tag, finishedWork) {
  17073. var updateQueue = finishedWork.updateQueue;
  17074. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  17075. if (lastEffect !== null) {
  17076. var firstEffect = lastEffect.next;
  17077. var effect = firstEffect;
  17078. do {
  17079. if ((effect.tag & tag) === tag) {
  17080. // Mount
  17081. var create = effect.create;
  17082. effect.destroy = create();
  17083. {
  17084. var destroy = effect.destroy;
  17085. if (destroy !== undefined && typeof destroy !== 'function') {
  17086. var addendum = void 0;
  17087. if (destroy === null) {
  17088. addendum = ' You returned null. If your effect does not require clean ' + 'up, return undefined (or nothing).';
  17089. } else if (typeof destroy.then === 'function') {
  17090. addendum = '\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. ' + 'Instead, write the async function inside your effect ' + 'and call it immediately:\n\n' + 'useEffect(() => {\n' + ' async function fetchData() {\n' + ' // You can await here\n' + ' const response = await MyAPI.getData(someId);\n' + ' // ...\n' + ' }\n' + ' fetchData();\n' + "}, [someId]); // Or [] if effect doesn't need props or state\n\n" + 'Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching';
  17091. } else {
  17092. addendum = ' You returned: ' + destroy;
  17093. }
  17094. error('An effect function must not return anything besides a function, ' + 'which is used for clean-up.%s', addendum);
  17095. }
  17096. }
  17097. }
  17098. effect = effect.next;
  17099. } while (effect !== firstEffect);
  17100. }
  17101. }
  17102. function schedulePassiveEffects(finishedWork) {
  17103. var updateQueue = finishedWork.updateQueue;
  17104. var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;
  17105. if (lastEffect !== null) {
  17106. var firstEffect = lastEffect.next;
  17107. var effect = firstEffect;
  17108. do {
  17109. var _effect = effect,
  17110. next = _effect.next,
  17111. tag = _effect.tag;
  17112. if ((tag & Passive$1) !== NoFlags$1 && (tag & HasEffect) !== NoFlags$1) {
  17113. enqueuePendingPassiveHookEffectUnmount(finishedWork, effect);
  17114. enqueuePendingPassiveHookEffectMount(finishedWork, effect);
  17115. }
  17116. effect = next;
  17117. } while (effect !== firstEffect);
  17118. }
  17119. }
  17120. function commitLifeCycles(finishedRoot, current, finishedWork, committedLanes) {
  17121. switch (finishedWork.tag) {
  17122. case FunctionComponent:
  17123. case ForwardRef:
  17124. case SimpleMemoComponent:
  17125. case Block:
  17126. {
  17127. // At this point layout effects have already been destroyed (during mutation phase).
  17128. // This is done to prevent sibling component effects from interfering with each other,
  17129. // e.g. a destroy function in one component should never override a ref set
  17130. // by a create function in another component during the same commit.
  17131. {
  17132. commitHookEffectListMount(Layout | HasEffect, finishedWork);
  17133. }
  17134. schedulePassiveEffects(finishedWork);
  17135. return;
  17136. }
  17137. case ClassComponent:
  17138. {
  17139. var instance = finishedWork.stateNode;
  17140. if (finishedWork.flags & Update) {
  17141. if (current === null) {
  17142. // We could update instance props and state here,
  17143. // but instead we rely on them being set during last render.
  17144. // TODO: revisit this when we implement resuming.
  17145. {
  17146. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  17147. if (instance.props !== finishedWork.memoizedProps) {
  17148. error('Expected %s props to match memoized props before ' + 'componentDidMount. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  17149. }
  17150. if (instance.state !== finishedWork.memoizedState) {
  17151. error('Expected %s state to match memoized state before ' + 'componentDidMount. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.state`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  17152. }
  17153. }
  17154. }
  17155. {
  17156. instance.componentDidMount();
  17157. }
  17158. } else {
  17159. var prevProps = finishedWork.elementType === finishedWork.type ? current.memoizedProps : resolveDefaultProps(finishedWork.type, current.memoizedProps);
  17160. var prevState = current.memoizedState; // We could update instance props and state here,
  17161. // but instead we rely on them being set during last render.
  17162. // TODO: revisit this when we implement resuming.
  17163. {
  17164. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  17165. if (instance.props !== finishedWork.memoizedProps) {
  17166. error('Expected %s props to match memoized props before ' + 'componentDidUpdate. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  17167. }
  17168. if (instance.state !== finishedWork.memoizedState) {
  17169. error('Expected %s state to match memoized state before ' + 'componentDidUpdate. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.state`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  17170. }
  17171. }
  17172. }
  17173. {
  17174. instance.componentDidUpdate(prevProps, prevState, instance.__reactInternalSnapshotBeforeUpdate);
  17175. }
  17176. }
  17177. } // TODO: I think this is now always non-null by the time it reaches the
  17178. // commit phase. Consider removing the type check.
  17179. var updateQueue = finishedWork.updateQueue;
  17180. if (updateQueue !== null) {
  17181. {
  17182. if (finishedWork.type === finishedWork.elementType && !didWarnAboutReassigningProps) {
  17183. if (instance.props !== finishedWork.memoizedProps) {
  17184. error('Expected %s props to match memoized props before ' + 'processing the update queue. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.props`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  17185. }
  17186. if (instance.state !== finishedWork.memoizedState) {
  17187. error('Expected %s state to match memoized state before ' + 'processing the update queue. ' + 'This might either be because of a bug in React, or because ' + 'a component reassigns its own `this.state`. ' + 'Please file an issue.', getComponentName(finishedWork.type) || 'instance');
  17188. }
  17189. }
  17190. } // We could update instance props and state here,
  17191. // but instead we rely on them being set during last render.
  17192. // TODO: revisit this when we implement resuming.
  17193. commitUpdateQueue(finishedWork, updateQueue, instance);
  17194. }
  17195. return;
  17196. }
  17197. case HostRoot:
  17198. {
  17199. // TODO: I think this is now always non-null by the time it reaches the
  17200. // commit phase. Consider removing the type check.
  17201. var _updateQueue = finishedWork.updateQueue;
  17202. if (_updateQueue !== null) {
  17203. var _instance = null;
  17204. if (finishedWork.child !== null) {
  17205. switch (finishedWork.child.tag) {
  17206. case HostComponent:
  17207. _instance = getPublicInstance(finishedWork.child.stateNode);
  17208. break;
  17209. case ClassComponent:
  17210. _instance = finishedWork.child.stateNode;
  17211. break;
  17212. }
  17213. }
  17214. commitUpdateQueue(finishedWork, _updateQueue, _instance);
  17215. }
  17216. return;
  17217. }
  17218. case HostComponent:
  17219. {
  17220. var _instance2 = finishedWork.stateNode; // Renderers may schedule work to be done after host components are mounted
  17221. // (eg DOM renderer may schedule auto-focus for inputs and form controls).
  17222. // These effects should only be committed when components are first mounted,
  17223. // aka when there is no current/alternate.
  17224. if (current === null && finishedWork.flags & Update) {
  17225. var type = finishedWork.type;
  17226. var props = finishedWork.memoizedProps;
  17227. commitMount(_instance2, type, props);
  17228. }
  17229. return;
  17230. }
  17231. case HostText:
  17232. {
  17233. // We have no life-cycles associated with text.
  17234. return;
  17235. }
  17236. case HostPortal:
  17237. {
  17238. // We have no life-cycles associated with portals.
  17239. return;
  17240. }
  17241. case Profiler:
  17242. {
  17243. {
  17244. var _finishedWork$memoize2 = finishedWork.memoizedProps,
  17245. onCommit = _finishedWork$memoize2.onCommit,
  17246. onRender = _finishedWork$memoize2.onRender;
  17247. var effectDuration = finishedWork.stateNode.effectDuration;
  17248. var commitTime = getCommitTime();
  17249. if (typeof onRender === 'function') {
  17250. {
  17251. onRender(finishedWork.memoizedProps.id, current === null ? 'mount' : 'update', finishedWork.actualDuration, finishedWork.treeBaseDuration, finishedWork.actualStartTime, commitTime, finishedRoot.memoizedInteractions);
  17252. }
  17253. }
  17254. }
  17255. return;
  17256. }
  17257. case SuspenseComponent:
  17258. {
  17259. commitSuspenseHydrationCallbacks(finishedRoot, finishedWork);
  17260. return;
  17261. }
  17262. case SuspenseListComponent:
  17263. case IncompleteClassComponent:
  17264. case FundamentalComponent:
  17265. case ScopeComponent:
  17266. case OffscreenComponent:
  17267. case LegacyHiddenComponent:
  17268. return;
  17269. }
  17270. {
  17271. {
  17272. throw Error( "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue." );
  17273. }
  17274. }
  17275. }
  17276. function hideOrUnhideAllChildren(finishedWork, isHidden) {
  17277. {
  17278. // We only have the top Fiber that was inserted but we need to recurse down its
  17279. // children to find all the terminal nodes.
  17280. var node = finishedWork;
  17281. while (true) {
  17282. if (node.tag === HostComponent) {
  17283. var instance = node.stateNode;
  17284. if (isHidden) {
  17285. hideInstance(instance);
  17286. } else {
  17287. unhideInstance(node.stateNode, node.memoizedProps);
  17288. }
  17289. } else if (node.tag === HostText) {
  17290. var _instance3 = node.stateNode;
  17291. if (isHidden) {
  17292. hideTextInstance(_instance3);
  17293. } else {
  17294. unhideTextInstance(_instance3, node.memoizedProps);
  17295. }
  17296. } else if ((node.tag === OffscreenComponent || node.tag === LegacyHiddenComponent) && node.memoizedState !== null && node !== finishedWork) ; else if (node.child !== null) {
  17297. node.child.return = node;
  17298. node = node.child;
  17299. continue;
  17300. }
  17301. if (node === finishedWork) {
  17302. return;
  17303. }
  17304. while (node.sibling === null) {
  17305. if (node.return === null || node.return === finishedWork) {
  17306. return;
  17307. }
  17308. node = node.return;
  17309. }
  17310. node.sibling.return = node.return;
  17311. node = node.sibling;
  17312. }
  17313. }
  17314. }
  17315. function commitAttachRef(finishedWork) {
  17316. var ref = finishedWork.ref;
  17317. if (ref !== null) {
  17318. var instance = finishedWork.stateNode;
  17319. var instanceToUse;
  17320. switch (finishedWork.tag) {
  17321. case HostComponent:
  17322. instanceToUse = getPublicInstance(instance);
  17323. break;
  17324. default:
  17325. instanceToUse = instance;
  17326. } // Moved outside to ensure DCE works with this flag
  17327. if (typeof ref === 'function') {
  17328. ref(instanceToUse);
  17329. } else {
  17330. {
  17331. if (!ref.hasOwnProperty('current')) {
  17332. error('Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().', getComponentName(finishedWork.type));
  17333. }
  17334. }
  17335. ref.current = instanceToUse;
  17336. }
  17337. }
  17338. }
  17339. function commitDetachRef(current) {
  17340. var currentRef = current.ref;
  17341. if (currentRef !== null) {
  17342. if (typeof currentRef === 'function') {
  17343. currentRef(null);
  17344. } else {
  17345. currentRef.current = null;
  17346. }
  17347. }
  17348. } // User-originating errors (lifecycles and refs) should not interrupt
  17349. // deletion, so don't let them throw. Host-originating errors should
  17350. // interrupt deletion, so it's okay
  17351. function commitUnmount(finishedRoot, current, renderPriorityLevel) {
  17352. onCommitUnmount(current);
  17353. switch (current.tag) {
  17354. case FunctionComponent:
  17355. case ForwardRef:
  17356. case MemoComponent:
  17357. case SimpleMemoComponent:
  17358. case Block:
  17359. {
  17360. var updateQueue = current.updateQueue;
  17361. if (updateQueue !== null) {
  17362. var lastEffect = updateQueue.lastEffect;
  17363. if (lastEffect !== null) {
  17364. var firstEffect = lastEffect.next;
  17365. var effect = firstEffect;
  17366. do {
  17367. var _effect2 = effect,
  17368. destroy = _effect2.destroy,
  17369. tag = _effect2.tag;
  17370. if (destroy !== undefined) {
  17371. if ((tag & Passive$1) !== NoFlags$1) {
  17372. enqueuePendingPassiveHookEffectUnmount(current, effect);
  17373. } else {
  17374. {
  17375. safelyCallDestroy(current, destroy);
  17376. }
  17377. }
  17378. }
  17379. effect = effect.next;
  17380. } while (effect !== firstEffect);
  17381. }
  17382. }
  17383. return;
  17384. }
  17385. case ClassComponent:
  17386. {
  17387. safelyDetachRef(current);
  17388. var instance = current.stateNode;
  17389. if (typeof instance.componentWillUnmount === 'function') {
  17390. safelyCallComponentWillUnmount(current, instance);
  17391. }
  17392. return;
  17393. }
  17394. case HostComponent:
  17395. {
  17396. safelyDetachRef(current);
  17397. return;
  17398. }
  17399. case HostPortal:
  17400. {
  17401. // TODO: this is recursive.
  17402. // We are also not using this parent because
  17403. // the portal will get pushed immediately.
  17404. {
  17405. unmountHostComponents(finishedRoot, current);
  17406. }
  17407. return;
  17408. }
  17409. case FundamentalComponent:
  17410. {
  17411. return;
  17412. }
  17413. case DehydratedFragment:
  17414. {
  17415. return;
  17416. }
  17417. case ScopeComponent:
  17418. {
  17419. return;
  17420. }
  17421. }
  17422. }
  17423. function commitNestedUnmounts(finishedRoot, root, renderPriorityLevel) {
  17424. // While we're inside a removed host node we don't want to call
  17425. // removeChild on the inner nodes because they're removed by the top
  17426. // call anyway. We also want to call componentWillUnmount on all
  17427. // composites before this host node is removed from the tree. Therefore
  17428. // we do an inner loop while we're still inside the host node.
  17429. var node = root;
  17430. while (true) {
  17431. commitUnmount(finishedRoot, node); // Visit children because they may contain more composite or host nodes.
  17432. // Skip portals because commitUnmount() currently visits them recursively.
  17433. if (node.child !== null && ( // If we use mutation we drill down into portals using commitUnmount above.
  17434. // If we don't use mutation we drill down into portals here instead.
  17435. node.tag !== HostPortal)) {
  17436. node.child.return = node;
  17437. node = node.child;
  17438. continue;
  17439. }
  17440. if (node === root) {
  17441. return;
  17442. }
  17443. while (node.sibling === null) {
  17444. if (node.return === null || node.return === root) {
  17445. return;
  17446. }
  17447. node = node.return;
  17448. }
  17449. node.sibling.return = node.return;
  17450. node = node.sibling;
  17451. }
  17452. }
  17453. function detachFiberMutation(fiber) {
  17454. // Cut off the return pointers to disconnect it from the tree. Ideally, we
  17455. // should clear the child pointer of the parent alternate to let this
  17456. // get GC:ed but we don't know which for sure which parent is the current
  17457. // one so we'll settle for GC:ing the subtree of this child. This child
  17458. // itself will be GC:ed when the parent updates the next time.
  17459. // Note: we cannot null out sibling here, otherwise it can cause issues
  17460. // with findDOMNode and how it requires the sibling field to carry out
  17461. // traversal in a later effect. See PR #16820. We now clear the sibling
  17462. // field after effects, see: detachFiberAfterEffects.
  17463. //
  17464. // Don't disconnect stateNode now; it will be detached in detachFiberAfterEffects.
  17465. // It may be required if the current component is an error boundary,
  17466. // and one of its descendants throws while unmounting a passive effect.
  17467. fiber.alternate = null;
  17468. fiber.child = null;
  17469. fiber.dependencies = null;
  17470. fiber.firstEffect = null;
  17471. fiber.lastEffect = null;
  17472. fiber.memoizedProps = null;
  17473. fiber.memoizedState = null;
  17474. fiber.pendingProps = null;
  17475. fiber.return = null;
  17476. fiber.updateQueue = null;
  17477. {
  17478. fiber._debugOwner = null;
  17479. }
  17480. }
  17481. function getHostParentFiber(fiber) {
  17482. var parent = fiber.return;
  17483. while (parent !== null) {
  17484. if (isHostParent(parent)) {
  17485. return parent;
  17486. }
  17487. parent = parent.return;
  17488. }
  17489. {
  17490. {
  17491. throw Error( "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." );
  17492. }
  17493. }
  17494. }
  17495. function isHostParent(fiber) {
  17496. return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;
  17497. }
  17498. function getHostSibling(fiber) {
  17499. // We're going to search forward into the tree until we find a sibling host
  17500. // node. Unfortunately, if multiple insertions are done in a row we have to
  17501. // search past them. This leads to exponential search for the next sibling.
  17502. // TODO: Find a more efficient way to do this.
  17503. var node = fiber;
  17504. siblings: while (true) {
  17505. // If we didn't find anything, let's try the next sibling.
  17506. while (node.sibling === null) {
  17507. if (node.return === null || isHostParent(node.return)) {
  17508. // If we pop out of the root or hit the parent the fiber we are the
  17509. // last sibling.
  17510. return null;
  17511. }
  17512. node = node.return;
  17513. }
  17514. node.sibling.return = node.return;
  17515. node = node.sibling;
  17516. while (node.tag !== HostComponent && node.tag !== HostText && node.tag !== DehydratedFragment) {
  17517. // If it is not host node and, we might have a host node inside it.
  17518. // Try to search down until we find one.
  17519. if (node.flags & Placement) {
  17520. // If we don't have a child, try the siblings instead.
  17521. continue siblings;
  17522. } // If we don't have a child, try the siblings instead.
  17523. // We also skip portals because they are not part of this host tree.
  17524. if (node.child === null || node.tag === HostPortal) {
  17525. continue siblings;
  17526. } else {
  17527. node.child.return = node;
  17528. node = node.child;
  17529. }
  17530. } // Check if this host node is stable or about to be placed.
  17531. if (!(node.flags & Placement)) {
  17532. // Found it!
  17533. return node.stateNode;
  17534. }
  17535. }
  17536. }
  17537. function commitPlacement(finishedWork) {
  17538. var parentFiber = getHostParentFiber(finishedWork); // Note: these two variables *must* always be updated together.
  17539. var parent;
  17540. var isContainer;
  17541. var parentStateNode = parentFiber.stateNode;
  17542. switch (parentFiber.tag) {
  17543. case HostComponent:
  17544. parent = parentStateNode;
  17545. isContainer = false;
  17546. break;
  17547. case HostRoot:
  17548. parent = parentStateNode.containerInfo;
  17549. isContainer = true;
  17550. break;
  17551. case HostPortal:
  17552. parent = parentStateNode.containerInfo;
  17553. isContainer = true;
  17554. break;
  17555. case FundamentalComponent:
  17556. // eslint-disable-next-line-no-fallthrough
  17557. default:
  17558. {
  17559. {
  17560. throw Error( "Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue." );
  17561. }
  17562. }
  17563. }
  17564. if (parentFiber.flags & ContentReset) {
  17565. // Reset the text content of the parent before doing any insertions
  17566. resetTextContent(parent); // Clear ContentReset from the effect tag
  17567. parentFiber.flags &= ~ContentReset;
  17568. }
  17569. var before = getHostSibling(finishedWork); // We only have the top Fiber that was inserted but we need to recurse down its
  17570. // children to find all the terminal nodes.
  17571. if (isContainer) {
  17572. insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);
  17573. } else {
  17574. insertOrAppendPlacementNode(finishedWork, before, parent);
  17575. }
  17576. }
  17577. function insertOrAppendPlacementNodeIntoContainer(node, before, parent) {
  17578. var tag = node.tag;
  17579. var isHost = tag === HostComponent || tag === HostText;
  17580. if (isHost || enableFundamentalAPI ) {
  17581. var stateNode = isHost ? node.stateNode : node.stateNode.instance;
  17582. if (before) {
  17583. insertInContainerBefore(parent, stateNode, before);
  17584. } else {
  17585. appendChildToContainer(parent, stateNode);
  17586. }
  17587. } else if (tag === HostPortal) ; else {
  17588. var child = node.child;
  17589. if (child !== null) {
  17590. insertOrAppendPlacementNodeIntoContainer(child, before, parent);
  17591. var sibling = child.sibling;
  17592. while (sibling !== null) {
  17593. insertOrAppendPlacementNodeIntoContainer(sibling, before, parent);
  17594. sibling = sibling.sibling;
  17595. }
  17596. }
  17597. }
  17598. }
  17599. function insertOrAppendPlacementNode(node, before, parent) {
  17600. var tag = node.tag;
  17601. var isHost = tag === HostComponent || tag === HostText;
  17602. if (isHost || enableFundamentalAPI ) {
  17603. var stateNode = isHost ? node.stateNode : node.stateNode.instance;
  17604. if (before) {
  17605. insertBefore(parent, stateNode, before);
  17606. } else {
  17607. appendChild(parent, stateNode);
  17608. }
  17609. } else if (tag === HostPortal) ; else {
  17610. var child = node.child;
  17611. if (child !== null) {
  17612. insertOrAppendPlacementNode(child, before, parent);
  17613. var sibling = child.sibling;
  17614. while (sibling !== null) {
  17615. insertOrAppendPlacementNode(sibling, before, parent);
  17616. sibling = sibling.sibling;
  17617. }
  17618. }
  17619. }
  17620. }
  17621. function unmountHostComponents(finishedRoot, current, renderPriorityLevel) {
  17622. // We only have the top Fiber that was deleted but we need to recurse down its
  17623. // children to find all the terminal nodes.
  17624. var node = current; // Each iteration, currentParent is populated with node's host parent if not
  17625. // currentParentIsValid.
  17626. var currentParentIsValid = false; // Note: these two variables *must* always be updated together.
  17627. var currentParent;
  17628. var currentParentIsContainer;
  17629. while (true) {
  17630. if (!currentParentIsValid) {
  17631. var parent = node.return;
  17632. findParent: while (true) {
  17633. if (!(parent !== null)) {
  17634. {
  17635. throw Error( "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." );
  17636. }
  17637. }
  17638. var parentStateNode = parent.stateNode;
  17639. switch (parent.tag) {
  17640. case HostComponent:
  17641. currentParent = parentStateNode;
  17642. currentParentIsContainer = false;
  17643. break findParent;
  17644. case HostRoot:
  17645. currentParent = parentStateNode.containerInfo;
  17646. currentParentIsContainer = true;
  17647. break findParent;
  17648. case HostPortal:
  17649. currentParent = parentStateNode.containerInfo;
  17650. currentParentIsContainer = true;
  17651. break findParent;
  17652. }
  17653. parent = parent.return;
  17654. }
  17655. currentParentIsValid = true;
  17656. }
  17657. if (node.tag === HostComponent || node.tag === HostText) {
  17658. commitNestedUnmounts(finishedRoot, node); // After all the children have unmounted, it is now safe to remove the
  17659. // node from the tree.
  17660. if (currentParentIsContainer) {
  17661. removeChildFromContainer(currentParent, node.stateNode);
  17662. } else {
  17663. removeChild(currentParent, node.stateNode);
  17664. } // Don't visit children because we already visited them.
  17665. } else if (node.tag === HostPortal) {
  17666. if (node.child !== null) {
  17667. // When we go into a portal, it becomes the parent to remove from.
  17668. // We will reassign it back when we pop the portal on the way up.
  17669. currentParent = node.stateNode.containerInfo;
  17670. currentParentIsContainer = true; // Visit children because portals might contain host components.
  17671. node.child.return = node;
  17672. node = node.child;
  17673. continue;
  17674. }
  17675. } else {
  17676. commitUnmount(finishedRoot, node); // Visit children because we may find more host components below.
  17677. if (node.child !== null) {
  17678. node.child.return = node;
  17679. node = node.child;
  17680. continue;
  17681. }
  17682. }
  17683. if (node === current) {
  17684. return;
  17685. }
  17686. while (node.sibling === null) {
  17687. if (node.return === null || node.return === current) {
  17688. return;
  17689. }
  17690. node = node.return;
  17691. if (node.tag === HostPortal) {
  17692. // When we go out of the portal, we need to restore the parent.
  17693. // Since we don't keep a stack of them, we will search for it.
  17694. currentParentIsValid = false;
  17695. }
  17696. }
  17697. node.sibling.return = node.return;
  17698. node = node.sibling;
  17699. }
  17700. }
  17701. function commitDeletion(finishedRoot, current, renderPriorityLevel) {
  17702. {
  17703. // Recursively delete all host nodes from the parent.
  17704. // Detach refs and call componentWillUnmount() on the whole subtree.
  17705. unmountHostComponents(finishedRoot, current);
  17706. }
  17707. var alternate = current.alternate;
  17708. detachFiberMutation(current);
  17709. if (alternate !== null) {
  17710. detachFiberMutation(alternate);
  17711. }
  17712. }
  17713. function commitWork(current, finishedWork) {
  17714. switch (finishedWork.tag) {
  17715. case FunctionComponent:
  17716. case ForwardRef:
  17717. case MemoComponent:
  17718. case SimpleMemoComponent:
  17719. case Block:
  17720. {
  17721. // Layout effects are destroyed during the mutation phase so that all
  17722. // destroy functions for all fibers are called before any create functions.
  17723. // This prevents sibling component effects from interfering with each other,
  17724. // e.g. a destroy function in one component should never override a ref set
  17725. // by a create function in another component during the same commit.
  17726. {
  17727. commitHookEffectListUnmount(Layout | HasEffect, finishedWork);
  17728. }
  17729. return;
  17730. }
  17731. case ClassComponent:
  17732. {
  17733. return;
  17734. }
  17735. case HostComponent:
  17736. {
  17737. var instance = finishedWork.stateNode;
  17738. if (instance != null) {
  17739. // Commit the work prepared earlier.
  17740. var newProps = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  17741. // as the newProps. The updatePayload will contain the real change in
  17742. // this case.
  17743. var oldProps = current !== null ? current.memoizedProps : newProps;
  17744. var type = finishedWork.type; // TODO: Type the updateQueue to be specific to host components.
  17745. var updatePayload = finishedWork.updateQueue;
  17746. finishedWork.updateQueue = null;
  17747. if (updatePayload !== null) {
  17748. commitUpdate(instance, updatePayload, type, oldProps, newProps);
  17749. }
  17750. }
  17751. return;
  17752. }
  17753. case HostText:
  17754. {
  17755. if (!(finishedWork.stateNode !== null)) {
  17756. {
  17757. throw Error( "This should have a text node initialized. This error is likely caused by a bug in React. Please file an issue." );
  17758. }
  17759. }
  17760. var textInstance = finishedWork.stateNode;
  17761. var newText = finishedWork.memoizedProps; // For hydration we reuse the update path but we treat the oldProps
  17762. // as the newProps. The updatePayload will contain the real change in
  17763. // this case.
  17764. var oldText = current !== null ? current.memoizedProps : newText;
  17765. commitTextUpdate(textInstance, oldText, newText);
  17766. return;
  17767. }
  17768. case HostRoot:
  17769. {
  17770. {
  17771. var _root = finishedWork.stateNode;
  17772. if (_root.hydrate) {
  17773. // We've just hydrated. No need to hydrate again.
  17774. _root.hydrate = false;
  17775. commitHydratedContainer(_root.containerInfo);
  17776. }
  17777. }
  17778. return;
  17779. }
  17780. case Profiler:
  17781. {
  17782. return;
  17783. }
  17784. case SuspenseComponent:
  17785. {
  17786. commitSuspenseComponent(finishedWork);
  17787. attachSuspenseRetryListeners(finishedWork);
  17788. return;
  17789. }
  17790. case SuspenseListComponent:
  17791. {
  17792. attachSuspenseRetryListeners(finishedWork);
  17793. return;
  17794. }
  17795. case IncompleteClassComponent:
  17796. {
  17797. return;
  17798. }
  17799. case FundamentalComponent:
  17800. {
  17801. break;
  17802. }
  17803. case ScopeComponent:
  17804. {
  17805. break;
  17806. }
  17807. case OffscreenComponent:
  17808. case LegacyHiddenComponent:
  17809. {
  17810. var newState = finishedWork.memoizedState;
  17811. var isHidden = newState !== null;
  17812. hideOrUnhideAllChildren(finishedWork, isHidden);
  17813. return;
  17814. }
  17815. }
  17816. {
  17817. {
  17818. throw Error( "This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue." );
  17819. }
  17820. }
  17821. }
  17822. function commitSuspenseComponent(finishedWork) {
  17823. var newState = finishedWork.memoizedState;
  17824. if (newState !== null) {
  17825. markCommitTimeOfFallback();
  17826. {
  17827. // Hide the Offscreen component that contains the primary children. TODO:
  17828. // Ideally, this effect would have been scheduled on the Offscreen fiber
  17829. // itself. That's how unhiding works: the Offscreen component schedules an
  17830. // effect on itself. However, in this case, the component didn't complete,
  17831. // so the fiber was never added to the effect list in the normal path. We
  17832. // could have appended it to the effect list in the Suspense component's
  17833. // second pass, but doing it this way is less complicated. This would be
  17834. // simpler if we got rid of the effect list and traversed the tree, like
  17835. // we're planning to do.
  17836. var primaryChildParent = finishedWork.child;
  17837. hideOrUnhideAllChildren(primaryChildParent, true);
  17838. }
  17839. }
  17840. }
  17841. function commitSuspenseHydrationCallbacks(finishedRoot, finishedWork) {
  17842. var newState = finishedWork.memoizedState;
  17843. if (newState === null) {
  17844. var current = finishedWork.alternate;
  17845. if (current !== null) {
  17846. var prevState = current.memoizedState;
  17847. if (prevState !== null) {
  17848. var suspenseInstance = prevState.dehydrated;
  17849. if (suspenseInstance !== null) {
  17850. commitHydratedSuspenseInstance(suspenseInstance);
  17851. }
  17852. }
  17853. }
  17854. }
  17855. }
  17856. function attachSuspenseRetryListeners(finishedWork) {
  17857. // If this boundary just timed out, then it will have a set of wakeables.
  17858. // For each wakeable, attach a listener so that when it resolves, React
  17859. // attempts to re-render the boundary in the primary (pre-timeout) state.
  17860. var wakeables = finishedWork.updateQueue;
  17861. if (wakeables !== null) {
  17862. finishedWork.updateQueue = null;
  17863. var retryCache = finishedWork.stateNode;
  17864. if (retryCache === null) {
  17865. retryCache = finishedWork.stateNode = new PossiblyWeakSet();
  17866. }
  17867. wakeables.forEach(function (wakeable) {
  17868. // Memoize using the boundary fiber to prevent redundant listeners.
  17869. var retry = resolveRetryWakeable.bind(null, finishedWork, wakeable);
  17870. if (!retryCache.has(wakeable)) {
  17871. {
  17872. if (wakeable.__reactDoNotTraceInteractions !== true) {
  17873. retry = unstable_wrap(retry);
  17874. }
  17875. }
  17876. retryCache.add(wakeable);
  17877. wakeable.then(retry, retry);
  17878. }
  17879. });
  17880. }
  17881. } // This function detects when a Suspense boundary goes from visible to hidden.
  17882. // It returns false if the boundary is already hidden.
  17883. // TODO: Use an effect tag.
  17884. function isSuspenseBoundaryBeingHidden(current, finishedWork) {
  17885. if (current !== null) {
  17886. var oldState = current.memoizedState;
  17887. if (oldState === null || oldState.dehydrated !== null) {
  17888. var newState = finishedWork.memoizedState;
  17889. return newState !== null && newState.dehydrated === null;
  17890. }
  17891. }
  17892. return false;
  17893. }
  17894. function commitResetTextContent(current) {
  17895. resetTextContent(current.stateNode);
  17896. }
  17897. var COMPONENT_TYPE = 0;
  17898. var HAS_PSEUDO_CLASS_TYPE = 1;
  17899. var ROLE_TYPE = 2;
  17900. var TEST_NAME_TYPE = 3;
  17901. var TEXT_TYPE = 4;
  17902. if (typeof Symbol === 'function' && Symbol.for) {
  17903. var symbolFor$1 = Symbol.for;
  17904. COMPONENT_TYPE = symbolFor$1('selector.component');
  17905. HAS_PSEUDO_CLASS_TYPE = symbolFor$1('selector.has_pseudo_class');
  17906. ROLE_TYPE = symbolFor$1('selector.role');
  17907. TEST_NAME_TYPE = symbolFor$1('selector.test_id');
  17908. TEXT_TYPE = symbolFor$1('selector.text');
  17909. }
  17910. var commitHooks = [];
  17911. function onCommitRoot$1() {
  17912. {
  17913. commitHooks.forEach(function (commitHook) {
  17914. return commitHook();
  17915. });
  17916. }
  17917. }
  17918. var ceil = Math.ceil;
  17919. var ReactCurrentDispatcher$2 = ReactSharedInternals.ReactCurrentDispatcher,
  17920. ReactCurrentOwner$2 = ReactSharedInternals.ReactCurrentOwner,
  17921. IsSomeRendererActing = ReactSharedInternals.IsSomeRendererActing;
  17922. var NoContext =
  17923. /* */
  17924. 0;
  17925. var BatchedContext =
  17926. /* */
  17927. 1;
  17928. var EventContext =
  17929. /* */
  17930. 2;
  17931. var DiscreteEventContext =
  17932. /* */
  17933. 4;
  17934. var LegacyUnbatchedContext =
  17935. /* */
  17936. 8;
  17937. var RenderContext =
  17938. /* */
  17939. 16;
  17940. var CommitContext =
  17941. /* */
  17942. 32;
  17943. var RetryAfterError =
  17944. /* */
  17945. 64;
  17946. var RootIncomplete = 0;
  17947. var RootFatalErrored = 1;
  17948. var RootErrored = 2;
  17949. var RootSuspended = 3;
  17950. var RootSuspendedWithDelay = 4;
  17951. var RootCompleted = 5; // Describes where we are in the React execution stack
  17952. var executionContext = NoContext; // The root we're working on
  17953. var workInProgressRoot = null; // The fiber we're working on
  17954. var workInProgress = null; // The lanes we're rendering
  17955. var workInProgressRootRenderLanes = NoLanes; // Stack that allows components to change the render lanes for its subtree
  17956. // This is a superset of the lanes we started working on at the root. The only
  17957. // case where it's different from `workInProgressRootRenderLanes` is when we
  17958. // enter a subtree that is hidden and needs to be unhidden: Suspense and
  17959. // Offscreen component.
  17960. //
  17961. // Most things in the work loop should deal with workInProgressRootRenderLanes.
  17962. // Most things in begin/complete phases should deal with subtreeRenderLanes.
  17963. var subtreeRenderLanes = NoLanes;
  17964. var subtreeRenderLanesCursor = createCursor(NoLanes); // Whether to root completed, errored, suspended, etc.
  17965. var workInProgressRootExitStatus = RootIncomplete; // A fatal error, if one is thrown
  17966. var workInProgressRootFatalError = null; // "Included" lanes refer to lanes that were worked on during this render. It's
  17967. // slightly different than `renderLanes` because `renderLanes` can change as you
  17968. // enter and exit an Offscreen tree. This value is the combination of all render
  17969. // lanes for the entire render phase.
  17970. var workInProgressRootIncludedLanes = NoLanes; // The work left over by components that were visited during this render. Only
  17971. // includes unprocessed updates, not work in bailed out children.
  17972. var workInProgressRootSkippedLanes = NoLanes; // Lanes that were updated (in an interleaved event) during this render.
  17973. var workInProgressRootUpdatedLanes = NoLanes; // Lanes that were pinged (in an interleaved event) during this render.
  17974. var workInProgressRootPingedLanes = NoLanes;
  17975. var mostRecentlyUpdatedRoot = null; // The most recent time we committed a fallback. This lets us ensure a train
  17976. // model where we don't commit new loading states in too quick succession.
  17977. var globalMostRecentFallbackTime = 0;
  17978. var FALLBACK_THROTTLE_MS = 500; // The absolute time for when we should start giving up on rendering
  17979. // more and prefer CPU suspense heuristics instead.
  17980. var workInProgressRootRenderTargetTime = Infinity; // How long a render is supposed to take before we start following CPU
  17981. // suspense heuristics and opt out of rendering more content.
  17982. var RENDER_TIMEOUT_MS = 500;
  17983. function resetRenderTimer() {
  17984. workInProgressRootRenderTargetTime = now() + RENDER_TIMEOUT_MS;
  17985. }
  17986. function getRenderTargetTime() {
  17987. return workInProgressRootRenderTargetTime;
  17988. }
  17989. var nextEffect = null;
  17990. var hasUncaughtError = false;
  17991. var firstUncaughtError = null;
  17992. var legacyErrorBoundariesThatAlreadyFailed = null;
  17993. var rootDoesHavePassiveEffects = false;
  17994. var rootWithPendingPassiveEffects = null;
  17995. var pendingPassiveEffectsRenderPriority = NoPriority$1;
  17996. var pendingPassiveEffectsLanes = NoLanes;
  17997. var pendingPassiveHookEffectsMount = [];
  17998. var pendingPassiveHookEffectsUnmount = [];
  17999. var rootsWithPendingDiscreteUpdates = null; // Use these to prevent an infinite loop of nested updates
  18000. var NESTED_UPDATE_LIMIT = 50;
  18001. var nestedUpdateCount = 0;
  18002. var rootWithNestedUpdates = null;
  18003. var NESTED_PASSIVE_UPDATE_LIMIT = 50;
  18004. var nestedPassiveUpdateCount = 0; // Marks the need to reschedule pending interactions at these lanes
  18005. // during the commit phase. This enables them to be traced across components
  18006. // that spawn new work during render. E.g. hidden boundaries, suspended SSR
  18007. // hydration or SuspenseList.
  18008. // TODO: Can use a bitmask instead of an array
  18009. var spawnedWorkDuringRender = null; // If two updates are scheduled within the same event, we should treat their
  18010. // event times as simultaneous, even if the actual clock time has advanced
  18011. // between the first and second call.
  18012. var currentEventTime = NoTimestamp;
  18013. var currentEventWipLanes = NoLanes;
  18014. var currentEventPendingLanes = NoLanes; // Dev only flag that tracks if passive effects are currently being flushed.
  18015. // We warn about state updates for unmounted components differently in this case.
  18016. var isFlushingPassiveEffects = false;
  18017. var focusedInstanceHandle = null;
  18018. var shouldFireAfterActiveInstanceBlur = false;
  18019. function getWorkInProgressRoot() {
  18020. return workInProgressRoot;
  18021. }
  18022. function requestEventTime() {
  18023. if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
  18024. // We're inside React, so it's fine to read the actual time.
  18025. return now();
  18026. } // We're not inside React, so we may be in the middle of a browser event.
  18027. if (currentEventTime !== NoTimestamp) {
  18028. // Use the same start time for all updates until we enter React again.
  18029. return currentEventTime;
  18030. } // This is the first update since React yielded. Compute a new start time.
  18031. currentEventTime = now();
  18032. return currentEventTime;
  18033. }
  18034. function requestUpdateLane(fiber) {
  18035. // Special cases
  18036. var mode = fiber.mode;
  18037. if ((mode & BlockingMode) === NoMode) {
  18038. return SyncLane;
  18039. } else if ((mode & ConcurrentMode) === NoMode) {
  18040. return getCurrentPriorityLevel() === ImmediatePriority$1 ? SyncLane : SyncBatchedLane;
  18041. } // The algorithm for assigning an update to a lane should be stable for all
  18042. // updates at the same priority within the same event. To do this, the inputs
  18043. // to the algorithm must be the same. For example, we use the `renderLanes`
  18044. // to avoid choosing a lane that is already in the middle of rendering.
  18045. //
  18046. // However, the "included" lanes could be mutated in between updates in the
  18047. // same event, like if you perform an update inside `flushSync`. Or any other
  18048. // code path that might call `prepareFreshStack`.
  18049. //
  18050. // The trick we use is to cache the first of each of these inputs within an
  18051. // event. Then reset the cached values once we can be sure the event is over.
  18052. // Our heuristic for that is whenever we enter a concurrent work loop.
  18053. //
  18054. // We'll do the same for `currentEventPendingLanes` below.
  18055. if (currentEventWipLanes === NoLanes) {
  18056. currentEventWipLanes = workInProgressRootIncludedLanes;
  18057. }
  18058. var isTransition = requestCurrentTransition() !== NoTransition;
  18059. if (isTransition) {
  18060. if (currentEventPendingLanes !== NoLanes) {
  18061. currentEventPendingLanes = mostRecentlyUpdatedRoot !== null ? mostRecentlyUpdatedRoot.pendingLanes : NoLanes;
  18062. }
  18063. return findTransitionLane(currentEventWipLanes, currentEventPendingLanes);
  18064. } // TODO: Remove this dependency on the Scheduler priority.
  18065. // To do that, we're replacing it with an update lane priority.
  18066. var schedulerPriority = getCurrentPriorityLevel(); // The old behavior was using the priority level of the Scheduler.
  18067. // This couples React to the Scheduler internals, so we're replacing it
  18068. // with the currentUpdateLanePriority above. As an example of how this
  18069. // could be problematic, if we're not inside `Scheduler.runWithPriority`,
  18070. // then we'll get the priority of the current running Scheduler task,
  18071. // which is probably not what we want.
  18072. var lane;
  18073. if ( // TODO: Temporary. We're removing the concept of discrete updates.
  18074. (executionContext & DiscreteEventContext) !== NoContext && schedulerPriority === UserBlockingPriority$2) {
  18075. lane = findUpdateLane(InputDiscreteLanePriority, currentEventWipLanes);
  18076. } else {
  18077. var schedulerLanePriority = schedulerPriorityToLanePriority(schedulerPriority);
  18078. lane = findUpdateLane(schedulerLanePriority, currentEventWipLanes);
  18079. }
  18080. return lane;
  18081. }
  18082. function requestRetryLane(fiber) {
  18083. // This is a fork of `requestUpdateLane` designed specifically for Suspense
  18084. // "retries" — a special update that attempts to flip a Suspense boundary
  18085. // from its placeholder state to its primary/resolved state.
  18086. // Special cases
  18087. var mode = fiber.mode;
  18088. if ((mode & BlockingMode) === NoMode) {
  18089. return SyncLane;
  18090. } else if ((mode & ConcurrentMode) === NoMode) {
  18091. return getCurrentPriorityLevel() === ImmediatePriority$1 ? SyncLane : SyncBatchedLane;
  18092. } // See `requestUpdateLane` for explanation of `currentEventWipLanes`
  18093. if (currentEventWipLanes === NoLanes) {
  18094. currentEventWipLanes = workInProgressRootIncludedLanes;
  18095. }
  18096. return findRetryLane(currentEventWipLanes);
  18097. }
  18098. function scheduleUpdateOnFiber(fiber, lane, eventTime) {
  18099. checkForNestedUpdates();
  18100. warnAboutRenderPhaseUpdatesInDEV(fiber);
  18101. var root = markUpdateLaneFromFiberToRoot(fiber, lane);
  18102. if (root === null) {
  18103. warnAboutUpdateOnUnmountedFiberInDEV(fiber);
  18104. return null;
  18105. } // Mark that the root has a pending update.
  18106. markRootUpdated(root, lane, eventTime);
  18107. if (root === workInProgressRoot) {
  18108. // Received an update to a tree that's in the middle of rendering. Mark
  18109. // that there was an interleaved update work on this root. Unless the
  18110. // `deferRenderPhaseUpdateToNextBatch` flag is off and this is a render
  18111. // phase update. In that case, we don't treat render phase updates as if
  18112. // they were interleaved, for backwards compat reasons.
  18113. {
  18114. workInProgressRootUpdatedLanes = mergeLanes(workInProgressRootUpdatedLanes, lane);
  18115. }
  18116. if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
  18117. // The root already suspended with a delay, which means this render
  18118. // definitely won't finish. Since we have a new update, let's mark it as
  18119. // suspended now, right before marking the incoming update. This has the
  18120. // effect of interrupting the current render and switching to the update.
  18121. // TODO: Make sure this doesn't override pings that happen while we've
  18122. // already started rendering.
  18123. markRootSuspended$1(root, workInProgressRootRenderLanes);
  18124. }
  18125. } // TODO: requestUpdateLanePriority also reads the priority. Pass the
  18126. // priority as an argument to that function and this one.
  18127. var priorityLevel = getCurrentPriorityLevel();
  18128. if (lane === SyncLane) {
  18129. if ( // Check if we're inside unbatchedUpdates
  18130. (executionContext & LegacyUnbatchedContext) !== NoContext && // Check if we're not already rendering
  18131. (executionContext & (RenderContext | CommitContext)) === NoContext) {
  18132. // Register pending interactions on the root to avoid losing traced interaction data.
  18133. schedulePendingInteractions(root, lane); // This is a legacy edge case. The initial mount of a ReactDOM.render-ed
  18134. // root inside of batchedUpdates should be synchronous, but layout updates
  18135. // should be deferred until the end of the batch.
  18136. performSyncWorkOnRoot(root);
  18137. } else {
  18138. ensureRootIsScheduled(root, eventTime);
  18139. schedulePendingInteractions(root, lane);
  18140. if (executionContext === NoContext) {
  18141. // Flush the synchronous work now, unless we're already working or inside
  18142. // a batch. This is intentionally inside scheduleUpdateOnFiber instead of
  18143. // scheduleCallbackForFiber to preserve the ability to schedule a callback
  18144. // without immediately flushing it. We only do this for user-initiated
  18145. // updates, to preserve historical behavior of legacy mode.
  18146. resetRenderTimer();
  18147. flushSyncCallbackQueue();
  18148. }
  18149. }
  18150. } else {
  18151. // Schedule a discrete update but only if it's not Sync.
  18152. if ((executionContext & DiscreteEventContext) !== NoContext && ( // Only updates at user-blocking priority or greater are considered
  18153. // discrete, even inside a discrete event.
  18154. priorityLevel === UserBlockingPriority$2 || priorityLevel === ImmediatePriority$1)) {
  18155. // This is the result of a discrete event. Track the lowest priority
  18156. // discrete update per root so we can flush them early, if needed.
  18157. if (rootsWithPendingDiscreteUpdates === null) {
  18158. rootsWithPendingDiscreteUpdates = new Set([root]);
  18159. } else {
  18160. rootsWithPendingDiscreteUpdates.add(root);
  18161. }
  18162. } // Schedule other updates after in case the callback is sync.
  18163. ensureRootIsScheduled(root, eventTime);
  18164. schedulePendingInteractions(root, lane);
  18165. } // We use this when assigning a lane for a transition inside
  18166. // `requestUpdateLane`. We assume it's the same as the root being updated,
  18167. // since in the common case of a single root app it probably is. If it's not
  18168. // the same root, then it's not a huge deal, we just might batch more stuff
  18169. // together more than necessary.
  18170. mostRecentlyUpdatedRoot = root;
  18171. } // This is split into a separate function so we can mark a fiber with pending
  18172. // work without treating it as a typical update that originates from an event;
  18173. // e.g. retrying a Suspense boundary isn't an update, but it does schedule work
  18174. // on a fiber.
  18175. function markUpdateLaneFromFiberToRoot(sourceFiber, lane) {
  18176. // Update the source fiber's lanes
  18177. sourceFiber.lanes = mergeLanes(sourceFiber.lanes, lane);
  18178. var alternate = sourceFiber.alternate;
  18179. if (alternate !== null) {
  18180. alternate.lanes = mergeLanes(alternate.lanes, lane);
  18181. }
  18182. {
  18183. if (alternate === null && (sourceFiber.flags & (Placement | Hydrating)) !== NoFlags) {
  18184. warnAboutUpdateOnNotYetMountedFiberInDEV(sourceFiber);
  18185. }
  18186. } // Walk the parent path to the root and update the child expiration time.
  18187. var node = sourceFiber;
  18188. var parent = sourceFiber.return;
  18189. while (parent !== null) {
  18190. parent.childLanes = mergeLanes(parent.childLanes, lane);
  18191. alternate = parent.alternate;
  18192. if (alternate !== null) {
  18193. alternate.childLanes = mergeLanes(alternate.childLanes, lane);
  18194. } else {
  18195. {
  18196. if ((parent.flags & (Placement | Hydrating)) !== NoFlags) {
  18197. warnAboutUpdateOnNotYetMountedFiberInDEV(sourceFiber);
  18198. }
  18199. }
  18200. }
  18201. node = parent;
  18202. parent = parent.return;
  18203. }
  18204. if (node.tag === HostRoot) {
  18205. var root = node.stateNode;
  18206. return root;
  18207. } else {
  18208. return null;
  18209. }
  18210. } // Use this function to schedule a task for a root. There's only one task per
  18211. // root; if a task was already scheduled, we'll check to make sure the priority
  18212. // of the existing task is the same as the priority of the next level that the
  18213. // root has work on. This function is called on every update, and right before
  18214. // exiting a task.
  18215. function ensureRootIsScheduled(root, currentTime) {
  18216. var existingCallbackNode = root.callbackNode; // Check if any lanes are being starved by other work. If so, mark them as
  18217. // expired so we know to work on those next.
  18218. markStarvedLanesAsExpired(root, currentTime); // Determine the next lanes to work on, and their priority.
  18219. var nextLanes = getNextLanes(root, root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes); // This returns the priority level computed during the `getNextLanes` call.
  18220. var newCallbackPriority = returnNextLanesPriority();
  18221. if (nextLanes === NoLanes) {
  18222. // Special case: There's nothing to work on.
  18223. if (existingCallbackNode !== null) {
  18224. cancelCallback(existingCallbackNode);
  18225. root.callbackNode = null;
  18226. root.callbackPriority = NoLanePriority;
  18227. }
  18228. return;
  18229. } // Check if there's an existing task. We may be able to reuse it.
  18230. if (existingCallbackNode !== null) {
  18231. var existingCallbackPriority = root.callbackPriority;
  18232. if (existingCallbackPriority === newCallbackPriority) {
  18233. // The priority hasn't changed. We can reuse the existing task. Exit.
  18234. return;
  18235. } // The priority changed. Cancel the existing callback. We'll schedule a new
  18236. // one below.
  18237. cancelCallback(existingCallbackNode);
  18238. } // Schedule a new callback.
  18239. var newCallbackNode;
  18240. if (newCallbackPriority === SyncLanePriority) {
  18241. // Special case: Sync React callbacks are scheduled on a special
  18242. // internal queue
  18243. newCallbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
  18244. } else if (newCallbackPriority === SyncBatchedLanePriority) {
  18245. newCallbackNode = scheduleCallback(ImmediatePriority$1, performSyncWorkOnRoot.bind(null, root));
  18246. } else {
  18247. var schedulerPriorityLevel = lanePriorityToSchedulerPriority(newCallbackPriority);
  18248. newCallbackNode = scheduleCallback(schedulerPriorityLevel, performConcurrentWorkOnRoot.bind(null, root));
  18249. }
  18250. root.callbackPriority = newCallbackPriority;
  18251. root.callbackNode = newCallbackNode;
  18252. } // This is the entry point for every concurrent task, i.e. anything that
  18253. // goes through Scheduler.
  18254. function performConcurrentWorkOnRoot(root) {
  18255. // Since we know we're in a React event, we can clear the current
  18256. // event time. The next update will compute a new event time.
  18257. currentEventTime = NoTimestamp;
  18258. currentEventWipLanes = NoLanes;
  18259. currentEventPendingLanes = NoLanes;
  18260. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  18261. {
  18262. throw Error( "Should not already be working." );
  18263. }
  18264. } // Flush any pending passive effects before deciding which lanes to work on,
  18265. // in case they schedule additional work.
  18266. var originalCallbackNode = root.callbackNode;
  18267. var didFlushPassiveEffects = flushPassiveEffects();
  18268. if (didFlushPassiveEffects) {
  18269. // Something in the passive effect phase may have canceled the current task.
  18270. // Check if the task node for this root was changed.
  18271. if (root.callbackNode !== originalCallbackNode) {
  18272. // The current task was canceled. Exit. We don't need to call
  18273. // `ensureRootIsScheduled` because the check above implies either that
  18274. // there's a new task, or that there's no remaining work on this root.
  18275. return null;
  18276. }
  18277. } // Determine the next expiration time to work on, using the fields stored
  18278. // on the root.
  18279. var lanes = getNextLanes(root, root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes);
  18280. if (lanes === NoLanes) {
  18281. // Defensive coding. This is never expected to happen.
  18282. return null;
  18283. }
  18284. var exitStatus = renderRootConcurrent(root, lanes);
  18285. if (includesSomeLane(workInProgressRootIncludedLanes, workInProgressRootUpdatedLanes)) {
  18286. // The render included lanes that were updated during the render phase.
  18287. // For example, when unhiding a hidden tree, we include all the lanes
  18288. // that were previously skipped when the tree was hidden. That set of
  18289. // lanes is a superset of the lanes we started rendering with.
  18290. //
  18291. // So we'll throw out the current work and restart.
  18292. prepareFreshStack(root, NoLanes);
  18293. } else if (exitStatus !== RootIncomplete) {
  18294. if (exitStatus === RootErrored) {
  18295. executionContext |= RetryAfterError; // If an error occurred during hydration,
  18296. // discard server response and fall back to client side render.
  18297. if (root.hydrate) {
  18298. root.hydrate = false;
  18299. clearContainer(root.containerInfo);
  18300. } // If something threw an error, try rendering one more time. We'll render
  18301. // synchronously to block concurrent data mutations, and we'll includes
  18302. // all pending updates are included. If it still fails after the second
  18303. // attempt, we'll give up and commit the resulting tree.
  18304. lanes = getLanesToRetrySynchronouslyOnError(root);
  18305. if (lanes !== NoLanes) {
  18306. exitStatus = renderRootSync(root, lanes);
  18307. }
  18308. }
  18309. if (exitStatus === RootFatalErrored) {
  18310. var fatalError = workInProgressRootFatalError;
  18311. prepareFreshStack(root, NoLanes);
  18312. markRootSuspended$1(root, lanes);
  18313. ensureRootIsScheduled(root, now());
  18314. throw fatalError;
  18315. } // We now have a consistent tree. The next step is either to commit it,
  18316. // or, if something suspended, wait to commit it after a timeout.
  18317. var finishedWork = root.current.alternate;
  18318. root.finishedWork = finishedWork;
  18319. root.finishedLanes = lanes;
  18320. finishConcurrentRender(root, exitStatus, lanes);
  18321. }
  18322. ensureRootIsScheduled(root, now());
  18323. if (root.callbackNode === originalCallbackNode) {
  18324. // The task node scheduled for this root is the same one that's
  18325. // currently executed. Need to return a continuation.
  18326. return performConcurrentWorkOnRoot.bind(null, root);
  18327. }
  18328. return null;
  18329. }
  18330. function finishConcurrentRender(root, exitStatus, lanes) {
  18331. switch (exitStatus) {
  18332. case RootIncomplete:
  18333. case RootFatalErrored:
  18334. {
  18335. {
  18336. {
  18337. throw Error( "Root did not complete. This is a bug in React." );
  18338. }
  18339. }
  18340. }
  18341. // Flow knows about invariant, so it complains if I add a break
  18342. // statement, but eslint doesn't know about invariant, so it complains
  18343. // if I do. eslint-disable-next-line no-fallthrough
  18344. case RootErrored:
  18345. {
  18346. // We should have already attempted to retry this tree. If we reached
  18347. // this point, it errored again. Commit it.
  18348. commitRoot(root);
  18349. break;
  18350. }
  18351. case RootSuspended:
  18352. {
  18353. markRootSuspended$1(root, lanes); // We have an acceptable loading state. We need to figure out if we
  18354. // should immediately commit it or wait a bit.
  18355. if (includesOnlyRetries(lanes) && // do not delay if we're inside an act() scope
  18356. !shouldForceFlushFallbacksInDEV()) {
  18357. // This render only included retries, no updates. Throttle committing
  18358. // retries so that we don't show too many loading states too quickly.
  18359. var msUntilTimeout = globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now(); // Don't bother with a very short suspense time.
  18360. if (msUntilTimeout > 10) {
  18361. var nextLanes = getNextLanes(root, NoLanes);
  18362. if (nextLanes !== NoLanes) {
  18363. // There's additional work on this root.
  18364. break;
  18365. }
  18366. var suspendedLanes = root.suspendedLanes;
  18367. if (!isSubsetOfLanes(suspendedLanes, lanes)) {
  18368. // We should prefer to render the fallback of at the last
  18369. // suspended level. Ping the last suspended level to try
  18370. // rendering it again.
  18371. // FIXME: What if the suspended lanes are Idle? Should not restart.
  18372. var eventTime = requestEventTime();
  18373. markRootPinged(root, suspendedLanes);
  18374. break;
  18375. } // The render is suspended, it hasn't timed out, and there's no
  18376. // lower priority work to do. Instead of committing the fallback
  18377. // immediately, wait for more data to arrive.
  18378. root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), msUntilTimeout);
  18379. break;
  18380. }
  18381. } // The work expired. Commit immediately.
  18382. commitRoot(root);
  18383. break;
  18384. }
  18385. case RootSuspendedWithDelay:
  18386. {
  18387. markRootSuspended$1(root, lanes);
  18388. if (includesOnlyTransitions(lanes)) {
  18389. // This is a transition, so we should exit without committing a
  18390. // placeholder and without scheduling a timeout. Delay indefinitely
  18391. // until we receive more data.
  18392. break;
  18393. }
  18394. if (!shouldForceFlushFallbacksInDEV()) {
  18395. // This is not a transition, but we did trigger an avoided state.
  18396. // Schedule a placeholder to display after a short delay, using the Just
  18397. // Noticeable Difference.
  18398. // TODO: Is the JND optimization worth the added complexity? If this is
  18399. // the only reason we track the event time, then probably not.
  18400. // Consider removing.
  18401. var mostRecentEventTime = getMostRecentEventTime(root, lanes);
  18402. var eventTimeMs = mostRecentEventTime;
  18403. var timeElapsedMs = now() - eventTimeMs;
  18404. var _msUntilTimeout = jnd(timeElapsedMs) - timeElapsedMs; // Don't bother with a very short suspense time.
  18405. if (_msUntilTimeout > 10) {
  18406. // Instead of committing the fallback immediately, wait for more data
  18407. // to arrive.
  18408. root.timeoutHandle = scheduleTimeout(commitRoot.bind(null, root), _msUntilTimeout);
  18409. break;
  18410. }
  18411. } // Commit the placeholder.
  18412. commitRoot(root);
  18413. break;
  18414. }
  18415. case RootCompleted:
  18416. {
  18417. // The work completed. Ready to commit.
  18418. commitRoot(root);
  18419. break;
  18420. }
  18421. default:
  18422. {
  18423. {
  18424. {
  18425. throw Error( "Unknown root exit status." );
  18426. }
  18427. }
  18428. }
  18429. }
  18430. }
  18431. function markRootSuspended$1(root, suspendedLanes) {
  18432. // When suspending, we should always exclude lanes that were pinged or (more
  18433. // rarely, since we try to avoid it) updated during the render phase.
  18434. // TODO: Lol maybe there's a better way to factor this besides this
  18435. // obnoxiously named function :)
  18436. suspendedLanes = removeLanes(suspendedLanes, workInProgressRootPingedLanes);
  18437. suspendedLanes = removeLanes(suspendedLanes, workInProgressRootUpdatedLanes);
  18438. markRootSuspended(root, suspendedLanes);
  18439. } // This is the entry point for synchronous tasks that don't go
  18440. // through Scheduler
  18441. function performSyncWorkOnRoot(root) {
  18442. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  18443. {
  18444. throw Error( "Should not already be working." );
  18445. }
  18446. }
  18447. flushPassiveEffects();
  18448. var lanes;
  18449. var exitStatus;
  18450. if (root === workInProgressRoot && includesSomeLane(root.expiredLanes, workInProgressRootRenderLanes)) {
  18451. // There's a partial tree, and at least one of its lanes has expired. Finish
  18452. // rendering it before rendering the rest of the expired work.
  18453. lanes = workInProgressRootRenderLanes;
  18454. exitStatus = renderRootSync(root, lanes);
  18455. if (includesSomeLane(workInProgressRootIncludedLanes, workInProgressRootUpdatedLanes)) {
  18456. // The render included lanes that were updated during the render phase.
  18457. // For example, when unhiding a hidden tree, we include all the lanes
  18458. // that were previously skipped when the tree was hidden. That set of
  18459. // lanes is a superset of the lanes we started rendering with.
  18460. //
  18461. // Note that this only happens when part of the tree is rendered
  18462. // concurrently. If the whole tree is rendered synchronously, then there
  18463. // are no interleaved events.
  18464. lanes = getNextLanes(root, lanes);
  18465. exitStatus = renderRootSync(root, lanes);
  18466. }
  18467. } else {
  18468. lanes = getNextLanes(root, NoLanes);
  18469. exitStatus = renderRootSync(root, lanes);
  18470. }
  18471. if (root.tag !== LegacyRoot && exitStatus === RootErrored) {
  18472. executionContext |= RetryAfterError; // If an error occurred during hydration,
  18473. // discard server response and fall back to client side render.
  18474. if (root.hydrate) {
  18475. root.hydrate = false;
  18476. clearContainer(root.containerInfo);
  18477. } // If something threw an error, try rendering one more time. We'll render
  18478. // synchronously to block concurrent data mutations, and we'll includes
  18479. // all pending updates are included. If it still fails after the second
  18480. // attempt, we'll give up and commit the resulting tree.
  18481. lanes = getLanesToRetrySynchronouslyOnError(root);
  18482. if (lanes !== NoLanes) {
  18483. exitStatus = renderRootSync(root, lanes);
  18484. }
  18485. }
  18486. if (exitStatus === RootFatalErrored) {
  18487. var fatalError = workInProgressRootFatalError;
  18488. prepareFreshStack(root, NoLanes);
  18489. markRootSuspended$1(root, lanes);
  18490. ensureRootIsScheduled(root, now());
  18491. throw fatalError;
  18492. } // We now have a consistent tree. Because this is a sync render, we
  18493. // will commit it even if something suspended.
  18494. var finishedWork = root.current.alternate;
  18495. root.finishedWork = finishedWork;
  18496. root.finishedLanes = lanes;
  18497. commitRoot(root); // Before exiting, make sure there's a callback scheduled for the next
  18498. // pending level.
  18499. ensureRootIsScheduled(root, now());
  18500. return null;
  18501. }
  18502. function flushDiscreteUpdates() {
  18503. // TODO: Should be able to flush inside batchedUpdates, but not inside `act`.
  18504. // However, `act` uses `batchedUpdates`, so there's no way to distinguish
  18505. // those two cases. Need to fix this before exposing flushDiscreteUpdates
  18506. // as a public API.
  18507. if ((executionContext & (BatchedContext | RenderContext | CommitContext)) !== NoContext) {
  18508. {
  18509. if ((executionContext & RenderContext) !== NoContext) {
  18510. error('unstable_flushDiscreteUpdates: Cannot flush updates when React is ' + 'already rendering.');
  18511. }
  18512. } // We're already rendering, so we can't synchronously flush pending work.
  18513. // This is probably a nested event dispatch triggered by a lifecycle/effect,
  18514. // like `el.focus()`. Exit.
  18515. return;
  18516. }
  18517. flushPendingDiscreteUpdates(); // If the discrete updates scheduled passive effects, flush them now so that
  18518. // they fire before the next serial event.
  18519. flushPassiveEffects();
  18520. }
  18521. function flushPendingDiscreteUpdates() {
  18522. if (rootsWithPendingDiscreteUpdates !== null) {
  18523. // For each root with pending discrete updates, schedule a callback to
  18524. // immediately flush them.
  18525. var roots = rootsWithPendingDiscreteUpdates;
  18526. rootsWithPendingDiscreteUpdates = null;
  18527. roots.forEach(function (root) {
  18528. markDiscreteUpdatesExpired(root);
  18529. ensureRootIsScheduled(root, now());
  18530. });
  18531. } // Now flush the immediate queue.
  18532. flushSyncCallbackQueue();
  18533. }
  18534. function batchedUpdates$1(fn, a) {
  18535. var prevExecutionContext = executionContext;
  18536. executionContext |= BatchedContext;
  18537. try {
  18538. return fn(a);
  18539. } finally {
  18540. executionContext = prevExecutionContext;
  18541. if (executionContext === NoContext) {
  18542. // Flush the immediate callbacks that were scheduled during this batch
  18543. resetRenderTimer();
  18544. flushSyncCallbackQueue();
  18545. }
  18546. }
  18547. }
  18548. function batchedEventUpdates$1(fn, a) {
  18549. var prevExecutionContext = executionContext;
  18550. executionContext |= EventContext;
  18551. try {
  18552. return fn(a);
  18553. } finally {
  18554. executionContext = prevExecutionContext;
  18555. if (executionContext === NoContext) {
  18556. // Flush the immediate callbacks that were scheduled during this batch
  18557. resetRenderTimer();
  18558. flushSyncCallbackQueue();
  18559. }
  18560. }
  18561. }
  18562. function discreteUpdates$1(fn, a, b, c, d) {
  18563. var prevExecutionContext = executionContext;
  18564. executionContext |= DiscreteEventContext;
  18565. {
  18566. try {
  18567. return runWithPriority$1(UserBlockingPriority$2, fn.bind(null, a, b, c, d));
  18568. } finally {
  18569. executionContext = prevExecutionContext;
  18570. if (executionContext === NoContext) {
  18571. // Flush the immediate callbacks that were scheduled during this batch
  18572. resetRenderTimer();
  18573. flushSyncCallbackQueue();
  18574. }
  18575. }
  18576. }
  18577. }
  18578. function unbatchedUpdates(fn, a) {
  18579. var prevExecutionContext = executionContext;
  18580. executionContext &= ~BatchedContext;
  18581. executionContext |= LegacyUnbatchedContext;
  18582. try {
  18583. return fn(a);
  18584. } finally {
  18585. executionContext = prevExecutionContext;
  18586. if (executionContext === NoContext) {
  18587. // Flush the immediate callbacks that were scheduled during this batch
  18588. resetRenderTimer();
  18589. flushSyncCallbackQueue();
  18590. }
  18591. }
  18592. }
  18593. function flushSync(fn, a) {
  18594. var prevExecutionContext = executionContext;
  18595. if ((prevExecutionContext & (RenderContext | CommitContext)) !== NoContext) {
  18596. {
  18597. error('flushSync was called from inside a lifecycle method. React cannot ' + 'flush when React is already rendering. Consider moving this call to ' + 'a scheduler task or micro task.');
  18598. }
  18599. return fn(a);
  18600. }
  18601. executionContext |= BatchedContext;
  18602. {
  18603. try {
  18604. if (fn) {
  18605. return runWithPriority$1(ImmediatePriority$1, fn.bind(null, a));
  18606. } else {
  18607. return undefined;
  18608. }
  18609. } finally {
  18610. executionContext = prevExecutionContext; // Flush the immediate callbacks that were scheduled during this batch.
  18611. // Note that this will happen even if batchedUpdates is higher up
  18612. // the stack.
  18613. flushSyncCallbackQueue();
  18614. }
  18615. }
  18616. }
  18617. function pushRenderLanes(fiber, lanes) {
  18618. push(subtreeRenderLanesCursor, subtreeRenderLanes, fiber);
  18619. subtreeRenderLanes = mergeLanes(subtreeRenderLanes, lanes);
  18620. workInProgressRootIncludedLanes = mergeLanes(workInProgressRootIncludedLanes, lanes);
  18621. }
  18622. function popRenderLanes(fiber) {
  18623. subtreeRenderLanes = subtreeRenderLanesCursor.current;
  18624. pop(subtreeRenderLanesCursor, fiber);
  18625. }
  18626. function prepareFreshStack(root, lanes) {
  18627. root.finishedWork = null;
  18628. root.finishedLanes = NoLanes;
  18629. var timeoutHandle = root.timeoutHandle;
  18630. if (timeoutHandle !== noTimeout) {
  18631. // The root previous suspended and scheduled a timeout to commit a fallback
  18632. // state. Now that we have additional work, cancel the timeout.
  18633. root.timeoutHandle = noTimeout; // $FlowFixMe Complains noTimeout is not a TimeoutID, despite the check above
  18634. cancelTimeout(timeoutHandle);
  18635. }
  18636. if (workInProgress !== null) {
  18637. var interruptedWork = workInProgress.return;
  18638. while (interruptedWork !== null) {
  18639. unwindInterruptedWork(interruptedWork);
  18640. interruptedWork = interruptedWork.return;
  18641. }
  18642. }
  18643. workInProgressRoot = root;
  18644. workInProgress = createWorkInProgress(root.current, null);
  18645. workInProgressRootRenderLanes = subtreeRenderLanes = workInProgressRootIncludedLanes = lanes;
  18646. workInProgressRootExitStatus = RootIncomplete;
  18647. workInProgressRootFatalError = null;
  18648. workInProgressRootSkippedLanes = NoLanes;
  18649. workInProgressRootUpdatedLanes = NoLanes;
  18650. workInProgressRootPingedLanes = NoLanes;
  18651. {
  18652. spawnedWorkDuringRender = null;
  18653. }
  18654. {
  18655. ReactStrictModeWarnings.discardPendingWarnings();
  18656. }
  18657. }
  18658. function handleError(root, thrownValue) {
  18659. do {
  18660. var erroredWork = workInProgress;
  18661. try {
  18662. // Reset module-level state that was set during the render phase.
  18663. resetContextDependencies();
  18664. resetHooksAfterThrow();
  18665. resetCurrentFiber(); // TODO: I found and added this missing line while investigating a
  18666. // separate issue. Write a regression test using string refs.
  18667. ReactCurrentOwner$2.current = null;
  18668. if (erroredWork === null || erroredWork.return === null) {
  18669. // Expected to be working on a non-root fiber. This is a fatal error
  18670. // because there's no ancestor that can handle it; the root is
  18671. // supposed to capture all errors that weren't caught by an error
  18672. // boundary.
  18673. workInProgressRootExitStatus = RootFatalErrored;
  18674. workInProgressRootFatalError = thrownValue; // Set `workInProgress` to null. This represents advancing to the next
  18675. // sibling, or the parent if there are no siblings. But since the root
  18676. // has no siblings nor a parent, we set it to null. Usually this is
  18677. // handled by `completeUnitOfWork` or `unwindWork`, but since we're
  18678. // intentionally not calling those, we need set it here.
  18679. // TODO: Consider calling `unwindWork` to pop the contexts.
  18680. workInProgress = null;
  18681. return;
  18682. }
  18683. if (enableProfilerTimer && erroredWork.mode & ProfileMode) {
  18684. // Record the time spent rendering before an error was thrown. This
  18685. // avoids inaccurate Profiler durations in the case of a
  18686. // suspended render.
  18687. stopProfilerTimerIfRunningAndRecordDelta(erroredWork, true);
  18688. }
  18689. throwException(root, erroredWork.return, erroredWork, thrownValue, workInProgressRootRenderLanes);
  18690. completeUnitOfWork(erroredWork);
  18691. } catch (yetAnotherThrownValue) {
  18692. // Something in the return path also threw.
  18693. thrownValue = yetAnotherThrownValue;
  18694. if (workInProgress === erroredWork && erroredWork !== null) {
  18695. // If this boundary has already errored, then we had trouble processing
  18696. // the error. Bubble it to the next boundary.
  18697. erroredWork = erroredWork.return;
  18698. workInProgress = erroredWork;
  18699. } else {
  18700. erroredWork = workInProgress;
  18701. }
  18702. continue;
  18703. } // Return to the normal work loop.
  18704. return;
  18705. } while (true);
  18706. }
  18707. function pushDispatcher() {
  18708. var prevDispatcher = ReactCurrentDispatcher$2.current;
  18709. ReactCurrentDispatcher$2.current = ContextOnlyDispatcher;
  18710. if (prevDispatcher === null) {
  18711. // The React isomorphic package does not include a default dispatcher.
  18712. // Instead the first renderer will lazily attach one, in order to give
  18713. // nicer error messages.
  18714. return ContextOnlyDispatcher;
  18715. } else {
  18716. return prevDispatcher;
  18717. }
  18718. }
  18719. function popDispatcher(prevDispatcher) {
  18720. ReactCurrentDispatcher$2.current = prevDispatcher;
  18721. }
  18722. function pushInteractions(root) {
  18723. {
  18724. var prevInteractions = __interactionsRef.current;
  18725. __interactionsRef.current = root.memoizedInteractions;
  18726. return prevInteractions;
  18727. }
  18728. }
  18729. function popInteractions(prevInteractions) {
  18730. {
  18731. __interactionsRef.current = prevInteractions;
  18732. }
  18733. }
  18734. function markCommitTimeOfFallback() {
  18735. globalMostRecentFallbackTime = now();
  18736. }
  18737. function markSkippedUpdateLanes(lane) {
  18738. workInProgressRootSkippedLanes = mergeLanes(lane, workInProgressRootSkippedLanes);
  18739. }
  18740. function renderDidSuspend() {
  18741. if (workInProgressRootExitStatus === RootIncomplete) {
  18742. workInProgressRootExitStatus = RootSuspended;
  18743. }
  18744. }
  18745. function renderDidSuspendDelayIfPossible() {
  18746. if (workInProgressRootExitStatus === RootIncomplete || workInProgressRootExitStatus === RootSuspended) {
  18747. workInProgressRootExitStatus = RootSuspendedWithDelay;
  18748. } // Check if there are updates that we skipped tree that might have unblocked
  18749. // this render.
  18750. if (workInProgressRoot !== null && (includesNonIdleWork(workInProgressRootSkippedLanes) || includesNonIdleWork(workInProgressRootUpdatedLanes))) {
  18751. // Mark the current render as suspended so that we switch to working on
  18752. // the updates that were skipped. Usually we only suspend at the end of
  18753. // the render phase.
  18754. // TODO: We should probably always mark the root as suspended immediately
  18755. // (inside this function), since by suspending at the end of the render
  18756. // phase introduces a potential mistake where we suspend lanes that were
  18757. // pinged or updated while we were rendering.
  18758. markRootSuspended$1(workInProgressRoot, workInProgressRootRenderLanes);
  18759. }
  18760. }
  18761. function renderDidError() {
  18762. if (workInProgressRootExitStatus !== RootCompleted) {
  18763. workInProgressRootExitStatus = RootErrored;
  18764. }
  18765. } // Called during render to determine if anything has suspended.
  18766. // Returns false if we're not sure.
  18767. function renderHasNotSuspendedYet() {
  18768. // If something errored or completed, we can't really be sure,
  18769. // so those are false.
  18770. return workInProgressRootExitStatus === RootIncomplete;
  18771. }
  18772. function renderRootSync(root, lanes) {
  18773. var prevExecutionContext = executionContext;
  18774. executionContext |= RenderContext;
  18775. var prevDispatcher = pushDispatcher(); // If the root or lanes have changed, throw out the existing stack
  18776. // and prepare a fresh one. Otherwise we'll continue where we left off.
  18777. if (workInProgressRoot !== root || workInProgressRootRenderLanes !== lanes) {
  18778. prepareFreshStack(root, lanes);
  18779. startWorkOnPendingInteractions(root, lanes);
  18780. }
  18781. var prevInteractions = pushInteractions(root);
  18782. do {
  18783. try {
  18784. workLoopSync();
  18785. break;
  18786. } catch (thrownValue) {
  18787. handleError(root, thrownValue);
  18788. }
  18789. } while (true);
  18790. resetContextDependencies();
  18791. {
  18792. popInteractions(prevInteractions);
  18793. }
  18794. executionContext = prevExecutionContext;
  18795. popDispatcher(prevDispatcher);
  18796. if (workInProgress !== null) {
  18797. // This is a sync render, so we should have finished the whole tree.
  18798. {
  18799. {
  18800. throw Error( "Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue." );
  18801. }
  18802. }
  18803. }
  18804. workInProgressRoot = null;
  18805. workInProgressRootRenderLanes = NoLanes;
  18806. return workInProgressRootExitStatus;
  18807. } // The work loop is an extremely hot path. Tell Closure not to inline it.
  18808. /** @noinline */
  18809. function workLoopSync() {
  18810. // Already timed out, so perform work without checking if we need to yield.
  18811. while (workInProgress !== null) {
  18812. performUnitOfWork(workInProgress);
  18813. }
  18814. }
  18815. function renderRootConcurrent(root, lanes) {
  18816. var prevExecutionContext = executionContext;
  18817. executionContext |= RenderContext;
  18818. var prevDispatcher = pushDispatcher(); // If the root or lanes have changed, throw out the existing stack
  18819. // and prepare a fresh one. Otherwise we'll continue where we left off.
  18820. if (workInProgressRoot !== root || workInProgressRootRenderLanes !== lanes) {
  18821. resetRenderTimer();
  18822. prepareFreshStack(root, lanes);
  18823. startWorkOnPendingInteractions(root, lanes);
  18824. }
  18825. var prevInteractions = pushInteractions(root);
  18826. do {
  18827. try {
  18828. workLoopConcurrent();
  18829. break;
  18830. } catch (thrownValue) {
  18831. handleError(root, thrownValue);
  18832. }
  18833. } while (true);
  18834. resetContextDependencies();
  18835. {
  18836. popInteractions(prevInteractions);
  18837. }
  18838. popDispatcher(prevDispatcher);
  18839. executionContext = prevExecutionContext;
  18840. if (workInProgress !== null) {
  18841. return RootIncomplete;
  18842. } else {
  18843. workInProgressRoot = null;
  18844. workInProgressRootRenderLanes = NoLanes; // Return the final exit status.
  18845. return workInProgressRootExitStatus;
  18846. }
  18847. }
  18848. /** @noinline */
  18849. function workLoopConcurrent() {
  18850. // Perform work until Scheduler asks us to yield
  18851. while (workInProgress !== null && !shouldYield()) {
  18852. performUnitOfWork(workInProgress);
  18853. }
  18854. }
  18855. function performUnitOfWork(unitOfWork) {
  18856. // The current, flushed, state of this fiber is the alternate. Ideally
  18857. // nothing should rely on this, but relying on it here means that we don't
  18858. // need an additional field on the work in progress.
  18859. var current = unitOfWork.alternate;
  18860. setCurrentFiber(unitOfWork);
  18861. var next;
  18862. if ( (unitOfWork.mode & ProfileMode) !== NoMode) {
  18863. startProfilerTimer(unitOfWork);
  18864. next = beginWork$1(current, unitOfWork, subtreeRenderLanes);
  18865. stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, true);
  18866. } else {
  18867. next = beginWork$1(current, unitOfWork, subtreeRenderLanes);
  18868. }
  18869. resetCurrentFiber();
  18870. unitOfWork.memoizedProps = unitOfWork.pendingProps;
  18871. if (next === null) {
  18872. // If this doesn't spawn new work, complete the current work.
  18873. completeUnitOfWork(unitOfWork);
  18874. } else {
  18875. workInProgress = next;
  18876. }
  18877. ReactCurrentOwner$2.current = null;
  18878. }
  18879. function completeUnitOfWork(unitOfWork) {
  18880. // Attempt to complete the current unit of work, then move to the next
  18881. // sibling. If there are no more siblings, return to the parent fiber.
  18882. var completedWork = unitOfWork;
  18883. do {
  18884. // The current, flushed, state of this fiber is the alternate. Ideally
  18885. // nothing should rely on this, but relying on it here means that we don't
  18886. // need an additional field on the work in progress.
  18887. var current = completedWork.alternate;
  18888. var returnFiber = completedWork.return; // Check if the work completed or if something threw.
  18889. if ((completedWork.flags & Incomplete) === NoFlags) {
  18890. setCurrentFiber(completedWork);
  18891. var next = void 0;
  18892. if ( (completedWork.mode & ProfileMode) === NoMode) {
  18893. next = completeWork(current, completedWork, subtreeRenderLanes);
  18894. } else {
  18895. startProfilerTimer(completedWork);
  18896. next = completeWork(current, completedWork, subtreeRenderLanes); // Update render duration assuming we didn't error.
  18897. stopProfilerTimerIfRunningAndRecordDelta(completedWork, false);
  18898. }
  18899. resetCurrentFiber();
  18900. if (next !== null) {
  18901. // Completing this fiber spawned new work. Work on that next.
  18902. workInProgress = next;
  18903. return;
  18904. }
  18905. resetChildLanes(completedWork);
  18906. if (returnFiber !== null && // Do not append effects to parents if a sibling failed to complete
  18907. (returnFiber.flags & Incomplete) === NoFlags) {
  18908. // Append all the effects of the subtree and this fiber onto the effect
  18909. // list of the parent. The completion order of the children affects the
  18910. // side-effect order.
  18911. if (returnFiber.firstEffect === null) {
  18912. returnFiber.firstEffect = completedWork.firstEffect;
  18913. }
  18914. if (completedWork.lastEffect !== null) {
  18915. if (returnFiber.lastEffect !== null) {
  18916. returnFiber.lastEffect.nextEffect = completedWork.firstEffect;
  18917. }
  18918. returnFiber.lastEffect = completedWork.lastEffect;
  18919. } // If this fiber had side-effects, we append it AFTER the children's
  18920. // side-effects. We can perform certain side-effects earlier if needed,
  18921. // by doing multiple passes over the effect list. We don't want to
  18922. // schedule our own side-effect on our own list because if end up
  18923. // reusing children we'll schedule this effect onto itself since we're
  18924. // at the end.
  18925. var flags = completedWork.flags; // Skip both NoWork and PerformedWork tags when creating the effect
  18926. // list. PerformedWork effect is read by React DevTools but shouldn't be
  18927. // committed.
  18928. if (flags > PerformedWork) {
  18929. if (returnFiber.lastEffect !== null) {
  18930. returnFiber.lastEffect.nextEffect = completedWork;
  18931. } else {
  18932. returnFiber.firstEffect = completedWork;
  18933. }
  18934. returnFiber.lastEffect = completedWork;
  18935. }
  18936. }
  18937. } else {
  18938. // This fiber did not complete because something threw. Pop values off
  18939. // the stack without entering the complete phase. If this is a boundary,
  18940. // capture values if possible.
  18941. var _next = unwindWork(completedWork); // Because this fiber did not complete, don't reset its expiration time.
  18942. if (_next !== null) {
  18943. // If completing this work spawned new work, do that next. We'll come
  18944. // back here again.
  18945. // Since we're restarting, remove anything that is not a host effect
  18946. // from the effect tag.
  18947. _next.flags &= HostEffectMask;
  18948. workInProgress = _next;
  18949. return;
  18950. }
  18951. if ( (completedWork.mode & ProfileMode) !== NoMode) {
  18952. // Record the render duration for the fiber that errored.
  18953. stopProfilerTimerIfRunningAndRecordDelta(completedWork, false); // Include the time spent working on failed children before continuing.
  18954. var actualDuration = completedWork.actualDuration;
  18955. var child = completedWork.child;
  18956. while (child !== null) {
  18957. actualDuration += child.actualDuration;
  18958. child = child.sibling;
  18959. }
  18960. completedWork.actualDuration = actualDuration;
  18961. }
  18962. if (returnFiber !== null) {
  18963. // Mark the parent fiber as incomplete and clear its effect list.
  18964. returnFiber.firstEffect = returnFiber.lastEffect = null;
  18965. returnFiber.flags |= Incomplete;
  18966. }
  18967. }
  18968. var siblingFiber = completedWork.sibling;
  18969. if (siblingFiber !== null) {
  18970. // If there is more work to do in this returnFiber, do that next.
  18971. workInProgress = siblingFiber;
  18972. return;
  18973. } // Otherwise, return to the parent
  18974. completedWork = returnFiber; // Update the next thing we're working on in case something throws.
  18975. workInProgress = completedWork;
  18976. } while (completedWork !== null); // We've reached the root.
  18977. if (workInProgressRootExitStatus === RootIncomplete) {
  18978. workInProgressRootExitStatus = RootCompleted;
  18979. }
  18980. }
  18981. function resetChildLanes(completedWork) {
  18982. if ( // TODO: Move this check out of the hot path by moving `resetChildLanes`
  18983. // to switch statement in `completeWork`.
  18984. (completedWork.tag === LegacyHiddenComponent || completedWork.tag === OffscreenComponent) && completedWork.memoizedState !== null && !includesSomeLane(subtreeRenderLanes, OffscreenLane) && (completedWork.mode & ConcurrentMode) !== NoLanes) {
  18985. // The children of this component are hidden. Don't bubble their
  18986. // expiration times.
  18987. return;
  18988. }
  18989. var newChildLanes = NoLanes; // Bubble up the earliest expiration time.
  18990. if ( (completedWork.mode & ProfileMode) !== NoMode) {
  18991. // In profiling mode, resetChildExpirationTime is also used to reset
  18992. // profiler durations.
  18993. var actualDuration = completedWork.actualDuration;
  18994. var treeBaseDuration = completedWork.selfBaseDuration; // When a fiber is cloned, its actualDuration is reset to 0. This value will
  18995. // only be updated if work is done on the fiber (i.e. it doesn't bailout).
  18996. // When work is done, it should bubble to the parent's actualDuration. If
  18997. // the fiber has not been cloned though, (meaning no work was done), then
  18998. // this value will reflect the amount of time spent working on a previous
  18999. // render. In that case it should not bubble. We determine whether it was
  19000. // cloned by comparing the child pointer.
  19001. var shouldBubbleActualDurations = completedWork.alternate === null || completedWork.child !== completedWork.alternate.child;
  19002. var child = completedWork.child;
  19003. while (child !== null) {
  19004. newChildLanes = mergeLanes(newChildLanes, mergeLanes(child.lanes, child.childLanes));
  19005. if (shouldBubbleActualDurations) {
  19006. actualDuration += child.actualDuration;
  19007. }
  19008. treeBaseDuration += child.treeBaseDuration;
  19009. child = child.sibling;
  19010. }
  19011. var isTimedOutSuspense = completedWork.tag === SuspenseComponent && completedWork.memoizedState !== null;
  19012. if (isTimedOutSuspense) {
  19013. // Don't count time spent in a timed out Suspense subtree as part of the base duration.
  19014. var primaryChildFragment = completedWork.child;
  19015. if (primaryChildFragment !== null) {
  19016. treeBaseDuration -= primaryChildFragment.treeBaseDuration;
  19017. }
  19018. }
  19019. completedWork.actualDuration = actualDuration;
  19020. completedWork.treeBaseDuration = treeBaseDuration;
  19021. } else {
  19022. var _child = completedWork.child;
  19023. while (_child !== null) {
  19024. newChildLanes = mergeLanes(newChildLanes, mergeLanes(_child.lanes, _child.childLanes));
  19025. _child = _child.sibling;
  19026. }
  19027. }
  19028. completedWork.childLanes = newChildLanes;
  19029. }
  19030. function commitRoot(root) {
  19031. var renderPriorityLevel = getCurrentPriorityLevel();
  19032. runWithPriority$1(ImmediatePriority$1, commitRootImpl.bind(null, root, renderPriorityLevel));
  19033. return null;
  19034. }
  19035. function commitRootImpl(root, renderPriorityLevel) {
  19036. do {
  19037. // `flushPassiveEffects` will call `flushSyncUpdateQueue` at the end, which
  19038. // means `flushPassiveEffects` will sometimes result in additional
  19039. // passive effects. So we need to keep flushing in a loop until there are
  19040. // no more pending effects.
  19041. // TODO: Might be better if `flushPassiveEffects` did not automatically
  19042. // flush synchronous work at the end, to avoid factoring hazards like this.
  19043. flushPassiveEffects();
  19044. } while (rootWithPendingPassiveEffects !== null);
  19045. flushRenderPhaseStrictModeWarningsInDEV();
  19046. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  19047. {
  19048. throw Error( "Should not already be working." );
  19049. }
  19050. }
  19051. var finishedWork = root.finishedWork;
  19052. var lanes = root.finishedLanes;
  19053. if (finishedWork === null) {
  19054. return null;
  19055. }
  19056. root.finishedWork = null;
  19057. root.finishedLanes = NoLanes;
  19058. if (!(finishedWork !== root.current)) {
  19059. {
  19060. throw Error( "Cannot commit the same tree as before. This error is likely caused by a bug in React. Please file an issue." );
  19061. }
  19062. } // commitRoot never returns a continuation; it always finishes synchronously.
  19063. // So we can clear these now to allow a new callback to be scheduled.
  19064. root.callbackNode = null; // Update the first and last pending times on this root. The new first
  19065. // pending time is whatever is left on the root fiber.
  19066. var remainingLanes = mergeLanes(finishedWork.lanes, finishedWork.childLanes);
  19067. markRootFinished(root, remainingLanes); // Clear already finished discrete updates in case that a later call of
  19068. // `flushDiscreteUpdates` starts a useless render pass which may cancels
  19069. // a scheduled timeout.
  19070. if (rootsWithPendingDiscreteUpdates !== null) {
  19071. if (!hasDiscreteLanes(remainingLanes) && rootsWithPendingDiscreteUpdates.has(root)) {
  19072. rootsWithPendingDiscreteUpdates.delete(root);
  19073. }
  19074. }
  19075. if (root === workInProgressRoot) {
  19076. // We can reset these now that they are finished.
  19077. workInProgressRoot = null;
  19078. workInProgress = null;
  19079. workInProgressRootRenderLanes = NoLanes;
  19080. } // Get the list of effects.
  19081. var firstEffect;
  19082. if (finishedWork.flags > PerformedWork) {
  19083. // A fiber's effect list consists only of its children, not itself. So if
  19084. // the root has an effect, we need to add it to the end of the list. The
  19085. // resulting list is the set that would belong to the root's parent, if it
  19086. // had one; that is, all the effects in the tree including the root.
  19087. if (finishedWork.lastEffect !== null) {
  19088. finishedWork.lastEffect.nextEffect = finishedWork;
  19089. firstEffect = finishedWork.firstEffect;
  19090. } else {
  19091. firstEffect = finishedWork;
  19092. }
  19093. } else {
  19094. // There is no effect on the root.
  19095. firstEffect = finishedWork.firstEffect;
  19096. }
  19097. if (firstEffect !== null) {
  19098. var prevExecutionContext = executionContext;
  19099. executionContext |= CommitContext;
  19100. var prevInteractions = pushInteractions(root); // Reset this to null before calling lifecycles
  19101. ReactCurrentOwner$2.current = null; // The commit phase is broken into several sub-phases. We do a separate pass
  19102. // of the effect list for each phase: all mutation effects come before all
  19103. // layout effects, and so on.
  19104. // The first phase a "before mutation" phase. We use this phase to read the
  19105. // state of the host tree right before we mutate it. This is where
  19106. // getSnapshotBeforeUpdate is called.
  19107. focusedInstanceHandle = prepareForCommit(root.containerInfo);
  19108. shouldFireAfterActiveInstanceBlur = false;
  19109. nextEffect = firstEffect;
  19110. do {
  19111. {
  19112. invokeGuardedCallback(null, commitBeforeMutationEffects, null);
  19113. if (hasCaughtError()) {
  19114. if (!(nextEffect !== null)) {
  19115. {
  19116. throw Error( "Should be working on an effect." );
  19117. }
  19118. }
  19119. var error = clearCaughtError();
  19120. captureCommitPhaseError(nextEffect, error);
  19121. nextEffect = nextEffect.nextEffect;
  19122. }
  19123. }
  19124. } while (nextEffect !== null); // We no longer need to track the active instance fiber
  19125. focusedInstanceHandle = null;
  19126. {
  19127. // Mark the current commit time to be shared by all Profilers in this
  19128. // batch. This enables them to be grouped later.
  19129. recordCommitTime();
  19130. } // The next phase is the mutation phase, where we mutate the host tree.
  19131. nextEffect = firstEffect;
  19132. do {
  19133. {
  19134. invokeGuardedCallback(null, commitMutationEffects, null, root, renderPriorityLevel);
  19135. if (hasCaughtError()) {
  19136. if (!(nextEffect !== null)) {
  19137. {
  19138. throw Error( "Should be working on an effect." );
  19139. }
  19140. }
  19141. var _error = clearCaughtError();
  19142. captureCommitPhaseError(nextEffect, _error);
  19143. nextEffect = nextEffect.nextEffect;
  19144. }
  19145. }
  19146. } while (nextEffect !== null);
  19147. resetAfterCommit(root.containerInfo); // The work-in-progress tree is now the current tree. This must come after
  19148. // the mutation phase, so that the previous tree is still current during
  19149. // componentWillUnmount, but before the layout phase, so that the finished
  19150. // work is current during componentDidMount/Update.
  19151. root.current = finishedWork; // The next phase is the layout phase, where we call effects that read
  19152. // the host tree after it's been mutated. The idiomatic use case for this is
  19153. // layout, but class component lifecycles also fire here for legacy reasons.
  19154. nextEffect = firstEffect;
  19155. do {
  19156. {
  19157. invokeGuardedCallback(null, commitLayoutEffects, null, root, lanes);
  19158. if (hasCaughtError()) {
  19159. if (!(nextEffect !== null)) {
  19160. {
  19161. throw Error( "Should be working on an effect." );
  19162. }
  19163. }
  19164. var _error2 = clearCaughtError();
  19165. captureCommitPhaseError(nextEffect, _error2);
  19166. nextEffect = nextEffect.nextEffect;
  19167. }
  19168. }
  19169. } while (nextEffect !== null);
  19170. nextEffect = null; // Tell Scheduler to yield at the end of the frame, so the browser has an
  19171. // opportunity to paint.
  19172. requestPaint();
  19173. {
  19174. popInteractions(prevInteractions);
  19175. }
  19176. executionContext = prevExecutionContext;
  19177. } else {
  19178. // No effects.
  19179. root.current = finishedWork; // Measure these anyway so the flamegraph explicitly shows that there were
  19180. // no effects.
  19181. // TODO: Maybe there's a better way to report this.
  19182. {
  19183. recordCommitTime();
  19184. }
  19185. }
  19186. var rootDidHavePassiveEffects = rootDoesHavePassiveEffects;
  19187. if (rootDoesHavePassiveEffects) {
  19188. // This commit has passive effects. Stash a reference to them. But don't
  19189. // schedule a callback until after flushing layout work.
  19190. rootDoesHavePassiveEffects = false;
  19191. rootWithPendingPassiveEffects = root;
  19192. pendingPassiveEffectsLanes = lanes;
  19193. pendingPassiveEffectsRenderPriority = renderPriorityLevel;
  19194. } else {
  19195. // We are done with the effect chain at this point so let's clear the
  19196. // nextEffect pointers to assist with GC. If we have passive effects, we'll
  19197. // clear this in flushPassiveEffects.
  19198. nextEffect = firstEffect;
  19199. while (nextEffect !== null) {
  19200. var nextNextEffect = nextEffect.nextEffect;
  19201. nextEffect.nextEffect = null;
  19202. if (nextEffect.flags & Deletion) {
  19203. detachFiberAfterEffects(nextEffect);
  19204. }
  19205. nextEffect = nextNextEffect;
  19206. }
  19207. } // Read this again, since an effect might have updated it
  19208. remainingLanes = root.pendingLanes; // Check if there's remaining work on this root
  19209. if (remainingLanes !== NoLanes) {
  19210. {
  19211. if (spawnedWorkDuringRender !== null) {
  19212. var expirationTimes = spawnedWorkDuringRender;
  19213. spawnedWorkDuringRender = null;
  19214. for (var i = 0; i < expirationTimes.length; i++) {
  19215. scheduleInteractions(root, expirationTimes[i], root.memoizedInteractions);
  19216. }
  19217. }
  19218. schedulePendingInteractions(root, remainingLanes);
  19219. }
  19220. } else {
  19221. // If there's no remaining work, we can clear the set of already failed
  19222. // error boundaries.
  19223. legacyErrorBoundariesThatAlreadyFailed = null;
  19224. }
  19225. {
  19226. if (!rootDidHavePassiveEffects) {
  19227. // If there are no passive effects, then we can complete the pending interactions.
  19228. // Otherwise, we'll wait until after the passive effects are flushed.
  19229. // Wait to do this until after remaining work has been scheduled,
  19230. // so that we don't prematurely signal complete for interactions when there's e.g. hidden work.
  19231. finishPendingInteractions(root, lanes);
  19232. }
  19233. }
  19234. if (remainingLanes === SyncLane) {
  19235. // Count the number of times the root synchronously re-renders without
  19236. // finishing. If there are too many, it indicates an infinite update loop.
  19237. if (root === rootWithNestedUpdates) {
  19238. nestedUpdateCount++;
  19239. } else {
  19240. nestedUpdateCount = 0;
  19241. rootWithNestedUpdates = root;
  19242. }
  19243. } else {
  19244. nestedUpdateCount = 0;
  19245. }
  19246. onCommitRoot(finishedWork.stateNode, renderPriorityLevel);
  19247. {
  19248. onCommitRoot$1();
  19249. } // Always call this before exiting `commitRoot`, to ensure that any
  19250. // additional work on this root is scheduled.
  19251. ensureRootIsScheduled(root, now());
  19252. if (hasUncaughtError) {
  19253. hasUncaughtError = false;
  19254. var _error3 = firstUncaughtError;
  19255. firstUncaughtError = null;
  19256. throw _error3;
  19257. }
  19258. if ((executionContext & LegacyUnbatchedContext) !== NoContext) {
  19259. // a ReactDOM.render-ed root inside of batchedUpdates. The commit fired
  19260. // synchronously, but layout updates should be deferred until the end
  19261. // of the batch.
  19262. return null;
  19263. } // If layout work was scheduled, flush it now.
  19264. flushSyncCallbackQueue();
  19265. return null;
  19266. }
  19267. function commitBeforeMutationEffects() {
  19268. while (nextEffect !== null) {
  19269. var current = nextEffect.alternate;
  19270. if (!shouldFireAfterActiveInstanceBlur && focusedInstanceHandle !== null) {
  19271. if ((nextEffect.flags & Deletion) !== NoFlags) {
  19272. if (doesFiberContain(nextEffect, focusedInstanceHandle)) {
  19273. shouldFireAfterActiveInstanceBlur = true;
  19274. }
  19275. } else {
  19276. // TODO: Move this out of the hot path using a dedicated effect tag.
  19277. if (nextEffect.tag === SuspenseComponent && isSuspenseBoundaryBeingHidden(current, nextEffect) && doesFiberContain(nextEffect, focusedInstanceHandle)) {
  19278. shouldFireAfterActiveInstanceBlur = true;
  19279. }
  19280. }
  19281. }
  19282. var flags = nextEffect.flags;
  19283. if ((flags & Snapshot) !== NoFlags) {
  19284. setCurrentFiber(nextEffect);
  19285. commitBeforeMutationLifeCycles(current, nextEffect);
  19286. resetCurrentFiber();
  19287. }
  19288. if ((flags & Passive) !== NoFlags) {
  19289. // If there are passive effects, schedule a callback to flush at
  19290. // the earliest opportunity.
  19291. if (!rootDoesHavePassiveEffects) {
  19292. rootDoesHavePassiveEffects = true;
  19293. scheduleCallback(NormalPriority$1, function () {
  19294. flushPassiveEffects();
  19295. return null;
  19296. });
  19297. }
  19298. }
  19299. nextEffect = nextEffect.nextEffect;
  19300. }
  19301. }
  19302. function commitMutationEffects(root, renderPriorityLevel) {
  19303. // TODO: Should probably move the bulk of this function to commitWork.
  19304. while (nextEffect !== null) {
  19305. setCurrentFiber(nextEffect);
  19306. var flags = nextEffect.flags;
  19307. if (flags & ContentReset) {
  19308. commitResetTextContent(nextEffect);
  19309. }
  19310. if (flags & Ref) {
  19311. var current = nextEffect.alternate;
  19312. if (current !== null) {
  19313. commitDetachRef(current);
  19314. }
  19315. } // The following switch statement is only concerned about placement,
  19316. // updates, and deletions. To avoid needing to add a case for every possible
  19317. // bitmap value, we remove the secondary effects from the effect tag and
  19318. // switch on that value.
  19319. var primaryFlags = flags & (Placement | Update | Deletion | Hydrating);
  19320. switch (primaryFlags) {
  19321. case Placement:
  19322. {
  19323. commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
  19324. // inserted, before any life-cycles like componentDidMount gets called.
  19325. // TODO: findDOMNode doesn't rely on this any more but isMounted does
  19326. // and isMounted is deprecated anyway so we should be able to kill this.
  19327. nextEffect.flags &= ~Placement;
  19328. break;
  19329. }
  19330. case PlacementAndUpdate:
  19331. {
  19332. // Placement
  19333. commitPlacement(nextEffect); // Clear the "placement" from effect tag so that we know that this is
  19334. // inserted, before any life-cycles like componentDidMount gets called.
  19335. nextEffect.flags &= ~Placement; // Update
  19336. var _current = nextEffect.alternate;
  19337. commitWork(_current, nextEffect);
  19338. break;
  19339. }
  19340. case Hydrating:
  19341. {
  19342. nextEffect.flags &= ~Hydrating;
  19343. break;
  19344. }
  19345. case HydratingAndUpdate:
  19346. {
  19347. nextEffect.flags &= ~Hydrating; // Update
  19348. var _current2 = nextEffect.alternate;
  19349. commitWork(_current2, nextEffect);
  19350. break;
  19351. }
  19352. case Update:
  19353. {
  19354. var _current3 = nextEffect.alternate;
  19355. commitWork(_current3, nextEffect);
  19356. break;
  19357. }
  19358. case Deletion:
  19359. {
  19360. commitDeletion(root, nextEffect);
  19361. break;
  19362. }
  19363. }
  19364. resetCurrentFiber();
  19365. nextEffect = nextEffect.nextEffect;
  19366. }
  19367. }
  19368. function commitLayoutEffects(root, committedLanes) {
  19369. while (nextEffect !== null) {
  19370. setCurrentFiber(nextEffect);
  19371. var flags = nextEffect.flags;
  19372. if (flags & (Update | Callback)) {
  19373. var current = nextEffect.alternate;
  19374. commitLifeCycles(root, current, nextEffect);
  19375. }
  19376. {
  19377. if (flags & Ref) {
  19378. commitAttachRef(nextEffect);
  19379. }
  19380. }
  19381. resetCurrentFiber();
  19382. nextEffect = nextEffect.nextEffect;
  19383. }
  19384. }
  19385. function flushPassiveEffects() {
  19386. // Returns whether passive effects were flushed.
  19387. if (pendingPassiveEffectsRenderPriority !== NoPriority$1) {
  19388. var priorityLevel = pendingPassiveEffectsRenderPriority > NormalPriority$1 ? NormalPriority$1 : pendingPassiveEffectsRenderPriority;
  19389. pendingPassiveEffectsRenderPriority = NoPriority$1;
  19390. {
  19391. return runWithPriority$1(priorityLevel, flushPassiveEffectsImpl);
  19392. }
  19393. }
  19394. return false;
  19395. }
  19396. function enqueuePendingPassiveHookEffectMount(fiber, effect) {
  19397. pendingPassiveHookEffectsMount.push(effect, fiber);
  19398. if (!rootDoesHavePassiveEffects) {
  19399. rootDoesHavePassiveEffects = true;
  19400. scheduleCallback(NormalPriority$1, function () {
  19401. flushPassiveEffects();
  19402. return null;
  19403. });
  19404. }
  19405. }
  19406. function enqueuePendingPassiveHookEffectUnmount(fiber, effect) {
  19407. pendingPassiveHookEffectsUnmount.push(effect, fiber);
  19408. {
  19409. fiber.flags |= PassiveUnmountPendingDev;
  19410. var alternate = fiber.alternate;
  19411. if (alternate !== null) {
  19412. alternate.flags |= PassiveUnmountPendingDev;
  19413. }
  19414. }
  19415. if (!rootDoesHavePassiveEffects) {
  19416. rootDoesHavePassiveEffects = true;
  19417. scheduleCallback(NormalPriority$1, function () {
  19418. flushPassiveEffects();
  19419. return null;
  19420. });
  19421. }
  19422. }
  19423. function invokePassiveEffectCreate(effect) {
  19424. var create = effect.create;
  19425. effect.destroy = create();
  19426. }
  19427. function flushPassiveEffectsImpl() {
  19428. if (rootWithPendingPassiveEffects === null) {
  19429. return false;
  19430. }
  19431. var root = rootWithPendingPassiveEffects;
  19432. var lanes = pendingPassiveEffectsLanes;
  19433. rootWithPendingPassiveEffects = null;
  19434. pendingPassiveEffectsLanes = NoLanes;
  19435. if (!((executionContext & (RenderContext | CommitContext)) === NoContext)) {
  19436. {
  19437. throw Error( "Cannot flush passive effects while already rendering." );
  19438. }
  19439. }
  19440. {
  19441. isFlushingPassiveEffects = true;
  19442. }
  19443. var prevExecutionContext = executionContext;
  19444. executionContext |= CommitContext;
  19445. var prevInteractions = pushInteractions(root); // It's important that ALL pending passive effect destroy functions are called
  19446. // before ANY passive effect create functions are called.
  19447. // Otherwise effects in sibling components might interfere with each other.
  19448. // e.g. a destroy function in one component may unintentionally override a ref
  19449. // value set by a create function in another component.
  19450. // Layout effects have the same constraint.
  19451. // First pass: Destroy stale passive effects.
  19452. var unmountEffects = pendingPassiveHookEffectsUnmount;
  19453. pendingPassiveHookEffectsUnmount = [];
  19454. for (var i = 0; i < unmountEffects.length; i += 2) {
  19455. var _effect = unmountEffects[i];
  19456. var fiber = unmountEffects[i + 1];
  19457. var destroy = _effect.destroy;
  19458. _effect.destroy = undefined;
  19459. {
  19460. fiber.flags &= ~PassiveUnmountPendingDev;
  19461. var alternate = fiber.alternate;
  19462. if (alternate !== null) {
  19463. alternate.flags &= ~PassiveUnmountPendingDev;
  19464. }
  19465. }
  19466. if (typeof destroy === 'function') {
  19467. {
  19468. setCurrentFiber(fiber);
  19469. {
  19470. invokeGuardedCallback(null, destroy, null);
  19471. }
  19472. if (hasCaughtError()) {
  19473. if (!(fiber !== null)) {
  19474. {
  19475. throw Error( "Should be working on an effect." );
  19476. }
  19477. }
  19478. var error = clearCaughtError();
  19479. captureCommitPhaseError(fiber, error);
  19480. }
  19481. resetCurrentFiber();
  19482. }
  19483. }
  19484. } // Second pass: Create new passive effects.
  19485. var mountEffects = pendingPassiveHookEffectsMount;
  19486. pendingPassiveHookEffectsMount = [];
  19487. for (var _i = 0; _i < mountEffects.length; _i += 2) {
  19488. var _effect2 = mountEffects[_i];
  19489. var _fiber = mountEffects[_i + 1];
  19490. {
  19491. setCurrentFiber(_fiber);
  19492. {
  19493. invokeGuardedCallback(null, invokePassiveEffectCreate, null, _effect2);
  19494. }
  19495. if (hasCaughtError()) {
  19496. if (!(_fiber !== null)) {
  19497. {
  19498. throw Error( "Should be working on an effect." );
  19499. }
  19500. }
  19501. var _error4 = clearCaughtError();
  19502. captureCommitPhaseError(_fiber, _error4);
  19503. }
  19504. resetCurrentFiber();
  19505. }
  19506. } // Note: This currently assumes there are no passive effects on the root fiber
  19507. // because the root is not part of its own effect list.
  19508. // This could change in the future.
  19509. var effect = root.current.firstEffect;
  19510. while (effect !== null) {
  19511. var nextNextEffect = effect.nextEffect; // Remove nextEffect pointer to assist GC
  19512. effect.nextEffect = null;
  19513. if (effect.flags & Deletion) {
  19514. detachFiberAfterEffects(effect);
  19515. }
  19516. effect = nextNextEffect;
  19517. }
  19518. {
  19519. popInteractions(prevInteractions);
  19520. finishPendingInteractions(root, lanes);
  19521. }
  19522. {
  19523. isFlushingPassiveEffects = false;
  19524. }
  19525. executionContext = prevExecutionContext;
  19526. flushSyncCallbackQueue(); // If additional passive effects were scheduled, increment a counter. If this
  19527. // exceeds the limit, we'll fire a warning.
  19528. nestedPassiveUpdateCount = rootWithPendingPassiveEffects === null ? 0 : nestedPassiveUpdateCount + 1;
  19529. return true;
  19530. }
  19531. function isAlreadyFailedLegacyErrorBoundary(instance) {
  19532. return legacyErrorBoundariesThatAlreadyFailed !== null && legacyErrorBoundariesThatAlreadyFailed.has(instance);
  19533. }
  19534. function markLegacyErrorBoundaryAsFailed(instance) {
  19535. if (legacyErrorBoundariesThatAlreadyFailed === null) {
  19536. legacyErrorBoundariesThatAlreadyFailed = new Set([instance]);
  19537. } else {
  19538. legacyErrorBoundariesThatAlreadyFailed.add(instance);
  19539. }
  19540. }
  19541. function prepareToThrowUncaughtError(error) {
  19542. if (!hasUncaughtError) {
  19543. hasUncaughtError = true;
  19544. firstUncaughtError = error;
  19545. }
  19546. }
  19547. var onUncaughtError = prepareToThrowUncaughtError;
  19548. function captureCommitPhaseErrorOnRoot(rootFiber, sourceFiber, error) {
  19549. var errorInfo = createCapturedValue(error, sourceFiber);
  19550. var update = createRootErrorUpdate(rootFiber, errorInfo, SyncLane);
  19551. enqueueUpdate(rootFiber, update);
  19552. var eventTime = requestEventTime();
  19553. var root = markUpdateLaneFromFiberToRoot(rootFiber, SyncLane);
  19554. if (root !== null) {
  19555. markRootUpdated(root, SyncLane, eventTime);
  19556. ensureRootIsScheduled(root, eventTime);
  19557. schedulePendingInteractions(root, SyncLane);
  19558. }
  19559. }
  19560. function captureCommitPhaseError(sourceFiber, error) {
  19561. if (sourceFiber.tag === HostRoot) {
  19562. // Error was thrown at the root. There is no parent, so the root
  19563. // itself should capture it.
  19564. captureCommitPhaseErrorOnRoot(sourceFiber, sourceFiber, error);
  19565. return;
  19566. }
  19567. var fiber = sourceFiber.return;
  19568. while (fiber !== null) {
  19569. if (fiber.tag === HostRoot) {
  19570. captureCommitPhaseErrorOnRoot(fiber, sourceFiber, error);
  19571. return;
  19572. } else if (fiber.tag === ClassComponent) {
  19573. var ctor = fiber.type;
  19574. var instance = fiber.stateNode;
  19575. if (typeof ctor.getDerivedStateFromError === 'function' || typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
  19576. var errorInfo = createCapturedValue(error, sourceFiber);
  19577. var update = createClassErrorUpdate(fiber, errorInfo, SyncLane);
  19578. enqueueUpdate(fiber, update);
  19579. var eventTime = requestEventTime();
  19580. var root = markUpdateLaneFromFiberToRoot(fiber, SyncLane);
  19581. if (root !== null) {
  19582. markRootUpdated(root, SyncLane, eventTime);
  19583. ensureRootIsScheduled(root, eventTime);
  19584. schedulePendingInteractions(root, SyncLane);
  19585. } else {
  19586. // This component has already been unmounted.
  19587. // We can't schedule any follow up work for the root because the fiber is already unmounted,
  19588. // but we can still call the log-only boundary so the error isn't swallowed.
  19589. //
  19590. // TODO This is only a temporary bandaid for the old reconciler fork.
  19591. // We can delete this special case once the new fork is merged.
  19592. if (typeof instance.componentDidCatch === 'function' && !isAlreadyFailedLegacyErrorBoundary(instance)) {
  19593. try {
  19594. instance.componentDidCatch(error, errorInfo);
  19595. } catch (errorToIgnore) {// TODO Ignore this error? Rethrow it?
  19596. // This is kind of an edge case.
  19597. }
  19598. }
  19599. }
  19600. return;
  19601. }
  19602. }
  19603. fiber = fiber.return;
  19604. }
  19605. }
  19606. function pingSuspendedRoot(root, wakeable, pingedLanes) {
  19607. var pingCache = root.pingCache;
  19608. if (pingCache !== null) {
  19609. // The wakeable resolved, so we no longer need to memoize, because it will
  19610. // never be thrown again.
  19611. pingCache.delete(wakeable);
  19612. }
  19613. var eventTime = requestEventTime();
  19614. markRootPinged(root, pingedLanes);
  19615. if (workInProgressRoot === root && isSubsetOfLanes(workInProgressRootRenderLanes, pingedLanes)) {
  19616. // Received a ping at the same priority level at which we're currently
  19617. // rendering. We might want to restart this render. This should mirror
  19618. // the logic of whether or not a root suspends once it completes.
  19619. // TODO: If we're rendering sync either due to Sync, Batched or expired,
  19620. // we should probably never restart.
  19621. // If we're suspended with delay, or if it's a retry, we'll always suspend
  19622. // so we can always restart.
  19623. if (workInProgressRootExitStatus === RootSuspendedWithDelay || workInProgressRootExitStatus === RootSuspended && includesOnlyRetries(workInProgressRootRenderLanes) && now() - globalMostRecentFallbackTime < FALLBACK_THROTTLE_MS) {
  19624. // Restart from the root.
  19625. prepareFreshStack(root, NoLanes);
  19626. } else {
  19627. // Even though we can't restart right now, we might get an
  19628. // opportunity later. So we mark this render as having a ping.
  19629. workInProgressRootPingedLanes = mergeLanes(workInProgressRootPingedLanes, pingedLanes);
  19630. }
  19631. }
  19632. ensureRootIsScheduled(root, eventTime);
  19633. schedulePendingInteractions(root, pingedLanes);
  19634. }
  19635. function retryTimedOutBoundary(boundaryFiber, retryLane) {
  19636. // The boundary fiber (a Suspense component or SuspenseList component)
  19637. // previously was rendered in its fallback state. One of the promises that
  19638. // suspended it has resolved, which means at least part of the tree was
  19639. // likely unblocked. Try rendering again, at a new expiration time.
  19640. if (retryLane === NoLane) {
  19641. retryLane = requestRetryLane(boundaryFiber);
  19642. } // TODO: Special case idle priority?
  19643. var eventTime = requestEventTime();
  19644. var root = markUpdateLaneFromFiberToRoot(boundaryFiber, retryLane);
  19645. if (root !== null) {
  19646. markRootUpdated(root, retryLane, eventTime);
  19647. ensureRootIsScheduled(root, eventTime);
  19648. schedulePendingInteractions(root, retryLane);
  19649. }
  19650. }
  19651. function resolveRetryWakeable(boundaryFiber, wakeable) {
  19652. var retryLane = NoLane; // Default
  19653. var retryCache;
  19654. {
  19655. retryCache = boundaryFiber.stateNode;
  19656. }
  19657. if (retryCache !== null) {
  19658. // The wakeable resolved, so we no longer need to memoize, because it will
  19659. // never be thrown again.
  19660. retryCache.delete(wakeable);
  19661. }
  19662. retryTimedOutBoundary(boundaryFiber, retryLane);
  19663. } // Computes the next Just Noticeable Difference (JND) boundary.
  19664. // The theory is that a person can't tell the difference between small differences in time.
  19665. // Therefore, if we wait a bit longer than necessary that won't translate to a noticeable
  19666. // difference in the experience. However, waiting for longer might mean that we can avoid
  19667. // showing an intermediate loading state. The longer we have already waited, the harder it
  19668. // is to tell small differences in time. Therefore, the longer we've already waited,
  19669. // the longer we can wait additionally. At some point we have to give up though.
  19670. // We pick a train model where the next boundary commits at a consistent schedule.
  19671. // These particular numbers are vague estimates. We expect to adjust them based on research.
  19672. function jnd(timeElapsed) {
  19673. return timeElapsed < 120 ? 120 : timeElapsed < 480 ? 480 : timeElapsed < 1080 ? 1080 : timeElapsed < 1920 ? 1920 : timeElapsed < 3000 ? 3000 : timeElapsed < 4320 ? 4320 : ceil(timeElapsed / 1960) * 1960;
  19674. }
  19675. function checkForNestedUpdates() {
  19676. if (nestedUpdateCount > NESTED_UPDATE_LIMIT) {
  19677. nestedUpdateCount = 0;
  19678. rootWithNestedUpdates = null;
  19679. {
  19680. {
  19681. throw Error( "Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops." );
  19682. }
  19683. }
  19684. }
  19685. {
  19686. if (nestedPassiveUpdateCount > NESTED_PASSIVE_UPDATE_LIMIT) {
  19687. nestedPassiveUpdateCount = 0;
  19688. error('Maximum update depth exceeded. This can happen when a component ' + "calls setState inside useEffect, but useEffect either doesn't " + 'have a dependency array, or one of the dependencies changes on ' + 'every render.');
  19689. }
  19690. }
  19691. }
  19692. function flushRenderPhaseStrictModeWarningsInDEV() {
  19693. {
  19694. ReactStrictModeWarnings.flushLegacyContextWarning();
  19695. {
  19696. ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings();
  19697. }
  19698. }
  19699. }
  19700. var didWarnStateUpdateForNotYetMountedComponent = null;
  19701. function warnAboutUpdateOnNotYetMountedFiberInDEV(fiber) {
  19702. {
  19703. if ((executionContext & RenderContext) !== NoContext) {
  19704. // We let the other warning about render phase updates deal with this one.
  19705. return;
  19706. }
  19707. if (!(fiber.mode & (BlockingMode | ConcurrentMode))) {
  19708. return;
  19709. }
  19710. var tag = fiber.tag;
  19711. if (tag !== IndeterminateComponent && tag !== HostRoot && tag !== ClassComponent && tag !== FunctionComponent && tag !== ForwardRef && tag !== MemoComponent && tag !== SimpleMemoComponent && tag !== Block) {
  19712. // Only warn for user-defined components, not internal ones like Suspense.
  19713. return;
  19714. } // We show the whole stack but dedupe on the top component's name because
  19715. // the problematic code almost always lies inside that component.
  19716. var componentName = getComponentName(fiber.type) || 'ReactComponent';
  19717. if (didWarnStateUpdateForNotYetMountedComponent !== null) {
  19718. if (didWarnStateUpdateForNotYetMountedComponent.has(componentName)) {
  19719. return;
  19720. }
  19721. didWarnStateUpdateForNotYetMountedComponent.add(componentName);
  19722. } else {
  19723. didWarnStateUpdateForNotYetMountedComponent = new Set([componentName]);
  19724. }
  19725. var previousFiber = current;
  19726. try {
  19727. setCurrentFiber(fiber);
  19728. error("Can't perform a React state update on a component that hasn't mounted yet. " + 'This indicates that you have a side-effect in your render function that ' + 'asynchronously later calls tries to update the component. Move this work to ' + 'useEffect instead.');
  19729. } finally {
  19730. if (previousFiber) {
  19731. setCurrentFiber(fiber);
  19732. } else {
  19733. resetCurrentFiber();
  19734. }
  19735. }
  19736. }
  19737. }
  19738. var didWarnStateUpdateForUnmountedComponent = null;
  19739. function warnAboutUpdateOnUnmountedFiberInDEV(fiber) {
  19740. {
  19741. var tag = fiber.tag;
  19742. if (tag !== HostRoot && tag !== ClassComponent && tag !== FunctionComponent && tag !== ForwardRef && tag !== MemoComponent && tag !== SimpleMemoComponent && tag !== Block) {
  19743. // Only warn for user-defined components, not internal ones like Suspense.
  19744. return;
  19745. } // If there are pending passive effects unmounts for this Fiber,
  19746. // we can assume that they would have prevented this update.
  19747. if ((fiber.flags & PassiveUnmountPendingDev) !== NoFlags) {
  19748. return;
  19749. } // We show the whole stack but dedupe on the top component's name because
  19750. // the problematic code almost always lies inside that component.
  19751. var componentName = getComponentName(fiber.type) || 'ReactComponent';
  19752. if (didWarnStateUpdateForUnmountedComponent !== null) {
  19753. if (didWarnStateUpdateForUnmountedComponent.has(componentName)) {
  19754. return;
  19755. }
  19756. didWarnStateUpdateForUnmountedComponent.add(componentName);
  19757. } else {
  19758. didWarnStateUpdateForUnmountedComponent = new Set([componentName]);
  19759. }
  19760. if (isFlushingPassiveEffects) ; else {
  19761. var previousFiber = current;
  19762. try {
  19763. setCurrentFiber(fiber);
  19764. error("Can't perform a React state update on an unmounted component. This " + 'is a no-op, but it indicates a memory leak in your application. To ' + 'fix, cancel all subscriptions and asynchronous tasks in %s.', tag === ClassComponent ? 'the componentWillUnmount method' : 'a useEffect cleanup function');
  19765. } finally {
  19766. if (previousFiber) {
  19767. setCurrentFiber(fiber);
  19768. } else {
  19769. resetCurrentFiber();
  19770. }
  19771. }
  19772. }
  19773. }
  19774. }
  19775. var beginWork$1;
  19776. {
  19777. var dummyFiber = null;
  19778. beginWork$1 = function (current, unitOfWork, lanes) {
  19779. // If a component throws an error, we replay it again in a synchronously
  19780. // dispatched event, so that the debugger will treat it as an uncaught
  19781. // error See ReactErrorUtils for more information.
  19782. // Before entering the begin phase, copy the work-in-progress onto a dummy
  19783. // fiber. If beginWork throws, we'll use this to reset the state.
  19784. var originalWorkInProgressCopy = assignFiberPropertiesInDEV(dummyFiber, unitOfWork);
  19785. try {
  19786. return beginWork(current, unitOfWork, lanes);
  19787. } catch (originalError) {
  19788. if (originalError !== null && typeof originalError === 'object' && typeof originalError.then === 'function') {
  19789. // Don't replay promises. Treat everything else like an error.
  19790. throw originalError;
  19791. } // Keep this code in sync with handleError; any changes here must have
  19792. // corresponding changes there.
  19793. resetContextDependencies();
  19794. resetHooksAfterThrow(); // Don't reset current debug fiber, since we're about to work on the
  19795. // same fiber again.
  19796. // Unwind the failed stack frame
  19797. unwindInterruptedWork(unitOfWork); // Restore the original properties of the fiber.
  19798. assignFiberPropertiesInDEV(unitOfWork, originalWorkInProgressCopy);
  19799. if ( unitOfWork.mode & ProfileMode) {
  19800. // Reset the profiler timer.
  19801. startProfilerTimer(unitOfWork);
  19802. } // Run beginWork again.
  19803. invokeGuardedCallback(null, beginWork, null, current, unitOfWork, lanes);
  19804. if (hasCaughtError()) {
  19805. var replayError = clearCaughtError(); // `invokeGuardedCallback` sometimes sets an expando `_suppressLogging`.
  19806. // Rethrow this error instead of the original one.
  19807. throw replayError;
  19808. } else {
  19809. // This branch is reachable if the render phase is impure.
  19810. throw originalError;
  19811. }
  19812. }
  19813. };
  19814. }
  19815. var didWarnAboutUpdateInRender = false;
  19816. var didWarnAboutUpdateInRenderForAnotherComponent;
  19817. {
  19818. didWarnAboutUpdateInRenderForAnotherComponent = new Set();
  19819. }
  19820. function warnAboutRenderPhaseUpdatesInDEV(fiber) {
  19821. {
  19822. if (isRendering && (executionContext & RenderContext) !== NoContext && !getIsUpdatingOpaqueValueInRenderPhaseInDEV()) {
  19823. switch (fiber.tag) {
  19824. case FunctionComponent:
  19825. case ForwardRef:
  19826. case SimpleMemoComponent:
  19827. {
  19828. var renderingComponentName = workInProgress && getComponentName(workInProgress.type) || 'Unknown'; // Dedupe by the rendering component because it's the one that needs to be fixed.
  19829. var dedupeKey = renderingComponentName;
  19830. if (!didWarnAboutUpdateInRenderForAnotherComponent.has(dedupeKey)) {
  19831. didWarnAboutUpdateInRenderForAnotherComponent.add(dedupeKey);
  19832. var setStateComponentName = getComponentName(fiber.type) || 'Unknown';
  19833. error('Cannot update a component (`%s`) while rendering a ' + 'different component (`%s`). To locate the bad setState() call inside `%s`, ' + 'follow the stack trace as described in https://reactjs.org/link/setstate-in-render', setStateComponentName, renderingComponentName, renderingComponentName);
  19834. }
  19835. break;
  19836. }
  19837. case ClassComponent:
  19838. {
  19839. if (!didWarnAboutUpdateInRender) {
  19840. error('Cannot update during an existing state transition (such as ' + 'within `render`). Render methods should be a pure ' + 'function of props and state.');
  19841. didWarnAboutUpdateInRender = true;
  19842. }
  19843. break;
  19844. }
  19845. }
  19846. }
  19847. }
  19848. } // a 'shared' variable that changes when act() opens/closes in tests.
  19849. var IsThisRendererActing = {
  19850. current: false
  19851. };
  19852. function warnIfNotScopedWithMatchingAct(fiber) {
  19853. {
  19854. if ( IsSomeRendererActing.current === true && IsThisRendererActing.current !== true) {
  19855. var previousFiber = current;
  19856. try {
  19857. setCurrentFiber(fiber);
  19858. error("It looks like you're using the wrong act() around your test interactions.\n" + 'Be sure to use the matching version of act() corresponding to your renderer:\n\n' + '// for react-dom:\n' + // Break up imports to avoid accidentally parsing them as dependencies.
  19859. 'import {act} fr' + "om 'react-dom/test-utils';\n" + '// ...\n' + 'act(() => ...);\n\n' + '// for react-test-renderer:\n' + // Break up imports to avoid accidentally parsing them as dependencies.
  19860. 'import TestRenderer fr' + "om react-test-renderer';\n" + 'const {act} = TestRenderer;\n' + '// ...\n' + 'act(() => ...);');
  19861. } finally {
  19862. if (previousFiber) {
  19863. setCurrentFiber(fiber);
  19864. } else {
  19865. resetCurrentFiber();
  19866. }
  19867. }
  19868. }
  19869. }
  19870. }
  19871. function warnIfNotCurrentlyActingEffectsInDEV(fiber) {
  19872. {
  19873. if ( (fiber.mode & StrictMode) !== NoMode && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
  19874. error('An update to %s ran an effect, but was not wrapped in act(...).\n\n' + 'When testing, code that causes React state updates should be ' + 'wrapped into act(...):\n\n' + 'act(() => {\n' + ' /* fire events that update state */\n' + '});\n' + '/* assert on the output */\n\n' + "This ensures that you're testing the behavior the user would see " + 'in the browser.' + ' Learn more at https://reactjs.org/link/wrap-tests-with-act', getComponentName(fiber.type));
  19875. }
  19876. }
  19877. }
  19878. function warnIfNotCurrentlyActingUpdatesInDEV(fiber) {
  19879. {
  19880. if ( executionContext === NoContext && IsSomeRendererActing.current === false && IsThisRendererActing.current === false) {
  19881. var previousFiber = current;
  19882. try {
  19883. setCurrentFiber(fiber);
  19884. error('An update to %s inside a test was not wrapped in act(...).\n\n' + 'When testing, code that causes React state updates should be ' + 'wrapped into act(...):\n\n' + 'act(() => {\n' + ' /* fire events that update state */\n' + '});\n' + '/* assert on the output */\n\n' + "This ensures that you're testing the behavior the user would see " + 'in the browser.' + ' Learn more at https://reactjs.org/link/wrap-tests-with-act', getComponentName(fiber.type));
  19885. } finally {
  19886. if (previousFiber) {
  19887. setCurrentFiber(fiber);
  19888. } else {
  19889. resetCurrentFiber();
  19890. }
  19891. }
  19892. }
  19893. }
  19894. }
  19895. var warnIfNotCurrentlyActingUpdatesInDev = warnIfNotCurrentlyActingUpdatesInDEV; // In tests, we want to enforce a mocked scheduler.
  19896. var didWarnAboutUnmockedScheduler = false; // TODO Before we release concurrent mode, revisit this and decide whether a mocked
  19897. // scheduler is the actual recommendation. The alternative could be a testing build,
  19898. // a new lib, or whatever; we dunno just yet. This message is for early adopters
  19899. // to get their tests right.
  19900. function warnIfUnmockedScheduler(fiber) {
  19901. {
  19902. if (didWarnAboutUnmockedScheduler === false && unstable_flushAllWithoutAsserting === undefined) {
  19903. if (fiber.mode & BlockingMode || fiber.mode & ConcurrentMode) {
  19904. didWarnAboutUnmockedScheduler = true;
  19905. error('In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' + 'to guarantee consistent behaviour across tests and browsers. ' + 'For example, with jest: \n' + // Break up requires to avoid accidentally parsing them as dependencies.
  19906. "jest.mock('scheduler', () => require" + "('scheduler/unstable_mock'));\n\n" + 'For more info, visit https://reactjs.org/link/mock-scheduler');
  19907. }
  19908. }
  19909. }
  19910. }
  19911. function computeThreadID(root, lane) {
  19912. // Interaction threads are unique per root and expiration time.
  19913. // NOTE: Intentionally unsound cast. All that matters is that it's a number
  19914. // and it represents a batch of work. Could make a helper function instead,
  19915. // but meh this is fine for now.
  19916. return lane * 1000 + root.interactionThreadID;
  19917. }
  19918. function markSpawnedWork(lane) {
  19919. if (spawnedWorkDuringRender === null) {
  19920. spawnedWorkDuringRender = [lane];
  19921. } else {
  19922. spawnedWorkDuringRender.push(lane);
  19923. }
  19924. }
  19925. function scheduleInteractions(root, lane, interactions) {
  19926. if (interactions.size > 0) {
  19927. var pendingInteractionMap = root.pendingInteractionMap;
  19928. var pendingInteractions = pendingInteractionMap.get(lane);
  19929. if (pendingInteractions != null) {
  19930. interactions.forEach(function (interaction) {
  19931. if (!pendingInteractions.has(interaction)) {
  19932. // Update the pending async work count for previously unscheduled interaction.
  19933. interaction.__count++;
  19934. }
  19935. pendingInteractions.add(interaction);
  19936. });
  19937. } else {
  19938. pendingInteractionMap.set(lane, new Set(interactions)); // Update the pending async work count for the current interactions.
  19939. interactions.forEach(function (interaction) {
  19940. interaction.__count++;
  19941. });
  19942. }
  19943. var subscriber = __subscriberRef.current;
  19944. if (subscriber !== null) {
  19945. var threadID = computeThreadID(root, lane);
  19946. subscriber.onWorkScheduled(interactions, threadID);
  19947. }
  19948. }
  19949. }
  19950. function schedulePendingInteractions(root, lane) {
  19951. scheduleInteractions(root, lane, __interactionsRef.current);
  19952. }
  19953. function startWorkOnPendingInteractions(root, lanes) {
  19954. // we can accurately attribute time spent working on it, And so that cascading
  19955. // work triggered during the render phase will be associated with it.
  19956. var interactions = new Set();
  19957. root.pendingInteractionMap.forEach(function (scheduledInteractions, scheduledLane) {
  19958. if (includesSomeLane(lanes, scheduledLane)) {
  19959. scheduledInteractions.forEach(function (interaction) {
  19960. return interactions.add(interaction);
  19961. });
  19962. }
  19963. }); // Store the current set of interactions on the FiberRoot for a few reasons:
  19964. // We can re-use it in hot functions like performConcurrentWorkOnRoot()
  19965. // without having to recalculate it. We will also use it in commitWork() to
  19966. // pass to any Profiler onRender() hooks. This also provides DevTools with a
  19967. // way to access it when the onCommitRoot() hook is called.
  19968. root.memoizedInteractions = interactions;
  19969. if (interactions.size > 0) {
  19970. var subscriber = __subscriberRef.current;
  19971. if (subscriber !== null) {
  19972. var threadID = computeThreadID(root, lanes);
  19973. try {
  19974. subscriber.onWorkStarted(interactions, threadID);
  19975. } catch (error) {
  19976. // If the subscriber throws, rethrow it in a separate task
  19977. scheduleCallback(ImmediatePriority$1, function () {
  19978. throw error;
  19979. });
  19980. }
  19981. }
  19982. }
  19983. }
  19984. function finishPendingInteractions(root, committedLanes) {
  19985. var remainingLanesAfterCommit = root.pendingLanes;
  19986. var subscriber;
  19987. try {
  19988. subscriber = __subscriberRef.current;
  19989. if (subscriber !== null && root.memoizedInteractions.size > 0) {
  19990. // FIXME: More than one lane can finish in a single commit.
  19991. var threadID = computeThreadID(root, committedLanes);
  19992. subscriber.onWorkStopped(root.memoizedInteractions, threadID);
  19993. }
  19994. } catch (error) {
  19995. // If the subscriber throws, rethrow it in a separate task
  19996. scheduleCallback(ImmediatePriority$1, function () {
  19997. throw error;
  19998. });
  19999. } finally {
  20000. // Clear completed interactions from the pending Map.
  20001. // Unless the render was suspended or cascading work was scheduled,
  20002. // In which case– leave pending interactions until the subsequent render.
  20003. var pendingInteractionMap = root.pendingInteractionMap;
  20004. pendingInteractionMap.forEach(function (scheduledInteractions, lane) {
  20005. // Only decrement the pending interaction count if we're done.
  20006. // If there's still work at the current priority,
  20007. // That indicates that we are waiting for suspense data.
  20008. if (!includesSomeLane(remainingLanesAfterCommit, lane)) {
  20009. pendingInteractionMap.delete(lane);
  20010. scheduledInteractions.forEach(function (interaction) {
  20011. interaction.__count--;
  20012. if (subscriber !== null && interaction.__count === 0) {
  20013. try {
  20014. subscriber.onInteractionScheduledWorkCompleted(interaction);
  20015. } catch (error) {
  20016. // If the subscriber throws, rethrow it in a separate task
  20017. scheduleCallback(ImmediatePriority$1, function () {
  20018. throw error;
  20019. });
  20020. }
  20021. }
  20022. });
  20023. }
  20024. });
  20025. }
  20026. } // `act` testing API
  20027. function shouldForceFlushFallbacksInDEV() {
  20028. // Never force flush in production. This function should get stripped out.
  20029. return actingUpdatesScopeDepth > 0;
  20030. }
  20031. // so we can tell if any async act() calls try to run in parallel.
  20032. var actingUpdatesScopeDepth = 0;
  20033. function detachFiberAfterEffects(fiber) {
  20034. fiber.sibling = null;
  20035. fiber.stateNode = null;
  20036. }
  20037. var resolveFamily = null; // $FlowFixMe Flow gets confused by a WeakSet feature check below.
  20038. var failedBoundaries = null;
  20039. var setRefreshHandler = function (handler) {
  20040. {
  20041. resolveFamily = handler;
  20042. }
  20043. };
  20044. function resolveFunctionForHotReloading(type) {
  20045. {
  20046. if (resolveFamily === null) {
  20047. // Hot reloading is disabled.
  20048. return type;
  20049. }
  20050. var family = resolveFamily(type);
  20051. if (family === undefined) {
  20052. return type;
  20053. } // Use the latest known implementation.
  20054. return family.current;
  20055. }
  20056. }
  20057. function resolveClassForHotReloading(type) {
  20058. // No implementation differences.
  20059. return resolveFunctionForHotReloading(type);
  20060. }
  20061. function resolveForwardRefForHotReloading(type) {
  20062. {
  20063. if (resolveFamily === null) {
  20064. // Hot reloading is disabled.
  20065. return type;
  20066. }
  20067. var family = resolveFamily(type);
  20068. if (family === undefined) {
  20069. // Check if we're dealing with a real forwardRef. Don't want to crash early.
  20070. if (type !== null && type !== undefined && typeof type.render === 'function') {
  20071. // ForwardRef is special because its resolved .type is an object,
  20072. // but it's possible that we only have its inner render function in the map.
  20073. // If that inner render function is different, we'll build a new forwardRef type.
  20074. var currentRender = resolveFunctionForHotReloading(type.render);
  20075. if (type.render !== currentRender) {
  20076. var syntheticType = {
  20077. $$typeof: REACT_FORWARD_REF_TYPE,
  20078. render: currentRender
  20079. };
  20080. if (type.displayName !== undefined) {
  20081. syntheticType.displayName = type.displayName;
  20082. }
  20083. return syntheticType;
  20084. }
  20085. }
  20086. return type;
  20087. } // Use the latest known implementation.
  20088. return family.current;
  20089. }
  20090. }
  20091. function isCompatibleFamilyForHotReloading(fiber, element) {
  20092. {
  20093. if (resolveFamily === null) {
  20094. // Hot reloading is disabled.
  20095. return false;
  20096. }
  20097. var prevType = fiber.elementType;
  20098. var nextType = element.type; // If we got here, we know types aren't === equal.
  20099. var needsCompareFamilies = false;
  20100. var $$typeofNextType = typeof nextType === 'object' && nextType !== null ? nextType.$$typeof : null;
  20101. switch (fiber.tag) {
  20102. case ClassComponent:
  20103. {
  20104. if (typeof nextType === 'function') {
  20105. needsCompareFamilies = true;
  20106. }
  20107. break;
  20108. }
  20109. case FunctionComponent:
  20110. {
  20111. if (typeof nextType === 'function') {
  20112. needsCompareFamilies = true;
  20113. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  20114. // We don't know the inner type yet.
  20115. // We're going to assume that the lazy inner type is stable,
  20116. // and so it is sufficient to avoid reconciling it away.
  20117. // We're not going to unwrap or actually use the new lazy type.
  20118. needsCompareFamilies = true;
  20119. }
  20120. break;
  20121. }
  20122. case ForwardRef:
  20123. {
  20124. if ($$typeofNextType === REACT_FORWARD_REF_TYPE) {
  20125. needsCompareFamilies = true;
  20126. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  20127. needsCompareFamilies = true;
  20128. }
  20129. break;
  20130. }
  20131. case MemoComponent:
  20132. case SimpleMemoComponent:
  20133. {
  20134. if ($$typeofNextType === REACT_MEMO_TYPE) {
  20135. // TODO: if it was but can no longer be simple,
  20136. // we shouldn't set this.
  20137. needsCompareFamilies = true;
  20138. } else if ($$typeofNextType === REACT_LAZY_TYPE) {
  20139. needsCompareFamilies = true;
  20140. }
  20141. break;
  20142. }
  20143. default:
  20144. return false;
  20145. } // Check if both types have a family and it's the same one.
  20146. if (needsCompareFamilies) {
  20147. // Note: memo() and forwardRef() we'll compare outer rather than inner type.
  20148. // This means both of them need to be registered to preserve state.
  20149. // If we unwrapped and compared the inner types for wrappers instead,
  20150. // then we would risk falsely saying two separate memo(Foo)
  20151. // calls are equivalent because they wrap the same Foo function.
  20152. var prevFamily = resolveFamily(prevType);
  20153. if (prevFamily !== undefined && prevFamily === resolveFamily(nextType)) {
  20154. return true;
  20155. }
  20156. }
  20157. return false;
  20158. }
  20159. }
  20160. function markFailedErrorBoundaryForHotReloading(fiber) {
  20161. {
  20162. if (resolveFamily === null) {
  20163. // Hot reloading is disabled.
  20164. return;
  20165. }
  20166. if (typeof WeakSet !== 'function') {
  20167. return;
  20168. }
  20169. if (failedBoundaries === null) {
  20170. failedBoundaries = new WeakSet();
  20171. }
  20172. failedBoundaries.add(fiber);
  20173. }
  20174. }
  20175. var scheduleRefresh = function (root, update) {
  20176. {
  20177. if (resolveFamily === null) {
  20178. // Hot reloading is disabled.
  20179. return;
  20180. }
  20181. var staleFamilies = update.staleFamilies,
  20182. updatedFamilies = update.updatedFamilies;
  20183. flushPassiveEffects();
  20184. flushSync(function () {
  20185. scheduleFibersWithFamiliesRecursively(root.current, updatedFamilies, staleFamilies);
  20186. });
  20187. }
  20188. };
  20189. var scheduleRoot = function (root, element) {
  20190. {
  20191. if (root.context !== emptyContextObject) {
  20192. // Super edge case: root has a legacy _renderSubtree context
  20193. // but we don't know the parentComponent so we can't pass it.
  20194. // Just ignore. We'll delete this with _renderSubtree code path later.
  20195. return;
  20196. }
  20197. flushPassiveEffects();
  20198. flushSync(function () {
  20199. updateContainer(element, root, null, null);
  20200. });
  20201. }
  20202. };
  20203. function scheduleFibersWithFamiliesRecursively(fiber, updatedFamilies, staleFamilies) {
  20204. {
  20205. var alternate = fiber.alternate,
  20206. child = fiber.child,
  20207. sibling = fiber.sibling,
  20208. tag = fiber.tag,
  20209. type = fiber.type;
  20210. var candidateType = null;
  20211. switch (tag) {
  20212. case FunctionComponent:
  20213. case SimpleMemoComponent:
  20214. case ClassComponent:
  20215. candidateType = type;
  20216. break;
  20217. case ForwardRef:
  20218. candidateType = type.render;
  20219. break;
  20220. }
  20221. if (resolveFamily === null) {
  20222. throw new Error('Expected resolveFamily to be set during hot reload.');
  20223. }
  20224. var needsRender = false;
  20225. var needsRemount = false;
  20226. if (candidateType !== null) {
  20227. var family = resolveFamily(candidateType);
  20228. if (family !== undefined) {
  20229. if (staleFamilies.has(family)) {
  20230. needsRemount = true;
  20231. } else if (updatedFamilies.has(family)) {
  20232. if (tag === ClassComponent) {
  20233. needsRemount = true;
  20234. } else {
  20235. needsRender = true;
  20236. }
  20237. }
  20238. }
  20239. }
  20240. if (failedBoundaries !== null) {
  20241. if (failedBoundaries.has(fiber) || alternate !== null && failedBoundaries.has(alternate)) {
  20242. needsRemount = true;
  20243. }
  20244. }
  20245. if (needsRemount) {
  20246. fiber._debugNeedsRemount = true;
  20247. }
  20248. if (needsRemount || needsRender) {
  20249. scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
  20250. }
  20251. if (child !== null && !needsRemount) {
  20252. scheduleFibersWithFamiliesRecursively(child, updatedFamilies, staleFamilies);
  20253. }
  20254. if (sibling !== null) {
  20255. scheduleFibersWithFamiliesRecursively(sibling, updatedFamilies, staleFamilies);
  20256. }
  20257. }
  20258. }
  20259. var findHostInstancesForRefresh = function (root, families) {
  20260. {
  20261. var hostInstances = new Set();
  20262. var types = new Set(families.map(function (family) {
  20263. return family.current;
  20264. }));
  20265. findHostInstancesForMatchingFibersRecursively(root.current, types, hostInstances);
  20266. return hostInstances;
  20267. }
  20268. };
  20269. function findHostInstancesForMatchingFibersRecursively(fiber, types, hostInstances) {
  20270. {
  20271. var child = fiber.child,
  20272. sibling = fiber.sibling,
  20273. tag = fiber.tag,
  20274. type = fiber.type;
  20275. var candidateType = null;
  20276. switch (tag) {
  20277. case FunctionComponent:
  20278. case SimpleMemoComponent:
  20279. case ClassComponent:
  20280. candidateType = type;
  20281. break;
  20282. case ForwardRef:
  20283. candidateType = type.render;
  20284. break;
  20285. }
  20286. var didMatch = false;
  20287. if (candidateType !== null) {
  20288. if (types.has(candidateType)) {
  20289. didMatch = true;
  20290. }
  20291. }
  20292. if (didMatch) {
  20293. // We have a match. This only drills down to the closest host components.
  20294. // There's no need to search deeper because for the purpose of giving
  20295. // visual feedback, "flashing" outermost parent rectangles is sufficient.
  20296. findHostInstancesForFiberShallowly(fiber, hostInstances);
  20297. } else {
  20298. // If there's no match, maybe there will be one further down in the child tree.
  20299. if (child !== null) {
  20300. findHostInstancesForMatchingFibersRecursively(child, types, hostInstances);
  20301. }
  20302. }
  20303. if (sibling !== null) {
  20304. findHostInstancesForMatchingFibersRecursively(sibling, types, hostInstances);
  20305. }
  20306. }
  20307. }
  20308. function findHostInstancesForFiberShallowly(fiber, hostInstances) {
  20309. {
  20310. var foundHostInstances = findChildHostInstancesForFiberShallowly(fiber, hostInstances);
  20311. if (foundHostInstances) {
  20312. return;
  20313. } // If we didn't find any host children, fallback to closest host parent.
  20314. var node = fiber;
  20315. while (true) {
  20316. switch (node.tag) {
  20317. case HostComponent:
  20318. hostInstances.add(node.stateNode);
  20319. return;
  20320. case HostPortal:
  20321. hostInstances.add(node.stateNode.containerInfo);
  20322. return;
  20323. case HostRoot:
  20324. hostInstances.add(node.stateNode.containerInfo);
  20325. return;
  20326. }
  20327. if (node.return === null) {
  20328. throw new Error('Expected to reach root first.');
  20329. }
  20330. node = node.return;
  20331. }
  20332. }
  20333. }
  20334. function findChildHostInstancesForFiberShallowly(fiber, hostInstances) {
  20335. {
  20336. var node = fiber;
  20337. var foundHostInstances = false;
  20338. while (true) {
  20339. if (node.tag === HostComponent) {
  20340. // We got a match.
  20341. foundHostInstances = true;
  20342. hostInstances.add(node.stateNode); // There may still be more, so keep searching.
  20343. } else if (node.child !== null) {
  20344. node.child.return = node;
  20345. node = node.child;
  20346. continue;
  20347. }
  20348. if (node === fiber) {
  20349. return foundHostInstances;
  20350. }
  20351. while (node.sibling === null) {
  20352. if (node.return === null || node.return === fiber) {
  20353. return foundHostInstances;
  20354. }
  20355. node = node.return;
  20356. }
  20357. node.sibling.return = node.return;
  20358. node = node.sibling;
  20359. }
  20360. }
  20361. return false;
  20362. }
  20363. var hasBadMapPolyfill;
  20364. {
  20365. hasBadMapPolyfill = false;
  20366. try {
  20367. var nonExtensibleObject = Object.preventExtensions({});
  20368. /* eslint-disable no-new */
  20369. new Map([[nonExtensibleObject, null]]);
  20370. new Set([nonExtensibleObject]);
  20371. /* eslint-enable no-new */
  20372. } catch (e) {
  20373. // TODO: Consider warning about bad polyfills
  20374. hasBadMapPolyfill = true;
  20375. }
  20376. }
  20377. var debugCounter = 1;
  20378. function FiberNode(tag, pendingProps, key, mode) {
  20379. // Instance
  20380. this.tag = tag;
  20381. this.key = key;
  20382. this.elementType = null;
  20383. this.type = null;
  20384. this.stateNode = null; // Fiber
  20385. this.return = null;
  20386. this.child = null;
  20387. this.sibling = null;
  20388. this.index = 0;
  20389. this.ref = null;
  20390. this.pendingProps = pendingProps;
  20391. this.memoizedProps = null;
  20392. this.updateQueue = null;
  20393. this.memoizedState = null;
  20394. this.dependencies = null;
  20395. this.mode = mode; // Effects
  20396. this.flags = NoFlags;
  20397. this.nextEffect = null;
  20398. this.firstEffect = null;
  20399. this.lastEffect = null;
  20400. this.lanes = NoLanes;
  20401. this.childLanes = NoLanes;
  20402. this.alternate = null;
  20403. {
  20404. // Note: The following is done to avoid a v8 performance cliff.
  20405. //
  20406. // Initializing the fields below to smis and later updating them with
  20407. // double values will cause Fibers to end up having separate shapes.
  20408. // This behavior/bug has something to do with Object.preventExtension().
  20409. // Fortunately this only impacts DEV builds.
  20410. // Unfortunately it makes React unusably slow for some applications.
  20411. // To work around this, initialize the fields below with doubles.
  20412. //
  20413. // Learn more about this here:
  20414. // https://github.com/facebook/react/issues/14365
  20415. // https://bugs.chromium.org/p/v8/issues/detail?id=8538
  20416. this.actualDuration = Number.NaN;
  20417. this.actualStartTime = Number.NaN;
  20418. this.selfBaseDuration = Number.NaN;
  20419. this.treeBaseDuration = Number.NaN; // It's okay to replace the initial doubles with smis after initialization.
  20420. // This won't trigger the performance cliff mentioned above,
  20421. // and it simplifies other profiler code (including DevTools).
  20422. this.actualDuration = 0;
  20423. this.actualStartTime = -1;
  20424. this.selfBaseDuration = 0;
  20425. this.treeBaseDuration = 0;
  20426. }
  20427. {
  20428. // This isn't directly used but is handy for debugging internals:
  20429. this._debugID = debugCounter++;
  20430. this._debugSource = null;
  20431. this._debugOwner = null;
  20432. this._debugNeedsRemount = false;
  20433. this._debugHookTypes = null;
  20434. if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
  20435. Object.preventExtensions(this);
  20436. }
  20437. }
  20438. } // This is a constructor function, rather than a POJO constructor, still
  20439. // please ensure we do the following:
  20440. // 1) Nobody should add any instance methods on this. Instance methods can be
  20441. // more difficult to predict when they get optimized and they are almost
  20442. // never inlined properly in static compilers.
  20443. // 2) Nobody should rely on `instanceof Fiber` for type testing. We should
  20444. // always know when it is a fiber.
  20445. // 3) We might want to experiment with using numeric keys since they are easier
  20446. // to optimize in a non-JIT environment.
  20447. // 4) We can easily go from a constructor to a createFiber object literal if that
  20448. // is faster.
  20449. // 5) It should be easy to port this to a C struct and keep a C implementation
  20450. // compatible.
  20451. var createFiber = function (tag, pendingProps, key, mode) {
  20452. // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors
  20453. return new FiberNode(tag, pendingProps, key, mode);
  20454. };
  20455. function shouldConstruct$1(Component) {
  20456. var prototype = Component.prototype;
  20457. return !!(prototype && prototype.isReactComponent);
  20458. }
  20459. function isSimpleFunctionComponent(type) {
  20460. return typeof type === 'function' && !shouldConstruct$1(type) && type.defaultProps === undefined;
  20461. }
  20462. function resolveLazyComponentTag(Component) {
  20463. if (typeof Component === 'function') {
  20464. return shouldConstruct$1(Component) ? ClassComponent : FunctionComponent;
  20465. } else if (Component !== undefined && Component !== null) {
  20466. var $$typeof = Component.$$typeof;
  20467. if ($$typeof === REACT_FORWARD_REF_TYPE) {
  20468. return ForwardRef;
  20469. }
  20470. if ($$typeof === REACT_MEMO_TYPE) {
  20471. return MemoComponent;
  20472. }
  20473. }
  20474. return IndeterminateComponent;
  20475. } // This is used to create an alternate fiber to do work on.
  20476. function createWorkInProgress(current, pendingProps) {
  20477. var workInProgress = current.alternate;
  20478. if (workInProgress === null) {
  20479. // We use a double buffering pooling technique because we know that we'll
  20480. // only ever need at most two versions of a tree. We pool the "other" unused
  20481. // node that we're free to reuse. This is lazily created to avoid allocating
  20482. // extra objects for things that are never updated. It also allow us to
  20483. // reclaim the extra memory if needed.
  20484. workInProgress = createFiber(current.tag, pendingProps, current.key, current.mode);
  20485. workInProgress.elementType = current.elementType;
  20486. workInProgress.type = current.type;
  20487. workInProgress.stateNode = current.stateNode;
  20488. {
  20489. // DEV-only fields
  20490. workInProgress._debugID = current._debugID;
  20491. workInProgress._debugSource = current._debugSource;
  20492. workInProgress._debugOwner = current._debugOwner;
  20493. workInProgress._debugHookTypes = current._debugHookTypes;
  20494. }
  20495. workInProgress.alternate = current;
  20496. current.alternate = workInProgress;
  20497. } else {
  20498. workInProgress.pendingProps = pendingProps; // Needed because Blocks store data on type.
  20499. workInProgress.type = current.type; // We already have an alternate.
  20500. // Reset the effect tag.
  20501. workInProgress.flags = NoFlags; // The effect list is no longer valid.
  20502. workInProgress.nextEffect = null;
  20503. workInProgress.firstEffect = null;
  20504. workInProgress.lastEffect = null;
  20505. {
  20506. // We intentionally reset, rather than copy, actualDuration & actualStartTime.
  20507. // This prevents time from endlessly accumulating in new commits.
  20508. // This has the downside of resetting values for different priority renders,
  20509. // But works for yielding (the common case) and should support resuming.
  20510. workInProgress.actualDuration = 0;
  20511. workInProgress.actualStartTime = -1;
  20512. }
  20513. }
  20514. workInProgress.childLanes = current.childLanes;
  20515. workInProgress.lanes = current.lanes;
  20516. workInProgress.child = current.child;
  20517. workInProgress.memoizedProps = current.memoizedProps;
  20518. workInProgress.memoizedState = current.memoizedState;
  20519. workInProgress.updateQueue = current.updateQueue; // Clone the dependencies object. This is mutated during the render phase, so
  20520. // it cannot be shared with the current fiber.
  20521. var currentDependencies = current.dependencies;
  20522. workInProgress.dependencies = currentDependencies === null ? null : {
  20523. lanes: currentDependencies.lanes,
  20524. firstContext: currentDependencies.firstContext
  20525. }; // These will be overridden during the parent's reconciliation
  20526. workInProgress.sibling = current.sibling;
  20527. workInProgress.index = current.index;
  20528. workInProgress.ref = current.ref;
  20529. {
  20530. workInProgress.selfBaseDuration = current.selfBaseDuration;
  20531. workInProgress.treeBaseDuration = current.treeBaseDuration;
  20532. }
  20533. {
  20534. workInProgress._debugNeedsRemount = current._debugNeedsRemount;
  20535. switch (workInProgress.tag) {
  20536. case IndeterminateComponent:
  20537. case FunctionComponent:
  20538. case SimpleMemoComponent:
  20539. workInProgress.type = resolveFunctionForHotReloading(current.type);
  20540. break;
  20541. case ClassComponent:
  20542. workInProgress.type = resolveClassForHotReloading(current.type);
  20543. break;
  20544. case ForwardRef:
  20545. workInProgress.type = resolveForwardRefForHotReloading(current.type);
  20546. break;
  20547. }
  20548. }
  20549. return workInProgress;
  20550. } // Used to reuse a Fiber for a second pass.
  20551. function resetWorkInProgress(workInProgress, renderLanes) {
  20552. // This resets the Fiber to what createFiber or createWorkInProgress would
  20553. // have set the values to before during the first pass. Ideally this wouldn't
  20554. // be necessary but unfortunately many code paths reads from the workInProgress
  20555. // when they should be reading from current and writing to workInProgress.
  20556. // We assume pendingProps, index, key, ref, return are still untouched to
  20557. // avoid doing another reconciliation.
  20558. // Reset the effect tag but keep any Placement tags, since that's something
  20559. // that child fiber is setting, not the reconciliation.
  20560. workInProgress.flags &= Placement; // The effect list is no longer valid.
  20561. workInProgress.nextEffect = null;
  20562. workInProgress.firstEffect = null;
  20563. workInProgress.lastEffect = null;
  20564. var current = workInProgress.alternate;
  20565. if (current === null) {
  20566. // Reset to createFiber's initial values.
  20567. workInProgress.childLanes = NoLanes;
  20568. workInProgress.lanes = renderLanes;
  20569. workInProgress.child = null;
  20570. workInProgress.memoizedProps = null;
  20571. workInProgress.memoizedState = null;
  20572. workInProgress.updateQueue = null;
  20573. workInProgress.dependencies = null;
  20574. workInProgress.stateNode = null;
  20575. {
  20576. // Note: We don't reset the actualTime counts. It's useful to accumulate
  20577. // actual time across multiple render passes.
  20578. workInProgress.selfBaseDuration = 0;
  20579. workInProgress.treeBaseDuration = 0;
  20580. }
  20581. } else {
  20582. // Reset to the cloned values that createWorkInProgress would've.
  20583. workInProgress.childLanes = current.childLanes;
  20584. workInProgress.lanes = current.lanes;
  20585. workInProgress.child = current.child;
  20586. workInProgress.memoizedProps = current.memoizedProps;
  20587. workInProgress.memoizedState = current.memoizedState;
  20588. workInProgress.updateQueue = current.updateQueue; // Needed because Blocks store data on type.
  20589. workInProgress.type = current.type; // Clone the dependencies object. This is mutated during the render phase, so
  20590. // it cannot be shared with the current fiber.
  20591. var currentDependencies = current.dependencies;
  20592. workInProgress.dependencies = currentDependencies === null ? null : {
  20593. lanes: currentDependencies.lanes,
  20594. firstContext: currentDependencies.firstContext
  20595. };
  20596. {
  20597. // Note: We don't reset the actualTime counts. It's useful to accumulate
  20598. // actual time across multiple render passes.
  20599. workInProgress.selfBaseDuration = current.selfBaseDuration;
  20600. workInProgress.treeBaseDuration = current.treeBaseDuration;
  20601. }
  20602. }
  20603. return workInProgress;
  20604. }
  20605. function createHostRootFiber(tag) {
  20606. var mode;
  20607. if (tag === ConcurrentRoot) {
  20608. mode = ConcurrentMode | BlockingMode | StrictMode;
  20609. } else if (tag === BlockingRoot) {
  20610. mode = BlockingMode | StrictMode;
  20611. } else {
  20612. mode = NoMode;
  20613. }
  20614. if ( isDevToolsPresent) {
  20615. // Always collect profile timings when DevTools are present.
  20616. // This enables DevTools to start capturing timing at any point–
  20617. // Without some nodes in the tree having empty base times.
  20618. mode |= ProfileMode;
  20619. }
  20620. return createFiber(HostRoot, null, null, mode);
  20621. }
  20622. function createFiberFromTypeAndProps(type, // React$ElementType
  20623. key, pendingProps, owner, mode, lanes) {
  20624. var fiberTag = IndeterminateComponent; // The resolved type is set if we know what the final type will be. I.e. it's not lazy.
  20625. var resolvedType = type;
  20626. if (typeof type === 'function') {
  20627. if (shouldConstruct$1(type)) {
  20628. fiberTag = ClassComponent;
  20629. {
  20630. resolvedType = resolveClassForHotReloading(resolvedType);
  20631. }
  20632. } else {
  20633. {
  20634. resolvedType = resolveFunctionForHotReloading(resolvedType);
  20635. }
  20636. }
  20637. } else if (typeof type === 'string') {
  20638. fiberTag = HostComponent;
  20639. } else {
  20640. getTag: switch (type) {
  20641. case REACT_FRAGMENT_TYPE:
  20642. return createFiberFromFragment(pendingProps.children, mode, lanes, key);
  20643. case REACT_DEBUG_TRACING_MODE_TYPE:
  20644. fiberTag = Mode;
  20645. mode |= DebugTracingMode;
  20646. break;
  20647. case REACT_STRICT_MODE_TYPE:
  20648. fiberTag = Mode;
  20649. mode |= StrictMode;
  20650. break;
  20651. case REACT_PROFILER_TYPE:
  20652. return createFiberFromProfiler(pendingProps, mode, lanes, key);
  20653. case REACT_SUSPENSE_TYPE:
  20654. return createFiberFromSuspense(pendingProps, mode, lanes, key);
  20655. case REACT_SUSPENSE_LIST_TYPE:
  20656. return createFiberFromSuspenseList(pendingProps, mode, lanes, key);
  20657. case REACT_OFFSCREEN_TYPE:
  20658. return createFiberFromOffscreen(pendingProps, mode, lanes, key);
  20659. case REACT_LEGACY_HIDDEN_TYPE:
  20660. return createFiberFromLegacyHidden(pendingProps, mode, lanes, key);
  20661. case REACT_SCOPE_TYPE:
  20662. // eslint-disable-next-line no-fallthrough
  20663. default:
  20664. {
  20665. if (typeof type === 'object' && type !== null) {
  20666. switch (type.$$typeof) {
  20667. case REACT_PROVIDER_TYPE:
  20668. fiberTag = ContextProvider;
  20669. break getTag;
  20670. case REACT_CONTEXT_TYPE:
  20671. // This is a consumer
  20672. fiberTag = ContextConsumer;
  20673. break getTag;
  20674. case REACT_FORWARD_REF_TYPE:
  20675. fiberTag = ForwardRef;
  20676. {
  20677. resolvedType = resolveForwardRefForHotReloading(resolvedType);
  20678. }
  20679. break getTag;
  20680. case REACT_MEMO_TYPE:
  20681. fiberTag = MemoComponent;
  20682. break getTag;
  20683. case REACT_LAZY_TYPE:
  20684. fiberTag = LazyComponent;
  20685. resolvedType = null;
  20686. break getTag;
  20687. case REACT_BLOCK_TYPE:
  20688. fiberTag = Block;
  20689. break getTag;
  20690. }
  20691. }
  20692. var info = '';
  20693. {
  20694. if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
  20695. info += ' You likely forgot to export your component from the file ' + "it's defined in, or you might have mixed up default and " + 'named imports.';
  20696. }
  20697. var ownerName = owner ? getComponentName(owner.type) : null;
  20698. if (ownerName) {
  20699. info += '\n\nCheck the render method of `' + ownerName + '`.';
  20700. }
  20701. }
  20702. {
  20703. {
  20704. throw Error( "Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: " + (type == null ? type : typeof type) + "." + info );
  20705. }
  20706. }
  20707. }
  20708. }
  20709. }
  20710. var fiber = createFiber(fiberTag, pendingProps, key, mode);
  20711. fiber.elementType = type;
  20712. fiber.type = resolvedType;
  20713. fiber.lanes = lanes;
  20714. {
  20715. fiber._debugOwner = owner;
  20716. }
  20717. return fiber;
  20718. }
  20719. function createFiberFromElement(element, mode, lanes) {
  20720. var owner = null;
  20721. {
  20722. owner = element._owner;
  20723. }
  20724. var type = element.type;
  20725. var key = element.key;
  20726. var pendingProps = element.props;
  20727. var fiber = createFiberFromTypeAndProps(type, key, pendingProps, owner, mode, lanes);
  20728. {
  20729. fiber._debugSource = element._source;
  20730. fiber._debugOwner = element._owner;
  20731. }
  20732. return fiber;
  20733. }
  20734. function createFiberFromFragment(elements, mode, lanes, key) {
  20735. var fiber = createFiber(Fragment, elements, key, mode);
  20736. fiber.lanes = lanes;
  20737. return fiber;
  20738. }
  20739. function createFiberFromProfiler(pendingProps, mode, lanes, key) {
  20740. {
  20741. if (typeof pendingProps.id !== 'string') {
  20742. error('Profiler must specify an "id" as a prop');
  20743. }
  20744. }
  20745. var fiber = createFiber(Profiler, pendingProps, key, mode | ProfileMode); // TODO: The Profiler fiber shouldn't have a type. It has a tag.
  20746. fiber.elementType = REACT_PROFILER_TYPE;
  20747. fiber.type = REACT_PROFILER_TYPE;
  20748. fiber.lanes = lanes;
  20749. {
  20750. fiber.stateNode = {
  20751. effectDuration: 0,
  20752. passiveEffectDuration: 0
  20753. };
  20754. }
  20755. return fiber;
  20756. }
  20757. function createFiberFromSuspense(pendingProps, mode, lanes, key) {
  20758. var fiber = createFiber(SuspenseComponent, pendingProps, key, mode); // TODO: The SuspenseComponent fiber shouldn't have a type. It has a tag.
  20759. // This needs to be fixed in getComponentName so that it relies on the tag
  20760. // instead.
  20761. fiber.type = REACT_SUSPENSE_TYPE;
  20762. fiber.elementType = REACT_SUSPENSE_TYPE;
  20763. fiber.lanes = lanes;
  20764. return fiber;
  20765. }
  20766. function createFiberFromSuspenseList(pendingProps, mode, lanes, key) {
  20767. var fiber = createFiber(SuspenseListComponent, pendingProps, key, mode);
  20768. {
  20769. // TODO: The SuspenseListComponent fiber shouldn't have a type. It has a tag.
  20770. // This needs to be fixed in getComponentName so that it relies on the tag
  20771. // instead.
  20772. fiber.type = REACT_SUSPENSE_LIST_TYPE;
  20773. }
  20774. fiber.elementType = REACT_SUSPENSE_LIST_TYPE;
  20775. fiber.lanes = lanes;
  20776. return fiber;
  20777. }
  20778. function createFiberFromOffscreen(pendingProps, mode, lanes, key) {
  20779. var fiber = createFiber(OffscreenComponent, pendingProps, key, mode); // TODO: The OffscreenComponent fiber shouldn't have a type. It has a tag.
  20780. // This needs to be fixed in getComponentName so that it relies on the tag
  20781. // instead.
  20782. {
  20783. fiber.type = REACT_OFFSCREEN_TYPE;
  20784. }
  20785. fiber.elementType = REACT_OFFSCREEN_TYPE;
  20786. fiber.lanes = lanes;
  20787. return fiber;
  20788. }
  20789. function createFiberFromLegacyHidden(pendingProps, mode, lanes, key) {
  20790. var fiber = createFiber(LegacyHiddenComponent, pendingProps, key, mode); // TODO: The LegacyHidden fiber shouldn't have a type. It has a tag.
  20791. // This needs to be fixed in getComponentName so that it relies on the tag
  20792. // instead.
  20793. {
  20794. fiber.type = REACT_LEGACY_HIDDEN_TYPE;
  20795. }
  20796. fiber.elementType = REACT_LEGACY_HIDDEN_TYPE;
  20797. fiber.lanes = lanes;
  20798. return fiber;
  20799. }
  20800. function createFiberFromText(content, mode, lanes) {
  20801. var fiber = createFiber(HostText, content, null, mode);
  20802. fiber.lanes = lanes;
  20803. return fiber;
  20804. }
  20805. function createFiberFromHostInstanceForDeletion() {
  20806. var fiber = createFiber(HostComponent, null, null, NoMode); // TODO: These should not need a type.
  20807. fiber.elementType = 'DELETED';
  20808. fiber.type = 'DELETED';
  20809. return fiber;
  20810. }
  20811. function createFiberFromPortal(portal, mode, lanes) {
  20812. var pendingProps = portal.children !== null ? portal.children : [];
  20813. var fiber = createFiber(HostPortal, pendingProps, portal.key, mode);
  20814. fiber.lanes = lanes;
  20815. fiber.stateNode = {
  20816. containerInfo: portal.containerInfo,
  20817. pendingChildren: null,
  20818. // Used by persistent updates
  20819. implementation: portal.implementation
  20820. };
  20821. return fiber;
  20822. } // Used for stashing WIP properties to replay failed work in DEV.
  20823. function assignFiberPropertiesInDEV(target, source) {
  20824. if (target === null) {
  20825. // This Fiber's initial properties will always be overwritten.
  20826. // We only use a Fiber to ensure the same hidden class so DEV isn't slow.
  20827. target = createFiber(IndeterminateComponent, null, null, NoMode);
  20828. } // This is intentionally written as a list of all properties.
  20829. // We tried to use Object.assign() instead but this is called in
  20830. // the hottest path, and Object.assign() was too slow:
  20831. // https://github.com/facebook/react/issues/12502
  20832. // This code is DEV-only so size is not a concern.
  20833. target.tag = source.tag;
  20834. target.key = source.key;
  20835. target.elementType = source.elementType;
  20836. target.type = source.type;
  20837. target.stateNode = source.stateNode;
  20838. target.return = source.return;
  20839. target.child = source.child;
  20840. target.sibling = source.sibling;
  20841. target.index = source.index;
  20842. target.ref = source.ref;
  20843. target.pendingProps = source.pendingProps;
  20844. target.memoizedProps = source.memoizedProps;
  20845. target.updateQueue = source.updateQueue;
  20846. target.memoizedState = source.memoizedState;
  20847. target.dependencies = source.dependencies;
  20848. target.mode = source.mode;
  20849. target.flags = source.flags;
  20850. target.nextEffect = source.nextEffect;
  20851. target.firstEffect = source.firstEffect;
  20852. target.lastEffect = source.lastEffect;
  20853. target.lanes = source.lanes;
  20854. target.childLanes = source.childLanes;
  20855. target.alternate = source.alternate;
  20856. {
  20857. target.actualDuration = source.actualDuration;
  20858. target.actualStartTime = source.actualStartTime;
  20859. target.selfBaseDuration = source.selfBaseDuration;
  20860. target.treeBaseDuration = source.treeBaseDuration;
  20861. }
  20862. target._debugID = source._debugID;
  20863. target._debugSource = source._debugSource;
  20864. target._debugOwner = source._debugOwner;
  20865. target._debugNeedsRemount = source._debugNeedsRemount;
  20866. target._debugHookTypes = source._debugHookTypes;
  20867. return target;
  20868. }
  20869. function FiberRootNode(containerInfo, tag, hydrate) {
  20870. this.tag = tag;
  20871. this.containerInfo = containerInfo;
  20872. this.pendingChildren = null;
  20873. this.current = null;
  20874. this.pingCache = null;
  20875. this.finishedWork = null;
  20876. this.timeoutHandle = noTimeout;
  20877. this.context = null;
  20878. this.pendingContext = null;
  20879. this.hydrate = hydrate;
  20880. this.callbackNode = null;
  20881. this.callbackPriority = NoLanePriority;
  20882. this.eventTimes = createLaneMap(NoLanes);
  20883. this.expirationTimes = createLaneMap(NoTimestamp);
  20884. this.pendingLanes = NoLanes;
  20885. this.suspendedLanes = NoLanes;
  20886. this.pingedLanes = NoLanes;
  20887. this.expiredLanes = NoLanes;
  20888. this.mutableReadLanes = NoLanes;
  20889. this.finishedLanes = NoLanes;
  20890. this.entangledLanes = NoLanes;
  20891. this.entanglements = createLaneMap(NoLanes);
  20892. {
  20893. this.mutableSourceEagerHydrationData = null;
  20894. }
  20895. {
  20896. this.interactionThreadID = unstable_getThreadID();
  20897. this.memoizedInteractions = new Set();
  20898. this.pendingInteractionMap = new Map();
  20899. }
  20900. {
  20901. switch (tag) {
  20902. case BlockingRoot:
  20903. this._debugRootType = 'createBlockingRoot()';
  20904. break;
  20905. case ConcurrentRoot:
  20906. this._debugRootType = 'createRoot()';
  20907. break;
  20908. case LegacyRoot:
  20909. this._debugRootType = 'createLegacyRoot()';
  20910. break;
  20911. }
  20912. }
  20913. }
  20914. function createFiberRoot(containerInfo, tag, hydrate, hydrationCallbacks) {
  20915. var root = new FiberRootNode(containerInfo, tag, hydrate);
  20916. // stateNode is any.
  20917. var uninitializedFiber = createHostRootFiber(tag);
  20918. root.current = uninitializedFiber;
  20919. uninitializedFiber.stateNode = root;
  20920. initializeUpdateQueue(uninitializedFiber);
  20921. return root;
  20922. }
  20923. // This ensures that the version used for server rendering matches the one
  20924. // that is eventually read during hydration.
  20925. // If they don't match there's a potential tear and a full deopt render is required.
  20926. function registerMutableSourceForHydration(root, mutableSource) {
  20927. var getVersion = mutableSource._getVersion;
  20928. var version = getVersion(mutableSource._source); // TODO Clear this data once all pending hydration work is finished.
  20929. // Retaining it forever may interfere with GC.
  20930. if (root.mutableSourceEagerHydrationData == null) {
  20931. root.mutableSourceEagerHydrationData = [mutableSource, version];
  20932. } else {
  20933. root.mutableSourceEagerHydrationData.push(mutableSource, version);
  20934. }
  20935. }
  20936. function createPortal(children, containerInfo, // TODO: figure out the API for cross-renderer implementation.
  20937. implementation) {
  20938. var key = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  20939. return {
  20940. // This tag allow us to uniquely identify this as a React Portal
  20941. $$typeof: REACT_PORTAL_TYPE,
  20942. key: key == null ? null : '' + key,
  20943. children: children,
  20944. containerInfo: containerInfo,
  20945. implementation: implementation
  20946. };
  20947. }
  20948. var didWarnAboutNestedUpdates;
  20949. var didWarnAboutFindNodeInStrictMode;
  20950. {
  20951. didWarnAboutNestedUpdates = false;
  20952. didWarnAboutFindNodeInStrictMode = {};
  20953. }
  20954. function getContextForSubtree(parentComponent) {
  20955. if (!parentComponent) {
  20956. return emptyContextObject;
  20957. }
  20958. var fiber = get(parentComponent);
  20959. var parentContext = findCurrentUnmaskedContext(fiber);
  20960. if (fiber.tag === ClassComponent) {
  20961. var Component = fiber.type;
  20962. if (isContextProvider(Component)) {
  20963. return processChildContext(fiber, Component, parentContext);
  20964. }
  20965. }
  20966. return parentContext;
  20967. }
  20968. function findHostInstanceWithWarning(component, methodName) {
  20969. {
  20970. var fiber = get(component);
  20971. if (fiber === undefined) {
  20972. if (typeof component.render === 'function') {
  20973. {
  20974. {
  20975. throw Error( "Unable to find node on an unmounted component." );
  20976. }
  20977. }
  20978. } else {
  20979. {
  20980. {
  20981. throw Error( "Argument appears to not be a ReactComponent. Keys: " + Object.keys(component) );
  20982. }
  20983. }
  20984. }
  20985. }
  20986. var hostFiber = findCurrentHostFiber(fiber);
  20987. if (hostFiber === null) {
  20988. return null;
  20989. }
  20990. if (hostFiber.mode & StrictMode) {
  20991. var componentName = getComponentName(fiber.type) || 'Component';
  20992. if (!didWarnAboutFindNodeInStrictMode[componentName]) {
  20993. didWarnAboutFindNodeInStrictMode[componentName] = true;
  20994. var previousFiber = current;
  20995. try {
  20996. setCurrentFiber(hostFiber);
  20997. if (fiber.mode & StrictMode) {
  20998. error('%s is deprecated in StrictMode. ' + '%s was passed an instance of %s which is inside StrictMode. ' + 'Instead, add a ref directly to the element you want to reference. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-find-node', methodName, methodName, componentName);
  20999. } else {
  21000. error('%s is deprecated in StrictMode. ' + '%s was passed an instance of %s which renders StrictMode children. ' + 'Instead, add a ref directly to the element you want to reference. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-find-node', methodName, methodName, componentName);
  21001. }
  21002. } finally {
  21003. // Ideally this should reset to previous but this shouldn't be called in
  21004. // render and there's another warning for that anyway.
  21005. if (previousFiber) {
  21006. setCurrentFiber(previousFiber);
  21007. } else {
  21008. resetCurrentFiber();
  21009. }
  21010. }
  21011. }
  21012. }
  21013. return hostFiber.stateNode;
  21014. }
  21015. }
  21016. function createContainer(containerInfo, tag, hydrate, hydrationCallbacks) {
  21017. return createFiberRoot(containerInfo, tag, hydrate);
  21018. }
  21019. function updateContainer(element, container, parentComponent, callback) {
  21020. {
  21021. onScheduleRoot(container, element);
  21022. }
  21023. var current$1 = container.current;
  21024. var eventTime = requestEventTime();
  21025. {
  21026. // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
  21027. if ('undefined' !== typeof jest) {
  21028. warnIfUnmockedScheduler(current$1);
  21029. warnIfNotScopedWithMatchingAct(current$1);
  21030. }
  21031. }
  21032. var lane = requestUpdateLane(current$1);
  21033. var context = getContextForSubtree(parentComponent);
  21034. if (container.context === null) {
  21035. container.context = context;
  21036. } else {
  21037. container.pendingContext = context;
  21038. }
  21039. {
  21040. if (isRendering && current !== null && !didWarnAboutNestedUpdates) {
  21041. didWarnAboutNestedUpdates = true;
  21042. error('Render methods should be a pure function of props and state; ' + 'triggering nested component updates from render is not allowed. ' + 'If necessary, trigger nested updates in componentDidUpdate.\n\n' + 'Check the render method of %s.', getComponentName(current.type) || 'Unknown');
  21043. }
  21044. }
  21045. var update = createUpdate(eventTime, lane); // Caution: React DevTools currently depends on this property
  21046. // being called "element".
  21047. update.payload = {
  21048. element: element
  21049. };
  21050. callback = callback === undefined ? null : callback;
  21051. if (callback !== null) {
  21052. {
  21053. if (typeof callback !== 'function') {
  21054. error('render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback);
  21055. }
  21056. }
  21057. update.callback = callback;
  21058. }
  21059. enqueueUpdate(current$1, update);
  21060. scheduleUpdateOnFiber(current$1, lane, eventTime);
  21061. return lane;
  21062. }
  21063. function getPublicRootInstance(container) {
  21064. var containerFiber = container.current;
  21065. if (!containerFiber.child) {
  21066. return null;
  21067. }
  21068. switch (containerFiber.child.tag) {
  21069. case HostComponent:
  21070. return getPublicInstance(containerFiber.child.stateNode);
  21071. default:
  21072. return containerFiber.child.stateNode;
  21073. }
  21074. }
  21075. function markRetryLaneImpl(fiber, retryLane) {
  21076. var suspenseState = fiber.memoizedState;
  21077. if (suspenseState !== null && suspenseState.dehydrated !== null) {
  21078. suspenseState.retryLane = higherPriorityLane(suspenseState.retryLane, retryLane);
  21079. }
  21080. } // Increases the priority of thennables when they resolve within this boundary.
  21081. function markRetryLaneIfNotHydrated(fiber, retryLane) {
  21082. markRetryLaneImpl(fiber, retryLane);
  21083. var alternate = fiber.alternate;
  21084. if (alternate) {
  21085. markRetryLaneImpl(alternate, retryLane);
  21086. }
  21087. }
  21088. function attemptUserBlockingHydration$1(fiber) {
  21089. if (fiber.tag !== SuspenseComponent) {
  21090. // We ignore HostRoots here because we can't increase
  21091. // their priority and they should not suspend on I/O,
  21092. // since you have to wrap anything that might suspend in
  21093. // Suspense.
  21094. return;
  21095. }
  21096. var eventTime = requestEventTime();
  21097. var lane = InputDiscreteHydrationLane;
  21098. scheduleUpdateOnFiber(fiber, lane, eventTime);
  21099. markRetryLaneIfNotHydrated(fiber, lane);
  21100. }
  21101. function attemptContinuousHydration$1(fiber) {
  21102. if (fiber.tag !== SuspenseComponent) {
  21103. // We ignore HostRoots here because we can't increase
  21104. // their priority and they should not suspend on I/O,
  21105. // since you have to wrap anything that might suspend in
  21106. // Suspense.
  21107. return;
  21108. }
  21109. var eventTime = requestEventTime();
  21110. var lane = SelectiveHydrationLane;
  21111. scheduleUpdateOnFiber(fiber, lane, eventTime);
  21112. markRetryLaneIfNotHydrated(fiber, lane);
  21113. }
  21114. function attemptHydrationAtCurrentPriority$1(fiber) {
  21115. if (fiber.tag !== SuspenseComponent) {
  21116. // We ignore HostRoots here because we can't increase
  21117. // their priority other than synchronously flush it.
  21118. return;
  21119. }
  21120. var eventTime = requestEventTime();
  21121. var lane = requestUpdateLane(fiber);
  21122. scheduleUpdateOnFiber(fiber, lane, eventTime);
  21123. markRetryLaneIfNotHydrated(fiber, lane);
  21124. }
  21125. function runWithPriority$2(priority, fn) {
  21126. try {
  21127. setCurrentUpdateLanePriority(priority);
  21128. return fn();
  21129. } finally {
  21130. }
  21131. }
  21132. function findHostInstanceWithNoPortals(fiber) {
  21133. var hostFiber = findCurrentHostFiberWithNoPortals(fiber);
  21134. if (hostFiber === null) {
  21135. return null;
  21136. }
  21137. if (hostFiber.tag === FundamentalComponent) {
  21138. return hostFiber.stateNode.instance;
  21139. }
  21140. return hostFiber.stateNode;
  21141. }
  21142. var shouldSuspendImpl = function (fiber) {
  21143. return false;
  21144. };
  21145. function shouldSuspend(fiber) {
  21146. return shouldSuspendImpl(fiber);
  21147. }
  21148. var overrideHookState = null;
  21149. var overrideHookStateDeletePath = null;
  21150. var overrideHookStateRenamePath = null;
  21151. var overrideProps = null;
  21152. var overridePropsDeletePath = null;
  21153. var overridePropsRenamePath = null;
  21154. var scheduleUpdate = null;
  21155. var setSuspenseHandler = null;
  21156. {
  21157. var copyWithDeleteImpl = function (obj, path, index) {
  21158. var key = path[index];
  21159. var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj);
  21160. if (index + 1 === path.length) {
  21161. if (Array.isArray(updated)) {
  21162. updated.splice(key, 1);
  21163. } else {
  21164. delete updated[key];
  21165. }
  21166. return updated;
  21167. } // $FlowFixMe number or string is fine here
  21168. updated[key] = copyWithDeleteImpl(obj[key], path, index + 1);
  21169. return updated;
  21170. };
  21171. var copyWithDelete = function (obj, path) {
  21172. return copyWithDeleteImpl(obj, path, 0);
  21173. };
  21174. var copyWithRenameImpl = function (obj, oldPath, newPath, index) {
  21175. var oldKey = oldPath[index];
  21176. var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj);
  21177. if (index + 1 === oldPath.length) {
  21178. var newKey = newPath[index]; // $FlowFixMe number or string is fine here
  21179. updated[newKey] = updated[oldKey];
  21180. if (Array.isArray(updated)) {
  21181. updated.splice(oldKey, 1);
  21182. } else {
  21183. delete updated[oldKey];
  21184. }
  21185. } else {
  21186. // $FlowFixMe number or string is fine here
  21187. updated[oldKey] = copyWithRenameImpl( // $FlowFixMe number or string is fine here
  21188. obj[oldKey], oldPath, newPath, index + 1);
  21189. }
  21190. return updated;
  21191. };
  21192. var copyWithRename = function (obj, oldPath, newPath) {
  21193. if (oldPath.length !== newPath.length) {
  21194. warn('copyWithRename() expects paths of the same length');
  21195. return;
  21196. } else {
  21197. for (var i = 0; i < newPath.length - 1; i++) {
  21198. if (oldPath[i] !== newPath[i]) {
  21199. warn('copyWithRename() expects paths to be the same except for the deepest key');
  21200. return;
  21201. }
  21202. }
  21203. }
  21204. return copyWithRenameImpl(obj, oldPath, newPath, 0);
  21205. };
  21206. var copyWithSetImpl = function (obj, path, index, value) {
  21207. if (index >= path.length) {
  21208. return value;
  21209. }
  21210. var key = path[index];
  21211. var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj); // $FlowFixMe number or string is fine here
  21212. updated[key] = copyWithSetImpl(obj[key], path, index + 1, value);
  21213. return updated;
  21214. };
  21215. var copyWithSet = function (obj, path, value) {
  21216. return copyWithSetImpl(obj, path, 0, value);
  21217. };
  21218. var findHook = function (fiber, id) {
  21219. // For now, the "id" of stateful hooks is just the stateful hook index.
  21220. // This may change in the future with e.g. nested hooks.
  21221. var currentHook = fiber.memoizedState;
  21222. while (currentHook !== null && id > 0) {
  21223. currentHook = currentHook.next;
  21224. id--;
  21225. }
  21226. return currentHook;
  21227. }; // Support DevTools editable values for useState and useReducer.
  21228. overrideHookState = function (fiber, id, path, value) {
  21229. var hook = findHook(fiber, id);
  21230. if (hook !== null) {
  21231. var newState = copyWithSet(hook.memoizedState, path, value);
  21232. hook.memoizedState = newState;
  21233. hook.baseState = newState; // We aren't actually adding an update to the queue,
  21234. // because there is no update we can add for useReducer hooks that won't trigger an error.
  21235. // (There's no appropriate action type for DevTools overrides.)
  21236. // As a result though, React will see the scheduled update as a noop and bailout.
  21237. // Shallow cloning props works as a workaround for now to bypass the bailout check.
  21238. fiber.memoizedProps = _assign({}, fiber.memoizedProps);
  21239. scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
  21240. }
  21241. };
  21242. overrideHookStateDeletePath = function (fiber, id, path) {
  21243. var hook = findHook(fiber, id);
  21244. if (hook !== null) {
  21245. var newState = copyWithDelete(hook.memoizedState, path);
  21246. hook.memoizedState = newState;
  21247. hook.baseState = newState; // We aren't actually adding an update to the queue,
  21248. // because there is no update we can add for useReducer hooks that won't trigger an error.
  21249. // (There's no appropriate action type for DevTools overrides.)
  21250. // As a result though, React will see the scheduled update as a noop and bailout.
  21251. // Shallow cloning props works as a workaround for now to bypass the bailout check.
  21252. fiber.memoizedProps = _assign({}, fiber.memoizedProps);
  21253. scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
  21254. }
  21255. };
  21256. overrideHookStateRenamePath = function (fiber, id, oldPath, newPath) {
  21257. var hook = findHook(fiber, id);
  21258. if (hook !== null) {
  21259. var newState = copyWithRename(hook.memoizedState, oldPath, newPath);
  21260. hook.memoizedState = newState;
  21261. hook.baseState = newState; // We aren't actually adding an update to the queue,
  21262. // because there is no update we can add for useReducer hooks that won't trigger an error.
  21263. // (There's no appropriate action type for DevTools overrides.)
  21264. // As a result though, React will see the scheduled update as a noop and bailout.
  21265. // Shallow cloning props works as a workaround for now to bypass the bailout check.
  21266. fiber.memoizedProps = _assign({}, fiber.memoizedProps);
  21267. scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
  21268. }
  21269. }; // Support DevTools props for function components, forwardRef, memo, host components, etc.
  21270. overrideProps = function (fiber, path, value) {
  21271. fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
  21272. if (fiber.alternate) {
  21273. fiber.alternate.pendingProps = fiber.pendingProps;
  21274. }
  21275. scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
  21276. };
  21277. overridePropsDeletePath = function (fiber, path) {
  21278. fiber.pendingProps = copyWithDelete(fiber.memoizedProps, path);
  21279. if (fiber.alternate) {
  21280. fiber.alternate.pendingProps = fiber.pendingProps;
  21281. }
  21282. scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
  21283. };
  21284. overridePropsRenamePath = function (fiber, oldPath, newPath) {
  21285. fiber.pendingProps = copyWithRename(fiber.memoizedProps, oldPath, newPath);
  21286. if (fiber.alternate) {
  21287. fiber.alternate.pendingProps = fiber.pendingProps;
  21288. }
  21289. scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
  21290. };
  21291. scheduleUpdate = function (fiber) {
  21292. scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
  21293. };
  21294. setSuspenseHandler = function (newShouldSuspendImpl) {
  21295. shouldSuspendImpl = newShouldSuspendImpl;
  21296. };
  21297. }
  21298. function findHostInstanceByFiber(fiber) {
  21299. var hostFiber = findCurrentHostFiber(fiber);
  21300. if (hostFiber === null) {
  21301. return null;
  21302. }
  21303. return hostFiber.stateNode;
  21304. }
  21305. function emptyFindFiberByHostInstance(instance) {
  21306. return null;
  21307. }
  21308. function getCurrentFiberForDevTools() {
  21309. return current;
  21310. }
  21311. function injectIntoDevTools(devToolsConfig) {
  21312. var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
  21313. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
  21314. return injectInternals({
  21315. bundleType: devToolsConfig.bundleType,
  21316. version: devToolsConfig.version,
  21317. rendererPackageName: devToolsConfig.rendererPackageName,
  21318. rendererConfig: devToolsConfig.rendererConfig,
  21319. overrideHookState: overrideHookState,
  21320. overrideHookStateDeletePath: overrideHookStateDeletePath,
  21321. overrideHookStateRenamePath: overrideHookStateRenamePath,
  21322. overrideProps: overrideProps,
  21323. overridePropsDeletePath: overridePropsDeletePath,
  21324. overridePropsRenamePath: overridePropsRenamePath,
  21325. setSuspenseHandler: setSuspenseHandler,
  21326. scheduleUpdate: scheduleUpdate,
  21327. currentDispatcherRef: ReactCurrentDispatcher,
  21328. findHostInstanceByFiber: findHostInstanceByFiber,
  21329. findFiberByHostInstance: findFiberByHostInstance || emptyFindFiberByHostInstance,
  21330. // React Refresh
  21331. findHostInstancesForRefresh: findHostInstancesForRefresh ,
  21332. scheduleRefresh: scheduleRefresh ,
  21333. scheduleRoot: scheduleRoot ,
  21334. setRefreshHandler: setRefreshHandler ,
  21335. // Enables DevTools to append owner stacks to error messages in DEV mode.
  21336. getCurrentFiber: getCurrentFiberForDevTools
  21337. });
  21338. }
  21339. function ReactDOMRoot(container, options) {
  21340. this._internalRoot = createRootImpl(container, ConcurrentRoot, options);
  21341. }
  21342. function ReactDOMBlockingRoot(container, tag, options) {
  21343. this._internalRoot = createRootImpl(container, tag, options);
  21344. }
  21345. ReactDOMRoot.prototype.render = ReactDOMBlockingRoot.prototype.render = function (children) {
  21346. var root = this._internalRoot;
  21347. {
  21348. if (typeof arguments[1] === 'function') {
  21349. error('render(...): does not support the second callback argument. ' + 'To execute a side effect after rendering, declare it in a component body with useEffect().');
  21350. }
  21351. var container = root.containerInfo;
  21352. if (container.nodeType !== COMMENT_NODE) {
  21353. var hostInstance = findHostInstanceWithNoPortals(root.current);
  21354. if (hostInstance) {
  21355. if (hostInstance.parentNode !== container) {
  21356. error('render(...): It looks like the React-rendered content of the ' + 'root container was removed without using React. This is not ' + 'supported and will cause errors. Instead, call ' + "root.unmount() to empty a root's container.");
  21357. }
  21358. }
  21359. }
  21360. }
  21361. updateContainer(children, root, null, null);
  21362. };
  21363. ReactDOMRoot.prototype.unmount = ReactDOMBlockingRoot.prototype.unmount = function () {
  21364. {
  21365. if (typeof arguments[0] === 'function') {
  21366. error('unmount(...): does not support a callback argument. ' + 'To execute a side effect after rendering, declare it in a component body with useEffect().');
  21367. }
  21368. }
  21369. var root = this._internalRoot;
  21370. var container = root.containerInfo;
  21371. updateContainer(null, root, null, function () {
  21372. unmarkContainerAsRoot(container);
  21373. });
  21374. };
  21375. function createRootImpl(container, tag, options) {
  21376. // Tag is either LegacyRoot or Concurrent Root
  21377. var hydrate = options != null && options.hydrate === true;
  21378. var hydrationCallbacks = options != null && options.hydrationOptions || null;
  21379. var mutableSources = options != null && options.hydrationOptions != null && options.hydrationOptions.mutableSources || null;
  21380. var root = createContainer(container, tag, hydrate);
  21381. markContainerAsRoot(root.current, container);
  21382. var containerNodeType = container.nodeType;
  21383. {
  21384. var rootContainerElement = container.nodeType === COMMENT_NODE ? container.parentNode : container;
  21385. listenToAllSupportedEvents(rootContainerElement);
  21386. }
  21387. if (mutableSources) {
  21388. for (var i = 0; i < mutableSources.length; i++) {
  21389. var mutableSource = mutableSources[i];
  21390. registerMutableSourceForHydration(root, mutableSource);
  21391. }
  21392. }
  21393. return root;
  21394. }
  21395. function createLegacyRoot(container, options) {
  21396. return new ReactDOMBlockingRoot(container, LegacyRoot, options);
  21397. }
  21398. function isValidContainer(node) {
  21399. return !!(node && (node.nodeType === ELEMENT_NODE || node.nodeType === DOCUMENT_NODE || node.nodeType === DOCUMENT_FRAGMENT_NODE || node.nodeType === COMMENT_NODE && node.nodeValue === ' react-mount-point-unstable '));
  21400. }
  21401. var ReactCurrentOwner$3 = ReactSharedInternals.ReactCurrentOwner;
  21402. var topLevelUpdateWarnings;
  21403. var warnedAboutHydrateAPI = false;
  21404. {
  21405. topLevelUpdateWarnings = function (container) {
  21406. if (container._reactRootContainer && container.nodeType !== COMMENT_NODE) {
  21407. var hostInstance = findHostInstanceWithNoPortals(container._reactRootContainer._internalRoot.current);
  21408. if (hostInstance) {
  21409. if (hostInstance.parentNode !== container) {
  21410. error('render(...): It looks like the React-rendered content of this ' + 'container was removed without using React. This is not ' + 'supported and will cause errors. Instead, call ' + 'ReactDOM.unmountComponentAtNode to empty a container.');
  21411. }
  21412. }
  21413. }
  21414. var isRootRenderedBySomeReact = !!container._reactRootContainer;
  21415. var rootEl = getReactRootElementInContainer(container);
  21416. var hasNonRootReactChild = !!(rootEl && getInstanceFromNode(rootEl));
  21417. if (hasNonRootReactChild && !isRootRenderedBySomeReact) {
  21418. error('render(...): Replacing React-rendered children with a new root ' + 'component. If you intended to update the children of this node, ' + 'you should instead have the existing children update their state ' + 'and render the new components instead of calling ReactDOM.render.');
  21419. }
  21420. if (container.nodeType === ELEMENT_NODE && container.tagName && container.tagName.toUpperCase() === 'BODY') {
  21421. error('render(): Rendering components directly into document.body is ' + 'discouraged, since its children are often manipulated by third-party ' + 'scripts and browser extensions. This may lead to subtle ' + 'reconciliation issues. Try rendering into a container element created ' + 'for your app.');
  21422. }
  21423. };
  21424. }
  21425. function getReactRootElementInContainer(container) {
  21426. if (!container) {
  21427. return null;
  21428. }
  21429. if (container.nodeType === DOCUMENT_NODE) {
  21430. return container.documentElement;
  21431. } else {
  21432. return container.firstChild;
  21433. }
  21434. }
  21435. function shouldHydrateDueToLegacyHeuristic(container) {
  21436. var rootElement = getReactRootElementInContainer(container);
  21437. return !!(rootElement && rootElement.nodeType === ELEMENT_NODE && rootElement.hasAttribute(ROOT_ATTRIBUTE_NAME));
  21438. }
  21439. function legacyCreateRootFromDOMContainer(container, forceHydrate) {
  21440. var shouldHydrate = forceHydrate || shouldHydrateDueToLegacyHeuristic(container); // First clear any existing content.
  21441. if (!shouldHydrate) {
  21442. var warned = false;
  21443. var rootSibling;
  21444. while (rootSibling = container.lastChild) {
  21445. {
  21446. if (!warned && rootSibling.nodeType === ELEMENT_NODE && rootSibling.hasAttribute(ROOT_ATTRIBUTE_NAME)) {
  21447. warned = true;
  21448. error('render(): Target node has markup rendered by React, but there ' + 'are unrelated nodes as well. This is most commonly caused by ' + 'white-space inserted around server-rendered markup.');
  21449. }
  21450. }
  21451. container.removeChild(rootSibling);
  21452. }
  21453. }
  21454. {
  21455. if (shouldHydrate && !forceHydrate && !warnedAboutHydrateAPI) {
  21456. warnedAboutHydrateAPI = true;
  21457. warn('render(): Calling ReactDOM.render() to hydrate server-rendered markup ' + 'will stop working in React v18. Replace the ReactDOM.render() call ' + 'with ReactDOM.hydrate() if you want React to attach to the server HTML.');
  21458. }
  21459. }
  21460. return createLegacyRoot(container, shouldHydrate ? {
  21461. hydrate: true
  21462. } : undefined);
  21463. }
  21464. function warnOnInvalidCallback$1(callback, callerName) {
  21465. {
  21466. if (callback !== null && typeof callback !== 'function') {
  21467. error('%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
  21468. }
  21469. }
  21470. }
  21471. function legacyRenderSubtreeIntoContainer(parentComponent, children, container, forceHydrate, callback) {
  21472. {
  21473. topLevelUpdateWarnings(container);
  21474. warnOnInvalidCallback$1(callback === undefined ? null : callback, 'render');
  21475. } // TODO: Without `any` type, Flow says "Property cannot be accessed on any
  21476. // member of intersection type." Whyyyyyy.
  21477. var root = container._reactRootContainer;
  21478. var fiberRoot;
  21479. if (!root) {
  21480. // Initial mount
  21481. root = container._reactRootContainer = legacyCreateRootFromDOMContainer(container, forceHydrate);
  21482. fiberRoot = root._internalRoot;
  21483. if (typeof callback === 'function') {
  21484. var originalCallback = callback;
  21485. callback = function () {
  21486. var instance = getPublicRootInstance(fiberRoot);
  21487. originalCallback.call(instance);
  21488. };
  21489. } // Initial mount should not be batched.
  21490. unbatchedUpdates(function () {
  21491. updateContainer(children, fiberRoot, parentComponent, callback);
  21492. });
  21493. } else {
  21494. fiberRoot = root._internalRoot;
  21495. if (typeof callback === 'function') {
  21496. var _originalCallback = callback;
  21497. callback = function () {
  21498. var instance = getPublicRootInstance(fiberRoot);
  21499. _originalCallback.call(instance);
  21500. };
  21501. } // Update
  21502. updateContainer(children, fiberRoot, parentComponent, callback);
  21503. }
  21504. return getPublicRootInstance(fiberRoot);
  21505. }
  21506. function findDOMNode(componentOrElement) {
  21507. {
  21508. var owner = ReactCurrentOwner$3.current;
  21509. if (owner !== null && owner.stateNode !== null) {
  21510. var warnedAboutRefsInRender = owner.stateNode._warnedAboutRefsInRender;
  21511. if (!warnedAboutRefsInRender) {
  21512. error('%s is accessing findDOMNode inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', getComponentName(owner.type) || 'A component');
  21513. }
  21514. owner.stateNode._warnedAboutRefsInRender = true;
  21515. }
  21516. }
  21517. if (componentOrElement == null) {
  21518. return null;
  21519. }
  21520. if (componentOrElement.nodeType === ELEMENT_NODE) {
  21521. return componentOrElement;
  21522. }
  21523. {
  21524. return findHostInstanceWithWarning(componentOrElement, 'findDOMNode');
  21525. }
  21526. }
  21527. function hydrate(element, container, callback) {
  21528. if (!isValidContainer(container)) {
  21529. {
  21530. throw Error( "Target container is not a DOM element." );
  21531. }
  21532. }
  21533. {
  21534. var isModernRoot = isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined;
  21535. if (isModernRoot) {
  21536. error('You are calling ReactDOM.hydrate() on a container that was previously ' + 'passed to ReactDOM.createRoot(). This is not supported. ' + 'Did you mean to call createRoot(container, {hydrate: true}).render(element)?');
  21537. }
  21538. } // TODO: throw or warn if we couldn't hydrate?
  21539. return legacyRenderSubtreeIntoContainer(null, element, container, true, callback);
  21540. }
  21541. function render(element, container, callback) {
  21542. if (!isValidContainer(container)) {
  21543. {
  21544. throw Error( "Target container is not a DOM element." );
  21545. }
  21546. }
  21547. {
  21548. var isModernRoot = isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined;
  21549. if (isModernRoot) {
  21550. error('You are calling ReactDOM.render() on a container that was previously ' + 'passed to ReactDOM.createRoot(). This is not supported. ' + 'Did you mean to call root.render(element)?');
  21551. }
  21552. }
  21553. return legacyRenderSubtreeIntoContainer(null, element, container, false, callback);
  21554. }
  21555. function unstable_renderSubtreeIntoContainer(parentComponent, element, containerNode, callback) {
  21556. if (!isValidContainer(containerNode)) {
  21557. {
  21558. throw Error( "Target container is not a DOM element." );
  21559. }
  21560. }
  21561. if (!(parentComponent != null && has(parentComponent))) {
  21562. {
  21563. throw Error( "parentComponent must be a valid React Component" );
  21564. }
  21565. }
  21566. return legacyRenderSubtreeIntoContainer(parentComponent, element, containerNode, false, callback);
  21567. }
  21568. function unmountComponentAtNode(container) {
  21569. if (!isValidContainer(container)) {
  21570. {
  21571. throw Error( "unmountComponentAtNode(...): Target container is not a DOM element." );
  21572. }
  21573. }
  21574. {
  21575. var isModernRoot = isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined;
  21576. if (isModernRoot) {
  21577. error('You are calling ReactDOM.unmountComponentAtNode() on a container that was previously ' + 'passed to ReactDOM.createRoot(). This is not supported. Did you mean to call root.unmount()?');
  21578. }
  21579. }
  21580. if (container._reactRootContainer) {
  21581. {
  21582. var rootEl = getReactRootElementInContainer(container);
  21583. var renderedByDifferentReact = rootEl && !getInstanceFromNode(rootEl);
  21584. if (renderedByDifferentReact) {
  21585. error("unmountComponentAtNode(): The node you're attempting to unmount " + 'was rendered by another copy of React.');
  21586. }
  21587. } // Unmount should not be batched.
  21588. unbatchedUpdates(function () {
  21589. legacyRenderSubtreeIntoContainer(null, null, container, false, function () {
  21590. // $FlowFixMe This should probably use `delete container._reactRootContainer`
  21591. container._reactRootContainer = null;
  21592. unmarkContainerAsRoot(container);
  21593. });
  21594. }); // If you call unmountComponentAtNode twice in quick succession, you'll
  21595. // get `true` twice. That's probably fine?
  21596. return true;
  21597. } else {
  21598. {
  21599. var _rootEl = getReactRootElementInContainer(container);
  21600. var hasNonRootReactChild = !!(_rootEl && getInstanceFromNode(_rootEl)); // Check if the container itself is a React root node.
  21601. var isContainerReactRoot = container.nodeType === ELEMENT_NODE && isValidContainer(container.parentNode) && !!container.parentNode._reactRootContainer;
  21602. if (hasNonRootReactChild) {
  21603. error("unmountComponentAtNode(): The node you're attempting to unmount " + 'was rendered by React and is not a top-level container. %s', isContainerReactRoot ? 'You may have accidentally passed in a React root node instead ' + 'of its container.' : 'Instead, have the parent component update its state and ' + 'rerender in order to remove this component.');
  21604. }
  21605. }
  21606. return false;
  21607. }
  21608. }
  21609. setAttemptUserBlockingHydration(attemptUserBlockingHydration$1);
  21610. setAttemptContinuousHydration(attemptContinuousHydration$1);
  21611. setAttemptHydrationAtCurrentPriority(attemptHydrationAtCurrentPriority$1);
  21612. setAttemptHydrationAtPriority(runWithPriority$2);
  21613. var didWarnAboutUnstableCreatePortal = false;
  21614. {
  21615. if (typeof Map !== 'function' || // $FlowIssue Flow incorrectly thinks Map has no prototype
  21616. Map.prototype == null || typeof Map.prototype.forEach !== 'function' || typeof Set !== 'function' || // $FlowIssue Flow incorrectly thinks Set has no prototype
  21617. Set.prototype == null || typeof Set.prototype.clear !== 'function' || typeof Set.prototype.forEach !== 'function') {
  21618. error('React depends on Map and Set built-in types. Make sure that you load a ' + 'polyfill in older browsers. https://reactjs.org/link/react-polyfills');
  21619. }
  21620. }
  21621. setRestoreImplementation(restoreControlledState$3);
  21622. setBatchingImplementation(batchedUpdates$1, discreteUpdates$1, flushDiscreteUpdates, batchedEventUpdates$1);
  21623. function createPortal$1(children, container) {
  21624. var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  21625. if (!isValidContainer(container)) {
  21626. {
  21627. throw Error( "Target container is not a DOM element." );
  21628. }
  21629. } // TODO: pass ReactDOM portal implementation as third argument
  21630. // $FlowFixMe The Flow type is opaque but there's no way to actually create it.
  21631. return createPortal(children, container, null, key);
  21632. }
  21633. function renderSubtreeIntoContainer(parentComponent, element, containerNode, callback) {
  21634. return unstable_renderSubtreeIntoContainer(parentComponent, element, containerNode, callback);
  21635. }
  21636. function unstable_createPortal(children, container) {
  21637. var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  21638. {
  21639. if (!didWarnAboutUnstableCreatePortal) {
  21640. didWarnAboutUnstableCreatePortal = true;
  21641. warn('The ReactDOM.unstable_createPortal() alias has been deprecated, ' + 'and will be removed in React 18+. Update your code to use ' + 'ReactDOM.createPortal() instead. It has the exact same API, ' + 'but without the "unstable_" prefix.');
  21642. }
  21643. }
  21644. return createPortal$1(children, container, key);
  21645. }
  21646. var Internals = {
  21647. // Keep in sync with ReactTestUtils.js, and ReactTestUtilsAct.js.
  21648. // This is an array for better minification.
  21649. Events: [getInstanceFromNode, getNodeFromInstance, getFiberCurrentPropsFromNode, enqueueStateRestore, restoreStateIfNeeded, flushPassiveEffects, // TODO: This is related to `act`, not events. Move to separate key?
  21650. IsThisRendererActing]
  21651. };
  21652. var foundDevTools = injectIntoDevTools({
  21653. findFiberByHostInstance: getClosestInstanceFromNode,
  21654. bundleType: 1 ,
  21655. version: ReactVersion,
  21656. rendererPackageName: 'react-dom'
  21657. });
  21658. {
  21659. if (!foundDevTools && canUseDOM && window.top === window.self) {
  21660. // If we're in Chrome or Firefox, provide a download link if not installed.
  21661. if (navigator.userAgent.indexOf('Chrome') > -1 && navigator.userAgent.indexOf('Edge') === -1 || navigator.userAgent.indexOf('Firefox') > -1) {
  21662. var protocol = window.location.protocol; // Don't warn in exotic cases like chrome-extension://.
  21663. if (/^(https?|file):$/.test(protocol)) {
  21664. // eslint-disable-next-line react-internal/no-production-logging
  21665. console.info('%cDownload the React DevTools ' + 'for a better development experience: ' + 'https://reactjs.org/link/react-devtools' + (protocol === 'file:' ? '\nYou might need to use a local HTTP server (instead of file://): ' + 'https://reactjs.org/link/react-devtools-faq' : ''), 'font-weight:bold');
  21666. }
  21667. }
  21668. }
  21669. }
  21670. exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = Internals;
  21671. exports.createPortal = createPortal$1;
  21672. exports.findDOMNode = findDOMNode;
  21673. exports.flushSync = flushSync;
  21674. exports.hydrate = hydrate;
  21675. exports.render = render;
  21676. exports.unmountComponentAtNode = unmountComponentAtNode;
  21677. exports.unstable_batchedUpdates = batchedUpdates$1;
  21678. exports.unstable_createPortal = unstable_createPortal;
  21679. exports.unstable_renderSubtreeIntoContainer = renderSubtreeIntoContainer;
  21680. exports.version = ReactVersion;
  21681. })));