react-dom.js 918 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293
  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. })));