react-dom-server.node.development.js 238 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059
  1. /**
  2. * @license React
  3. * react-dom-server.node.development.js
  4. *
  5. * Copyright (c) Facebook, Inc. and its affiliates.
  6. *
  7. * This source code is licensed under the MIT license found in the
  8. * LICENSE file in the root directory of this source tree.
  9. */
  10. 'use strict';
  11. if (process.env.NODE_ENV !== "production") {
  12. (function() {
  13. 'use strict';
  14. var React = require('react');
  15. var util = require('util');
  16. var ReactVersion = '18.2.0';
  17. var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
  18. // by calls to these methods by a Babel plugin.
  19. //
  20. // In PROD (or in packages without access to React internals),
  21. // they are left as they are instead.
  22. function warn(format) {
  23. {
  24. {
  25. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  26. args[_key - 1] = arguments[_key];
  27. }
  28. printWarning('warn', format, args);
  29. }
  30. }
  31. }
  32. function error(format) {
  33. {
  34. {
  35. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  36. args[_key2 - 1] = arguments[_key2];
  37. }
  38. printWarning('error', format, args);
  39. }
  40. }
  41. }
  42. function printWarning(level, format, args) {
  43. // When changing this logic, you might want to also
  44. // update consoleWithStackDev.www.js as well.
  45. {
  46. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  47. var stack = ReactDebugCurrentFrame.getStackAddendum();
  48. if (stack !== '') {
  49. format += '%s';
  50. args = args.concat([stack]);
  51. } // eslint-disable-next-line react-internal/safe-string-coercion
  52. var argsWithFormat = args.map(function (item) {
  53. return String(item);
  54. }); // Careful: RN currently depends on this prefix
  55. argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
  56. // breaks IE9: https://github.com/facebook/react/issues/13610
  57. // eslint-disable-next-line react-internal/no-production-logging
  58. Function.prototype.apply.call(console[level], console, argsWithFormat);
  59. }
  60. }
  61. function scheduleWork(callback) {
  62. setImmediate(callback);
  63. }
  64. function flushBuffered(destination) {
  65. // If we don't have any more data to send right now.
  66. // Flush whatever is in the buffer to the wire.
  67. if (typeof destination.flush === 'function') {
  68. // By convention the Zlib streams provide a flush function for this purpose.
  69. // For Express, compression middleware adds this method.
  70. destination.flush();
  71. }
  72. }
  73. var VIEW_SIZE = 2048;
  74. var currentView = null;
  75. var writtenBytes = 0;
  76. var destinationHasCapacity = true;
  77. function beginWriting(destination) {
  78. currentView = new Uint8Array(VIEW_SIZE);
  79. writtenBytes = 0;
  80. destinationHasCapacity = true;
  81. }
  82. function writeStringChunk(destination, stringChunk) {
  83. if (stringChunk.length === 0) {
  84. return;
  85. } // maximum possible view needed to encode entire string
  86. if (stringChunk.length * 3 > VIEW_SIZE) {
  87. if (writtenBytes > 0) {
  88. writeToDestination(destination, currentView.subarray(0, writtenBytes));
  89. currentView = new Uint8Array(VIEW_SIZE);
  90. writtenBytes = 0;
  91. }
  92. writeToDestination(destination, textEncoder.encode(stringChunk));
  93. return;
  94. }
  95. var target = currentView;
  96. if (writtenBytes > 0) {
  97. target = currentView.subarray(writtenBytes);
  98. }
  99. var _textEncoder$encodeIn = textEncoder.encodeInto(stringChunk, target),
  100. read = _textEncoder$encodeIn.read,
  101. written = _textEncoder$encodeIn.written;
  102. writtenBytes += written;
  103. if (read < stringChunk.length) {
  104. writeToDestination(destination, currentView);
  105. currentView = new Uint8Array(VIEW_SIZE);
  106. writtenBytes = textEncoder.encodeInto(stringChunk.slice(read), currentView).written;
  107. }
  108. if (writtenBytes === VIEW_SIZE) {
  109. writeToDestination(destination, currentView);
  110. currentView = new Uint8Array(VIEW_SIZE);
  111. writtenBytes = 0;
  112. }
  113. }
  114. function writeViewChunk(destination, chunk) {
  115. if (chunk.byteLength === 0) {
  116. return;
  117. }
  118. if (chunk.byteLength > VIEW_SIZE) {
  119. // this chunk may overflow a single view which implies it was not
  120. // one that is cached by the streaming renderer. We will enqueu
  121. // it directly and expect it is not re-used
  122. if (writtenBytes > 0) {
  123. writeToDestination(destination, currentView.subarray(0, writtenBytes));
  124. currentView = new Uint8Array(VIEW_SIZE);
  125. writtenBytes = 0;
  126. }
  127. writeToDestination(destination, chunk);
  128. return;
  129. }
  130. var bytesToWrite = chunk;
  131. var allowableBytes = currentView.length - writtenBytes;
  132. if (allowableBytes < bytesToWrite.byteLength) {
  133. // this chunk would overflow the current view. We enqueue a full view
  134. // and start a new view with the remaining chunk
  135. if (allowableBytes === 0) {
  136. // the current view is already full, send it
  137. writeToDestination(destination, currentView);
  138. } else {
  139. // fill up the current view and apply the remaining chunk bytes
  140. // to a new view.
  141. currentView.set(bytesToWrite.subarray(0, allowableBytes), writtenBytes);
  142. writtenBytes += allowableBytes;
  143. writeToDestination(destination, currentView);
  144. bytesToWrite = bytesToWrite.subarray(allowableBytes);
  145. }
  146. currentView = new Uint8Array(VIEW_SIZE);
  147. writtenBytes = 0;
  148. }
  149. currentView.set(bytesToWrite, writtenBytes);
  150. writtenBytes += bytesToWrite.byteLength;
  151. if (writtenBytes === VIEW_SIZE) {
  152. writeToDestination(destination, currentView);
  153. currentView = new Uint8Array(VIEW_SIZE);
  154. writtenBytes = 0;
  155. }
  156. }
  157. function writeChunk(destination, chunk) {
  158. if (typeof chunk === 'string') {
  159. writeStringChunk(destination, chunk);
  160. } else {
  161. writeViewChunk(destination, chunk);
  162. }
  163. }
  164. function writeToDestination(destination, view) {
  165. var currentHasCapacity = destination.write(view);
  166. destinationHasCapacity = destinationHasCapacity && currentHasCapacity;
  167. }
  168. function writeChunkAndReturn(destination, chunk) {
  169. writeChunk(destination, chunk);
  170. return destinationHasCapacity;
  171. }
  172. function completeWriting(destination) {
  173. if (currentView && writtenBytes > 0) {
  174. destination.write(currentView.subarray(0, writtenBytes));
  175. }
  176. currentView = null;
  177. writtenBytes = 0;
  178. destinationHasCapacity = true;
  179. }
  180. function close(destination) {
  181. destination.end();
  182. }
  183. var textEncoder = new util.TextEncoder();
  184. function stringToChunk(content) {
  185. return content;
  186. }
  187. function stringToPrecomputedChunk(content) {
  188. return textEncoder.encode(content);
  189. }
  190. function closeWithError(destination, error) {
  191. // $FlowFixMe: This is an Error object or the destination accepts other types.
  192. destination.destroy(error);
  193. }
  194. /*
  195. * The `'' + value` pattern (used in in perf-sensitive code) throws for Symbol
  196. * and Temporal.* types. See https://github.com/facebook/react/pull/22064.
  197. *
  198. * The functions in this module will throw an easier-to-understand,
  199. * easier-to-debug exception with a clear errors message message explaining the
  200. * problem. (Instead of a confusing exception thrown inside the implementation
  201. * of the `value` object).
  202. */
  203. // $FlowFixMe only called in DEV, so void return is not possible.
  204. function typeName(value) {
  205. {
  206. // toStringTag is needed for namespaced types like Temporal.Instant
  207. var hasToStringTag = typeof Symbol === 'function' && Symbol.toStringTag;
  208. var type = hasToStringTag && value[Symbol.toStringTag] || value.constructor.name || 'Object';
  209. return type;
  210. }
  211. } // $FlowFixMe only called in DEV, so void return is not possible.
  212. function willCoercionThrow(value) {
  213. {
  214. try {
  215. testStringCoercion(value);
  216. return false;
  217. } catch (e) {
  218. return true;
  219. }
  220. }
  221. }
  222. function testStringCoercion(value) {
  223. // If you ended up here by following an exception call stack, here's what's
  224. // happened: you supplied an object or symbol value to React (as a prop, key,
  225. // DOM attribute, CSS property, string ref, etc.) and when React tried to
  226. // coerce it to a string using `'' + value`, an exception was thrown.
  227. //
  228. // The most common types that will cause this exception are `Symbol` instances
  229. // and Temporal objects like `Temporal.Instant`. But any object that has a
  230. // `valueOf` or `[Symbol.toPrimitive]` method that throws will also cause this
  231. // exception. (Library authors do this to prevent users from using built-in
  232. // numeric operators like `+` or comparison operators like `>=` because custom
  233. // methods are needed to perform accurate arithmetic or comparison.)
  234. //
  235. // To fix the problem, coerce this object or symbol value to a string before
  236. // passing it to React. The most reliable way is usually `String(value)`.
  237. //
  238. // To find which value is throwing, check the browser or debugger console.
  239. // Before this exception was thrown, there should be `console.error` output
  240. // that shows the type (Symbol, Temporal.PlainDate, etc.) that caused the
  241. // problem and how that type was used: key, atrribute, input value prop, etc.
  242. // In most cases, this console output also shows the component and its
  243. // ancestor components where the exception happened.
  244. //
  245. // eslint-disable-next-line react-internal/safe-string-coercion
  246. return '' + value;
  247. }
  248. function checkAttributeStringCoercion(value, attributeName) {
  249. {
  250. if (willCoercionThrow(value)) {
  251. error('The provided `%s` attribute is an unsupported type %s.' + ' This value must be coerced to a string before before using it here.', attributeName, typeName(value));
  252. return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
  253. }
  254. }
  255. }
  256. function checkCSSPropertyStringCoercion(value, propName) {
  257. {
  258. if (willCoercionThrow(value)) {
  259. error('The provided `%s` CSS property is an unsupported type %s.' + ' This value must be coerced to a string before before using it here.', propName, typeName(value));
  260. return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
  261. }
  262. }
  263. }
  264. function checkHtmlStringCoercion(value) {
  265. {
  266. if (willCoercionThrow(value)) {
  267. error('The provided HTML markup uses a value of unsupported type %s.' + ' This value must be coerced to a string before before using it here.', typeName(value));
  268. return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
  269. }
  270. }
  271. }
  272. var hasOwnProperty = Object.prototype.hasOwnProperty;
  273. // A reserved attribute.
  274. // It is handled by React separately and shouldn't be written to the DOM.
  275. var RESERVED = 0; // A simple string attribute.
  276. // Attributes that aren't in the filter are presumed to have this type.
  277. var STRING = 1; // A string attribute that accepts booleans in React. In HTML, these are called
  278. // "enumerated" attributes with "true" and "false" as possible values.
  279. // When true, it should be set to a "true" string.
  280. // When false, it should be set to a "false" string.
  281. var BOOLEANISH_STRING = 2; // A real boolean attribute.
  282. // When true, it should be present (set either to an empty string or its name).
  283. // When false, it should be omitted.
  284. var BOOLEAN = 3; // An attribute that can be used as a flag as well as with a value.
  285. // When true, it should be present (set either to an empty string or its name).
  286. // When false, it should be omitted.
  287. // For any other value, should be present with that value.
  288. var OVERLOADED_BOOLEAN = 4; // An attribute that must be numeric or parse as a numeric.
  289. // When falsy, it should be removed.
  290. var NUMERIC = 5; // An attribute that must be positive numeric or parse as a positive numeric.
  291. // When falsy, it should be removed.
  292. var POSITIVE_NUMERIC = 6;
  293. /* eslint-disable max-len */
  294. 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";
  295. /* eslint-enable max-len */
  296. var ATTRIBUTE_NAME_CHAR = ATTRIBUTE_NAME_START_CHAR + "\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
  297. var VALID_ATTRIBUTE_NAME_REGEX = new RegExp('^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$');
  298. var illegalAttributeNameCache = {};
  299. var validatedAttributeNameCache = {};
  300. function isAttributeNameSafe(attributeName) {
  301. if (hasOwnProperty.call(validatedAttributeNameCache, attributeName)) {
  302. return true;
  303. }
  304. if (hasOwnProperty.call(illegalAttributeNameCache, attributeName)) {
  305. return false;
  306. }
  307. if (VALID_ATTRIBUTE_NAME_REGEX.test(attributeName)) {
  308. validatedAttributeNameCache[attributeName] = true;
  309. return true;
  310. }
  311. illegalAttributeNameCache[attributeName] = true;
  312. {
  313. error('Invalid attribute name: `%s`', attributeName);
  314. }
  315. return false;
  316. }
  317. function shouldRemoveAttributeWithWarning(name, value, propertyInfo, isCustomComponentTag) {
  318. if (propertyInfo !== null && propertyInfo.type === RESERVED) {
  319. return false;
  320. }
  321. switch (typeof value) {
  322. case 'function': // $FlowIssue symbol is perfectly valid here
  323. case 'symbol':
  324. // eslint-disable-line
  325. return true;
  326. case 'boolean':
  327. {
  328. if (isCustomComponentTag) {
  329. return false;
  330. }
  331. if (propertyInfo !== null) {
  332. return !propertyInfo.acceptsBooleans;
  333. } else {
  334. var prefix = name.toLowerCase().slice(0, 5);
  335. return prefix !== 'data-' && prefix !== 'aria-';
  336. }
  337. }
  338. default:
  339. return false;
  340. }
  341. }
  342. function getPropertyInfo(name) {
  343. return properties.hasOwnProperty(name) ? properties[name] : null;
  344. }
  345. function PropertyInfoRecord(name, type, mustUseProperty, attributeName, attributeNamespace, sanitizeURL, removeEmptyString) {
  346. this.acceptsBooleans = type === BOOLEANISH_STRING || type === BOOLEAN || type === OVERLOADED_BOOLEAN;
  347. this.attributeName = attributeName;
  348. this.attributeNamespace = attributeNamespace;
  349. this.mustUseProperty = mustUseProperty;
  350. this.propertyName = name;
  351. this.type = type;
  352. this.sanitizeURL = sanitizeURL;
  353. this.removeEmptyString = removeEmptyString;
  354. } // When adding attributes to this list, be sure to also add them to
  355. // the `possibleStandardNames` module to ensure casing and incorrect
  356. // name warnings.
  357. var properties = {}; // These props are reserved by React. They shouldn't be written to the DOM.
  358. var reservedProps = ['children', 'dangerouslySetInnerHTML', // TODO: This prevents the assignment of defaultValue to regular
  359. // elements (not just inputs). Now that ReactDOMInput assigns to the
  360. // defaultValue property -- do we need this?
  361. 'defaultValue', 'defaultChecked', 'innerHTML', 'suppressContentEditableWarning', 'suppressHydrationWarning', 'style'];
  362. reservedProps.forEach(function (name) {
  363. properties[name] = new PropertyInfoRecord(name, RESERVED, false, // mustUseProperty
  364. name, // attributeName
  365. null, // attributeNamespace
  366. false, // sanitizeURL
  367. false);
  368. }); // A few React string attributes have a different name.
  369. // This is a mapping from React prop names to the attribute names.
  370. [['acceptCharset', 'accept-charset'], ['className', 'class'], ['htmlFor', 'for'], ['httpEquiv', 'http-equiv']].forEach(function (_ref) {
  371. var name = _ref[0],
  372. attributeName = _ref[1];
  373. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  374. attributeName, // attributeName
  375. null, // attributeNamespace
  376. false, // sanitizeURL
  377. false);
  378. }); // These are "enumerated" HTML attributes that accept "true" and "false".
  379. // In React, we let users pass `true` and `false` even though technically
  380. // these aren't boolean attributes (they are coerced to strings).
  381. ['contentEditable', 'draggable', 'spellCheck', 'value'].forEach(function (name) {
  382. properties[name] = new PropertyInfoRecord(name, BOOLEANISH_STRING, false, // mustUseProperty
  383. name.toLowerCase(), // attributeName
  384. null, // attributeNamespace
  385. false, // sanitizeURL
  386. false);
  387. }); // These are "enumerated" SVG attributes that accept "true" and "false".
  388. // In React, we let users pass `true` and `false` even though technically
  389. // these aren't boolean attributes (they are coerced to strings).
  390. // Since these are SVG attributes, their attribute names are case-sensitive.
  391. ['autoReverse', 'externalResourcesRequired', 'focusable', 'preserveAlpha'].forEach(function (name) {
  392. properties[name] = new PropertyInfoRecord(name, BOOLEANISH_STRING, false, // mustUseProperty
  393. name, // attributeName
  394. null, // attributeNamespace
  395. false, // sanitizeURL
  396. false);
  397. }); // These are HTML boolean attributes.
  398. ['allowFullScreen', 'async', // Note: there is a special case that prevents it from being written to the DOM
  399. // on the client side because the browsers are inconsistent. Instead we call focus().
  400. 'autoFocus', 'autoPlay', 'controls', 'default', 'defer', 'disabled', 'disablePictureInPicture', 'disableRemotePlayback', 'formNoValidate', 'hidden', 'loop', 'noModule', 'noValidate', 'open', 'playsInline', 'readOnly', 'required', 'reversed', 'scoped', 'seamless', // Microdata
  401. 'itemScope'].forEach(function (name) {
  402. properties[name] = new PropertyInfoRecord(name, BOOLEAN, false, // mustUseProperty
  403. name.toLowerCase(), // attributeName
  404. null, // attributeNamespace
  405. false, // sanitizeURL
  406. false);
  407. }); // These are the few React props that we set as DOM properties
  408. // rather than attributes. These are all booleans.
  409. ['checked', // Note: `option.selected` is not updated if `select.multiple` is
  410. // disabled with `removeAttribute`. We have special logic for handling this.
  411. 'multiple', 'muted', 'selected' // NOTE: if you add a camelCased prop to this list,
  412. // you'll need to set attributeName to name.toLowerCase()
  413. // instead in the assignment below.
  414. ].forEach(function (name) {
  415. properties[name] = new PropertyInfoRecord(name, BOOLEAN, true, // mustUseProperty
  416. name, // attributeName
  417. null, // attributeNamespace
  418. false, // sanitizeURL
  419. false);
  420. }); // These are HTML attributes that are "overloaded booleans": they behave like
  421. // booleans, but can also accept a string value.
  422. ['capture', 'download' // NOTE: if you add a camelCased prop to this list,
  423. // you'll need to set attributeName to name.toLowerCase()
  424. // instead in the assignment below.
  425. ].forEach(function (name) {
  426. properties[name] = new PropertyInfoRecord(name, OVERLOADED_BOOLEAN, false, // mustUseProperty
  427. name, // attributeName
  428. null, // attributeNamespace
  429. false, // sanitizeURL
  430. false);
  431. }); // These are HTML attributes that must be positive numbers.
  432. ['cols', 'rows', 'size', 'span' // NOTE: if you add a camelCased prop to this list,
  433. // you'll need to set attributeName to name.toLowerCase()
  434. // instead in the assignment below.
  435. ].forEach(function (name) {
  436. properties[name] = new PropertyInfoRecord(name, POSITIVE_NUMERIC, false, // mustUseProperty
  437. name, // attributeName
  438. null, // attributeNamespace
  439. false, // sanitizeURL
  440. false);
  441. }); // These are HTML attributes that must be numbers.
  442. ['rowSpan', 'start'].forEach(function (name) {
  443. properties[name] = new PropertyInfoRecord(name, NUMERIC, false, // mustUseProperty
  444. name.toLowerCase(), // attributeName
  445. null, // attributeNamespace
  446. false, // sanitizeURL
  447. false);
  448. });
  449. var CAMELIZE = /[\-\:]([a-z])/g;
  450. var capitalize = function (token) {
  451. return token[1].toUpperCase();
  452. }; // This is a list of all SVG attributes that need special casing, namespacing,
  453. // or boolean value assignment. Regular attributes that just accept strings
  454. // and have the same names are omitted, just like in the HTML attribute filter.
  455. // Some of these attributes can be hard to find. This list was created by
  456. // scraping the MDN documentation.
  457. ['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,
  458. // you'll need to set attributeName to name.toLowerCase()
  459. // instead in the assignment below.
  460. ].forEach(function (attributeName) {
  461. var name = attributeName.replace(CAMELIZE, capitalize);
  462. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  463. attributeName, null, // attributeNamespace
  464. false, // sanitizeURL
  465. false);
  466. }); // String SVG attributes with the xlink namespace.
  467. ['xlink:actuate', 'xlink:arcrole', 'xlink:role', 'xlink:show', 'xlink:title', 'xlink:type' // NOTE: if you add a camelCased prop to this list,
  468. // you'll need to set attributeName to name.toLowerCase()
  469. // instead in the assignment below.
  470. ].forEach(function (attributeName) {
  471. var name = attributeName.replace(CAMELIZE, capitalize);
  472. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  473. attributeName, 'http://www.w3.org/1999/xlink', false, // sanitizeURL
  474. false);
  475. }); // String SVG attributes with the xml namespace.
  476. ['xml:base', 'xml:lang', 'xml:space' // NOTE: if you add a camelCased prop to this list,
  477. // you'll need to set attributeName to name.toLowerCase()
  478. // instead in the assignment below.
  479. ].forEach(function (attributeName) {
  480. var name = attributeName.replace(CAMELIZE, capitalize);
  481. properties[name] = new PropertyInfoRecord(name, STRING, false, // mustUseProperty
  482. attributeName, 'http://www.w3.org/XML/1998/namespace', false, // sanitizeURL
  483. false);
  484. }); // These attribute exists both in HTML and SVG.
  485. // The attribute name is case-sensitive in SVG so we can't just use
  486. // the React name like we do for attributes that exist only in HTML.
  487. ['tabIndex', 'crossOrigin'].forEach(function (attributeName) {
  488. properties[attributeName] = new PropertyInfoRecord(attributeName, STRING, false, // mustUseProperty
  489. attributeName.toLowerCase(), // attributeName
  490. null, // attributeNamespace
  491. false, // sanitizeURL
  492. false);
  493. }); // These attributes accept URLs. These must not allow javascript: URLS.
  494. // These will also need to accept Trusted Types object in the future.
  495. var xlinkHref = 'xlinkHref';
  496. properties[xlinkHref] = new PropertyInfoRecord('xlinkHref', STRING, false, // mustUseProperty
  497. 'xlink:href', 'http://www.w3.org/1999/xlink', true, // sanitizeURL
  498. false);
  499. ['src', 'href', 'action', 'formAction'].forEach(function (attributeName) {
  500. properties[attributeName] = new PropertyInfoRecord(attributeName, STRING, false, // mustUseProperty
  501. attributeName.toLowerCase(), // attributeName
  502. null, // attributeNamespace
  503. true, // sanitizeURL
  504. true);
  505. });
  506. /**
  507. * CSS properties which accept numbers but are not in units of "px".
  508. */
  509. var isUnitlessNumber = {
  510. animationIterationCount: true,
  511. aspectRatio: true,
  512. borderImageOutset: true,
  513. borderImageSlice: true,
  514. borderImageWidth: true,
  515. boxFlex: true,
  516. boxFlexGroup: true,
  517. boxOrdinalGroup: true,
  518. columnCount: true,
  519. columns: true,
  520. flex: true,
  521. flexGrow: true,
  522. flexPositive: true,
  523. flexShrink: true,
  524. flexNegative: true,
  525. flexOrder: true,
  526. gridArea: true,
  527. gridRow: true,
  528. gridRowEnd: true,
  529. gridRowSpan: true,
  530. gridRowStart: true,
  531. gridColumn: true,
  532. gridColumnEnd: true,
  533. gridColumnSpan: true,
  534. gridColumnStart: true,
  535. fontWeight: true,
  536. lineClamp: true,
  537. lineHeight: true,
  538. opacity: true,
  539. order: true,
  540. orphans: true,
  541. tabSize: true,
  542. widows: true,
  543. zIndex: true,
  544. zoom: true,
  545. // SVG-related properties
  546. fillOpacity: true,
  547. floodOpacity: true,
  548. stopOpacity: true,
  549. strokeDasharray: true,
  550. strokeDashoffset: true,
  551. strokeMiterlimit: true,
  552. strokeOpacity: true,
  553. strokeWidth: true
  554. };
  555. /**
  556. * @param {string} prefix vendor-specific prefix, eg: Webkit
  557. * @param {string} key style name, eg: transitionDuration
  558. * @return {string} style name prefixed with `prefix`, properly camelCased, eg:
  559. * WebkitTransitionDuration
  560. */
  561. function prefixKey(prefix, key) {
  562. return prefix + key.charAt(0).toUpperCase() + key.substring(1);
  563. }
  564. /**
  565. * Support style names that may come passed in prefixed by adding permutations
  566. * of vendor prefixes.
  567. */
  568. var prefixes = ['Webkit', 'ms', 'Moz', 'O']; // Using Object.keys here, or else the vanilla for-in loop makes IE8 go into an
  569. // infinite loop, because it iterates over the newly added props too.
  570. Object.keys(isUnitlessNumber).forEach(function (prop) {
  571. prefixes.forEach(function (prefix) {
  572. isUnitlessNumber[prefixKey(prefix, prop)] = isUnitlessNumber[prop];
  573. });
  574. });
  575. var hasReadOnlyValue = {
  576. button: true,
  577. checkbox: true,
  578. image: true,
  579. hidden: true,
  580. radio: true,
  581. reset: true,
  582. submit: true
  583. };
  584. function checkControlledValueProps(tagName, props) {
  585. {
  586. if (!(hasReadOnlyValue[props.type] || props.onChange || props.onInput || props.readOnly || props.disabled || props.value == null)) {
  587. 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`.');
  588. }
  589. if (!(props.onChange || props.readOnly || props.disabled || props.checked == null)) {
  590. 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`.');
  591. }
  592. }
  593. }
  594. function isCustomComponent(tagName, props) {
  595. if (tagName.indexOf('-') === -1) {
  596. return typeof props.is === 'string';
  597. }
  598. switch (tagName) {
  599. // These are reserved SVG and MathML elements.
  600. // We don't mind this list too much because we expect it to never grow.
  601. // The alternative is to track the namespace in a few places which is convoluted.
  602. // https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
  603. case 'annotation-xml':
  604. case 'color-profile':
  605. case 'font-face':
  606. case 'font-face-src':
  607. case 'font-face-uri':
  608. case 'font-face-format':
  609. case 'font-face-name':
  610. case 'missing-glyph':
  611. return false;
  612. default:
  613. return true;
  614. }
  615. }
  616. var ariaProperties = {
  617. 'aria-current': 0,
  618. // state
  619. 'aria-description': 0,
  620. 'aria-details': 0,
  621. 'aria-disabled': 0,
  622. // state
  623. 'aria-hidden': 0,
  624. // state
  625. 'aria-invalid': 0,
  626. // state
  627. 'aria-keyshortcuts': 0,
  628. 'aria-label': 0,
  629. 'aria-roledescription': 0,
  630. // Widget Attributes
  631. 'aria-autocomplete': 0,
  632. 'aria-checked': 0,
  633. 'aria-expanded': 0,
  634. 'aria-haspopup': 0,
  635. 'aria-level': 0,
  636. 'aria-modal': 0,
  637. 'aria-multiline': 0,
  638. 'aria-multiselectable': 0,
  639. 'aria-orientation': 0,
  640. 'aria-placeholder': 0,
  641. 'aria-pressed': 0,
  642. 'aria-readonly': 0,
  643. 'aria-required': 0,
  644. 'aria-selected': 0,
  645. 'aria-sort': 0,
  646. 'aria-valuemax': 0,
  647. 'aria-valuemin': 0,
  648. 'aria-valuenow': 0,
  649. 'aria-valuetext': 0,
  650. // Live Region Attributes
  651. 'aria-atomic': 0,
  652. 'aria-busy': 0,
  653. 'aria-live': 0,
  654. 'aria-relevant': 0,
  655. // Drag-and-Drop Attributes
  656. 'aria-dropeffect': 0,
  657. 'aria-grabbed': 0,
  658. // Relationship Attributes
  659. 'aria-activedescendant': 0,
  660. 'aria-colcount': 0,
  661. 'aria-colindex': 0,
  662. 'aria-colspan': 0,
  663. 'aria-controls': 0,
  664. 'aria-describedby': 0,
  665. 'aria-errormessage': 0,
  666. 'aria-flowto': 0,
  667. 'aria-labelledby': 0,
  668. 'aria-owns': 0,
  669. 'aria-posinset': 0,
  670. 'aria-rowcount': 0,
  671. 'aria-rowindex': 0,
  672. 'aria-rowspan': 0,
  673. 'aria-setsize': 0
  674. };
  675. var warnedProperties = {};
  676. var rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
  677. var rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
  678. function validateProperty(tagName, name) {
  679. {
  680. if (hasOwnProperty.call(warnedProperties, name) && warnedProperties[name]) {
  681. return true;
  682. }
  683. if (rARIACamel.test(name)) {
  684. var ariaName = 'aria-' + name.slice(4).toLowerCase();
  685. var correctName = ariaProperties.hasOwnProperty(ariaName) ? ariaName : null; // If this is an aria-* attribute, but is not listed in the known DOM
  686. // DOM properties, then it is an invalid aria-* attribute.
  687. if (correctName == null) {
  688. error('Invalid ARIA attribute `%s`. ARIA attributes follow the pattern aria-* and must be lowercase.', name);
  689. warnedProperties[name] = true;
  690. return true;
  691. } // aria-* attributes should be lowercase; suggest the lowercase version.
  692. if (name !== correctName) {
  693. error('Invalid ARIA attribute `%s`. Did you mean `%s`?', name, correctName);
  694. warnedProperties[name] = true;
  695. return true;
  696. }
  697. }
  698. if (rARIA.test(name)) {
  699. var lowerCasedName = name.toLowerCase();
  700. var standardName = ariaProperties.hasOwnProperty(lowerCasedName) ? lowerCasedName : null; // If this is an aria-* attribute, but is not listed in the known DOM
  701. // DOM properties, then it is an invalid aria-* attribute.
  702. if (standardName == null) {
  703. warnedProperties[name] = true;
  704. return false;
  705. } // aria-* attributes should be lowercase; suggest the lowercase version.
  706. if (name !== standardName) {
  707. error('Unknown ARIA attribute `%s`. Did you mean `%s`?', name, standardName);
  708. warnedProperties[name] = true;
  709. return true;
  710. }
  711. }
  712. }
  713. return true;
  714. }
  715. function warnInvalidARIAProps(type, props) {
  716. {
  717. var invalidProps = [];
  718. for (var key in props) {
  719. var isValid = validateProperty(type, key);
  720. if (!isValid) {
  721. invalidProps.push(key);
  722. }
  723. }
  724. var unknownPropString = invalidProps.map(function (prop) {
  725. return '`' + prop + '`';
  726. }).join(', ');
  727. if (invalidProps.length === 1) {
  728. error('Invalid aria prop %s on <%s> tag. ' + 'For details, see https://reactjs.org/link/invalid-aria-props', unknownPropString, type);
  729. } else if (invalidProps.length > 1) {
  730. error('Invalid aria props %s on <%s> tag. ' + 'For details, see https://reactjs.org/link/invalid-aria-props', unknownPropString, type);
  731. }
  732. }
  733. }
  734. function validateProperties(type, props) {
  735. if (isCustomComponent(type, props)) {
  736. return;
  737. }
  738. warnInvalidARIAProps(type, props);
  739. }
  740. var didWarnValueNull = false;
  741. function validateProperties$1(type, props) {
  742. {
  743. if (type !== 'input' && type !== 'textarea' && type !== 'select') {
  744. return;
  745. }
  746. if (props != null && props.value === null && !didWarnValueNull) {
  747. didWarnValueNull = true;
  748. if (type === 'select' && props.multiple) {
  749. 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);
  750. } else {
  751. error('`value` prop on `%s` should not be null. ' + 'Consider using an empty string to clear the component or `undefined` ' + 'for uncontrolled components.', type);
  752. }
  753. }
  754. }
  755. }
  756. // When adding attributes to the HTML or SVG allowed attribute list, be sure to
  757. // also add them to this module to ensure casing and incorrect name
  758. // warnings.
  759. var possibleStandardNames = {
  760. // HTML
  761. accept: 'accept',
  762. acceptcharset: 'acceptCharset',
  763. 'accept-charset': 'acceptCharset',
  764. accesskey: 'accessKey',
  765. action: 'action',
  766. allowfullscreen: 'allowFullScreen',
  767. alt: 'alt',
  768. as: 'as',
  769. async: 'async',
  770. autocapitalize: 'autoCapitalize',
  771. autocomplete: 'autoComplete',
  772. autocorrect: 'autoCorrect',
  773. autofocus: 'autoFocus',
  774. autoplay: 'autoPlay',
  775. autosave: 'autoSave',
  776. capture: 'capture',
  777. cellpadding: 'cellPadding',
  778. cellspacing: 'cellSpacing',
  779. challenge: 'challenge',
  780. charset: 'charSet',
  781. checked: 'checked',
  782. children: 'children',
  783. cite: 'cite',
  784. class: 'className',
  785. classid: 'classID',
  786. classname: 'className',
  787. cols: 'cols',
  788. colspan: 'colSpan',
  789. content: 'content',
  790. contenteditable: 'contentEditable',
  791. contextmenu: 'contextMenu',
  792. controls: 'controls',
  793. controlslist: 'controlsList',
  794. coords: 'coords',
  795. crossorigin: 'crossOrigin',
  796. dangerouslysetinnerhtml: 'dangerouslySetInnerHTML',
  797. data: 'data',
  798. datetime: 'dateTime',
  799. default: 'default',
  800. defaultchecked: 'defaultChecked',
  801. defaultvalue: 'defaultValue',
  802. defer: 'defer',
  803. dir: 'dir',
  804. disabled: 'disabled',
  805. disablepictureinpicture: 'disablePictureInPicture',
  806. disableremoteplayback: 'disableRemotePlayback',
  807. download: 'download',
  808. draggable: 'draggable',
  809. enctype: 'encType',
  810. enterkeyhint: 'enterKeyHint',
  811. for: 'htmlFor',
  812. form: 'form',
  813. formmethod: 'formMethod',
  814. formaction: 'formAction',
  815. formenctype: 'formEncType',
  816. formnovalidate: 'formNoValidate',
  817. formtarget: 'formTarget',
  818. frameborder: 'frameBorder',
  819. headers: 'headers',
  820. height: 'height',
  821. hidden: 'hidden',
  822. high: 'high',
  823. href: 'href',
  824. hreflang: 'hrefLang',
  825. htmlfor: 'htmlFor',
  826. httpequiv: 'httpEquiv',
  827. 'http-equiv': 'httpEquiv',
  828. icon: 'icon',
  829. id: 'id',
  830. imagesizes: 'imageSizes',
  831. imagesrcset: 'imageSrcSet',
  832. innerhtml: 'innerHTML',
  833. inputmode: 'inputMode',
  834. integrity: 'integrity',
  835. is: 'is',
  836. itemid: 'itemID',
  837. itemprop: 'itemProp',
  838. itemref: 'itemRef',
  839. itemscope: 'itemScope',
  840. itemtype: 'itemType',
  841. keyparams: 'keyParams',
  842. keytype: 'keyType',
  843. kind: 'kind',
  844. label: 'label',
  845. lang: 'lang',
  846. list: 'list',
  847. loop: 'loop',
  848. low: 'low',
  849. manifest: 'manifest',
  850. marginwidth: 'marginWidth',
  851. marginheight: 'marginHeight',
  852. max: 'max',
  853. maxlength: 'maxLength',
  854. media: 'media',
  855. mediagroup: 'mediaGroup',
  856. method: 'method',
  857. min: 'min',
  858. minlength: 'minLength',
  859. multiple: 'multiple',
  860. muted: 'muted',
  861. name: 'name',
  862. nomodule: 'noModule',
  863. nonce: 'nonce',
  864. novalidate: 'noValidate',
  865. open: 'open',
  866. optimum: 'optimum',
  867. pattern: 'pattern',
  868. placeholder: 'placeholder',
  869. playsinline: 'playsInline',
  870. poster: 'poster',
  871. preload: 'preload',
  872. profile: 'profile',
  873. radiogroup: 'radioGroup',
  874. readonly: 'readOnly',
  875. referrerpolicy: 'referrerPolicy',
  876. rel: 'rel',
  877. required: 'required',
  878. reversed: 'reversed',
  879. role: 'role',
  880. rows: 'rows',
  881. rowspan: 'rowSpan',
  882. sandbox: 'sandbox',
  883. scope: 'scope',
  884. scoped: 'scoped',
  885. scrolling: 'scrolling',
  886. seamless: 'seamless',
  887. selected: 'selected',
  888. shape: 'shape',
  889. size: 'size',
  890. sizes: 'sizes',
  891. span: 'span',
  892. spellcheck: 'spellCheck',
  893. src: 'src',
  894. srcdoc: 'srcDoc',
  895. srclang: 'srcLang',
  896. srcset: 'srcSet',
  897. start: 'start',
  898. step: 'step',
  899. style: 'style',
  900. summary: 'summary',
  901. tabindex: 'tabIndex',
  902. target: 'target',
  903. title: 'title',
  904. type: 'type',
  905. usemap: 'useMap',
  906. value: 'value',
  907. width: 'width',
  908. wmode: 'wmode',
  909. wrap: 'wrap',
  910. // SVG
  911. about: 'about',
  912. accentheight: 'accentHeight',
  913. 'accent-height': 'accentHeight',
  914. accumulate: 'accumulate',
  915. additive: 'additive',
  916. alignmentbaseline: 'alignmentBaseline',
  917. 'alignment-baseline': 'alignmentBaseline',
  918. allowreorder: 'allowReorder',
  919. alphabetic: 'alphabetic',
  920. amplitude: 'amplitude',
  921. arabicform: 'arabicForm',
  922. 'arabic-form': 'arabicForm',
  923. ascent: 'ascent',
  924. attributename: 'attributeName',
  925. attributetype: 'attributeType',
  926. autoreverse: 'autoReverse',
  927. azimuth: 'azimuth',
  928. basefrequency: 'baseFrequency',
  929. baselineshift: 'baselineShift',
  930. 'baseline-shift': 'baselineShift',
  931. baseprofile: 'baseProfile',
  932. bbox: 'bbox',
  933. begin: 'begin',
  934. bias: 'bias',
  935. by: 'by',
  936. calcmode: 'calcMode',
  937. capheight: 'capHeight',
  938. 'cap-height': 'capHeight',
  939. clip: 'clip',
  940. clippath: 'clipPath',
  941. 'clip-path': 'clipPath',
  942. clippathunits: 'clipPathUnits',
  943. cliprule: 'clipRule',
  944. 'clip-rule': 'clipRule',
  945. color: 'color',
  946. colorinterpolation: 'colorInterpolation',
  947. 'color-interpolation': 'colorInterpolation',
  948. colorinterpolationfilters: 'colorInterpolationFilters',
  949. 'color-interpolation-filters': 'colorInterpolationFilters',
  950. colorprofile: 'colorProfile',
  951. 'color-profile': 'colorProfile',
  952. colorrendering: 'colorRendering',
  953. 'color-rendering': 'colorRendering',
  954. contentscripttype: 'contentScriptType',
  955. contentstyletype: 'contentStyleType',
  956. cursor: 'cursor',
  957. cx: 'cx',
  958. cy: 'cy',
  959. d: 'd',
  960. datatype: 'datatype',
  961. decelerate: 'decelerate',
  962. descent: 'descent',
  963. diffuseconstant: 'diffuseConstant',
  964. direction: 'direction',
  965. display: 'display',
  966. divisor: 'divisor',
  967. dominantbaseline: 'dominantBaseline',
  968. 'dominant-baseline': 'dominantBaseline',
  969. dur: 'dur',
  970. dx: 'dx',
  971. dy: 'dy',
  972. edgemode: 'edgeMode',
  973. elevation: 'elevation',
  974. enablebackground: 'enableBackground',
  975. 'enable-background': 'enableBackground',
  976. end: 'end',
  977. exponent: 'exponent',
  978. externalresourcesrequired: 'externalResourcesRequired',
  979. fill: 'fill',
  980. fillopacity: 'fillOpacity',
  981. 'fill-opacity': 'fillOpacity',
  982. fillrule: 'fillRule',
  983. 'fill-rule': 'fillRule',
  984. filter: 'filter',
  985. filterres: 'filterRes',
  986. filterunits: 'filterUnits',
  987. floodopacity: 'floodOpacity',
  988. 'flood-opacity': 'floodOpacity',
  989. floodcolor: 'floodColor',
  990. 'flood-color': 'floodColor',
  991. focusable: 'focusable',
  992. fontfamily: 'fontFamily',
  993. 'font-family': 'fontFamily',
  994. fontsize: 'fontSize',
  995. 'font-size': 'fontSize',
  996. fontsizeadjust: 'fontSizeAdjust',
  997. 'font-size-adjust': 'fontSizeAdjust',
  998. fontstretch: 'fontStretch',
  999. 'font-stretch': 'fontStretch',
  1000. fontstyle: 'fontStyle',
  1001. 'font-style': 'fontStyle',
  1002. fontvariant: 'fontVariant',
  1003. 'font-variant': 'fontVariant',
  1004. fontweight: 'fontWeight',
  1005. 'font-weight': 'fontWeight',
  1006. format: 'format',
  1007. from: 'from',
  1008. fx: 'fx',
  1009. fy: 'fy',
  1010. g1: 'g1',
  1011. g2: 'g2',
  1012. glyphname: 'glyphName',
  1013. 'glyph-name': 'glyphName',
  1014. glyphorientationhorizontal: 'glyphOrientationHorizontal',
  1015. 'glyph-orientation-horizontal': 'glyphOrientationHorizontal',
  1016. glyphorientationvertical: 'glyphOrientationVertical',
  1017. 'glyph-orientation-vertical': 'glyphOrientationVertical',
  1018. glyphref: 'glyphRef',
  1019. gradienttransform: 'gradientTransform',
  1020. gradientunits: 'gradientUnits',
  1021. hanging: 'hanging',
  1022. horizadvx: 'horizAdvX',
  1023. 'horiz-adv-x': 'horizAdvX',
  1024. horizoriginx: 'horizOriginX',
  1025. 'horiz-origin-x': 'horizOriginX',
  1026. ideographic: 'ideographic',
  1027. imagerendering: 'imageRendering',
  1028. 'image-rendering': 'imageRendering',
  1029. in2: 'in2',
  1030. in: 'in',
  1031. inlist: 'inlist',
  1032. intercept: 'intercept',
  1033. k1: 'k1',
  1034. k2: 'k2',
  1035. k3: 'k3',
  1036. k4: 'k4',
  1037. k: 'k',
  1038. kernelmatrix: 'kernelMatrix',
  1039. kernelunitlength: 'kernelUnitLength',
  1040. kerning: 'kerning',
  1041. keypoints: 'keyPoints',
  1042. keysplines: 'keySplines',
  1043. keytimes: 'keyTimes',
  1044. lengthadjust: 'lengthAdjust',
  1045. letterspacing: 'letterSpacing',
  1046. 'letter-spacing': 'letterSpacing',
  1047. lightingcolor: 'lightingColor',
  1048. 'lighting-color': 'lightingColor',
  1049. limitingconeangle: 'limitingConeAngle',
  1050. local: 'local',
  1051. markerend: 'markerEnd',
  1052. 'marker-end': 'markerEnd',
  1053. markerheight: 'markerHeight',
  1054. markermid: 'markerMid',
  1055. 'marker-mid': 'markerMid',
  1056. markerstart: 'markerStart',
  1057. 'marker-start': 'markerStart',
  1058. markerunits: 'markerUnits',
  1059. markerwidth: 'markerWidth',
  1060. mask: 'mask',
  1061. maskcontentunits: 'maskContentUnits',
  1062. maskunits: 'maskUnits',
  1063. mathematical: 'mathematical',
  1064. mode: 'mode',
  1065. numoctaves: 'numOctaves',
  1066. offset: 'offset',
  1067. opacity: 'opacity',
  1068. operator: 'operator',
  1069. order: 'order',
  1070. orient: 'orient',
  1071. orientation: 'orientation',
  1072. origin: 'origin',
  1073. overflow: 'overflow',
  1074. overlineposition: 'overlinePosition',
  1075. 'overline-position': 'overlinePosition',
  1076. overlinethickness: 'overlineThickness',
  1077. 'overline-thickness': 'overlineThickness',
  1078. paintorder: 'paintOrder',
  1079. 'paint-order': 'paintOrder',
  1080. panose1: 'panose1',
  1081. 'panose-1': 'panose1',
  1082. pathlength: 'pathLength',
  1083. patterncontentunits: 'patternContentUnits',
  1084. patterntransform: 'patternTransform',
  1085. patternunits: 'patternUnits',
  1086. pointerevents: 'pointerEvents',
  1087. 'pointer-events': 'pointerEvents',
  1088. points: 'points',
  1089. pointsatx: 'pointsAtX',
  1090. pointsaty: 'pointsAtY',
  1091. pointsatz: 'pointsAtZ',
  1092. prefix: 'prefix',
  1093. preservealpha: 'preserveAlpha',
  1094. preserveaspectratio: 'preserveAspectRatio',
  1095. primitiveunits: 'primitiveUnits',
  1096. property: 'property',
  1097. r: 'r',
  1098. radius: 'radius',
  1099. refx: 'refX',
  1100. refy: 'refY',
  1101. renderingintent: 'renderingIntent',
  1102. 'rendering-intent': 'renderingIntent',
  1103. repeatcount: 'repeatCount',
  1104. repeatdur: 'repeatDur',
  1105. requiredextensions: 'requiredExtensions',
  1106. requiredfeatures: 'requiredFeatures',
  1107. resource: 'resource',
  1108. restart: 'restart',
  1109. result: 'result',
  1110. results: 'results',
  1111. rotate: 'rotate',
  1112. rx: 'rx',
  1113. ry: 'ry',
  1114. scale: 'scale',
  1115. security: 'security',
  1116. seed: 'seed',
  1117. shaperendering: 'shapeRendering',
  1118. 'shape-rendering': 'shapeRendering',
  1119. slope: 'slope',
  1120. spacing: 'spacing',
  1121. specularconstant: 'specularConstant',
  1122. specularexponent: 'specularExponent',
  1123. speed: 'speed',
  1124. spreadmethod: 'spreadMethod',
  1125. startoffset: 'startOffset',
  1126. stddeviation: 'stdDeviation',
  1127. stemh: 'stemh',
  1128. stemv: 'stemv',
  1129. stitchtiles: 'stitchTiles',
  1130. stopcolor: 'stopColor',
  1131. 'stop-color': 'stopColor',
  1132. stopopacity: 'stopOpacity',
  1133. 'stop-opacity': 'stopOpacity',
  1134. strikethroughposition: 'strikethroughPosition',
  1135. 'strikethrough-position': 'strikethroughPosition',
  1136. strikethroughthickness: 'strikethroughThickness',
  1137. 'strikethrough-thickness': 'strikethroughThickness',
  1138. string: 'string',
  1139. stroke: 'stroke',
  1140. strokedasharray: 'strokeDasharray',
  1141. 'stroke-dasharray': 'strokeDasharray',
  1142. strokedashoffset: 'strokeDashoffset',
  1143. 'stroke-dashoffset': 'strokeDashoffset',
  1144. strokelinecap: 'strokeLinecap',
  1145. 'stroke-linecap': 'strokeLinecap',
  1146. strokelinejoin: 'strokeLinejoin',
  1147. 'stroke-linejoin': 'strokeLinejoin',
  1148. strokemiterlimit: 'strokeMiterlimit',
  1149. 'stroke-miterlimit': 'strokeMiterlimit',
  1150. strokewidth: 'strokeWidth',
  1151. 'stroke-width': 'strokeWidth',
  1152. strokeopacity: 'strokeOpacity',
  1153. 'stroke-opacity': 'strokeOpacity',
  1154. suppresscontenteditablewarning: 'suppressContentEditableWarning',
  1155. suppresshydrationwarning: 'suppressHydrationWarning',
  1156. surfacescale: 'surfaceScale',
  1157. systemlanguage: 'systemLanguage',
  1158. tablevalues: 'tableValues',
  1159. targetx: 'targetX',
  1160. targety: 'targetY',
  1161. textanchor: 'textAnchor',
  1162. 'text-anchor': 'textAnchor',
  1163. textdecoration: 'textDecoration',
  1164. 'text-decoration': 'textDecoration',
  1165. textlength: 'textLength',
  1166. textrendering: 'textRendering',
  1167. 'text-rendering': 'textRendering',
  1168. to: 'to',
  1169. transform: 'transform',
  1170. typeof: 'typeof',
  1171. u1: 'u1',
  1172. u2: 'u2',
  1173. underlineposition: 'underlinePosition',
  1174. 'underline-position': 'underlinePosition',
  1175. underlinethickness: 'underlineThickness',
  1176. 'underline-thickness': 'underlineThickness',
  1177. unicode: 'unicode',
  1178. unicodebidi: 'unicodeBidi',
  1179. 'unicode-bidi': 'unicodeBidi',
  1180. unicoderange: 'unicodeRange',
  1181. 'unicode-range': 'unicodeRange',
  1182. unitsperem: 'unitsPerEm',
  1183. 'units-per-em': 'unitsPerEm',
  1184. unselectable: 'unselectable',
  1185. valphabetic: 'vAlphabetic',
  1186. 'v-alphabetic': 'vAlphabetic',
  1187. values: 'values',
  1188. vectoreffect: 'vectorEffect',
  1189. 'vector-effect': 'vectorEffect',
  1190. version: 'version',
  1191. vertadvy: 'vertAdvY',
  1192. 'vert-adv-y': 'vertAdvY',
  1193. vertoriginx: 'vertOriginX',
  1194. 'vert-origin-x': 'vertOriginX',
  1195. vertoriginy: 'vertOriginY',
  1196. 'vert-origin-y': 'vertOriginY',
  1197. vhanging: 'vHanging',
  1198. 'v-hanging': 'vHanging',
  1199. videographic: 'vIdeographic',
  1200. 'v-ideographic': 'vIdeographic',
  1201. viewbox: 'viewBox',
  1202. viewtarget: 'viewTarget',
  1203. visibility: 'visibility',
  1204. vmathematical: 'vMathematical',
  1205. 'v-mathematical': 'vMathematical',
  1206. vocab: 'vocab',
  1207. widths: 'widths',
  1208. wordspacing: 'wordSpacing',
  1209. 'word-spacing': 'wordSpacing',
  1210. writingmode: 'writingMode',
  1211. 'writing-mode': 'writingMode',
  1212. x1: 'x1',
  1213. x2: 'x2',
  1214. x: 'x',
  1215. xchannelselector: 'xChannelSelector',
  1216. xheight: 'xHeight',
  1217. 'x-height': 'xHeight',
  1218. xlinkactuate: 'xlinkActuate',
  1219. 'xlink:actuate': 'xlinkActuate',
  1220. xlinkarcrole: 'xlinkArcrole',
  1221. 'xlink:arcrole': 'xlinkArcrole',
  1222. xlinkhref: 'xlinkHref',
  1223. 'xlink:href': 'xlinkHref',
  1224. xlinkrole: 'xlinkRole',
  1225. 'xlink:role': 'xlinkRole',
  1226. xlinkshow: 'xlinkShow',
  1227. 'xlink:show': 'xlinkShow',
  1228. xlinktitle: 'xlinkTitle',
  1229. 'xlink:title': 'xlinkTitle',
  1230. xlinktype: 'xlinkType',
  1231. 'xlink:type': 'xlinkType',
  1232. xmlbase: 'xmlBase',
  1233. 'xml:base': 'xmlBase',
  1234. xmllang: 'xmlLang',
  1235. 'xml:lang': 'xmlLang',
  1236. xmlns: 'xmlns',
  1237. 'xml:space': 'xmlSpace',
  1238. xmlnsxlink: 'xmlnsXlink',
  1239. 'xmlns:xlink': 'xmlnsXlink',
  1240. xmlspace: 'xmlSpace',
  1241. y1: 'y1',
  1242. y2: 'y2',
  1243. y: 'y',
  1244. ychannelselector: 'yChannelSelector',
  1245. z: 'z',
  1246. zoomandpan: 'zoomAndPan'
  1247. };
  1248. var validateProperty$1 = function () {};
  1249. {
  1250. var warnedProperties$1 = {};
  1251. var EVENT_NAME_REGEX = /^on./;
  1252. var INVALID_EVENT_NAME_REGEX = /^on[^A-Z]/;
  1253. var rARIA$1 = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
  1254. var rARIACamel$1 = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
  1255. validateProperty$1 = function (tagName, name, value, eventRegistry) {
  1256. if (hasOwnProperty.call(warnedProperties$1, name) && warnedProperties$1[name]) {
  1257. return true;
  1258. }
  1259. var lowerCasedName = name.toLowerCase();
  1260. if (lowerCasedName === 'onfocusin' || lowerCasedName === 'onfocusout') {
  1261. 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.');
  1262. warnedProperties$1[name] = true;
  1263. return true;
  1264. } // We can't rely on the event system being injected on the server.
  1265. if (eventRegistry != null) {
  1266. var registrationNameDependencies = eventRegistry.registrationNameDependencies,
  1267. possibleRegistrationNames = eventRegistry.possibleRegistrationNames;
  1268. if (registrationNameDependencies.hasOwnProperty(name)) {
  1269. return true;
  1270. }
  1271. var registrationName = possibleRegistrationNames.hasOwnProperty(lowerCasedName) ? possibleRegistrationNames[lowerCasedName] : null;
  1272. if (registrationName != null) {
  1273. error('Invalid event handler property `%s`. Did you mean `%s`?', name, registrationName);
  1274. warnedProperties$1[name] = true;
  1275. return true;
  1276. }
  1277. if (EVENT_NAME_REGEX.test(name)) {
  1278. error('Unknown event handler property `%s`. It will be ignored.', name);
  1279. warnedProperties$1[name] = true;
  1280. return true;
  1281. }
  1282. } else if (EVENT_NAME_REGEX.test(name)) {
  1283. // If no event plugins have been injected, we are in a server environment.
  1284. // So we can't tell if the event name is correct for sure, but we can filter
  1285. // out known bad ones like `onclick`. We can't suggest a specific replacement though.
  1286. if (INVALID_EVENT_NAME_REGEX.test(name)) {
  1287. error('Invalid event handler property `%s`. ' + 'React events use the camelCase naming convention, for example `onClick`.', name);
  1288. }
  1289. warnedProperties$1[name] = true;
  1290. return true;
  1291. } // Let the ARIA attribute hook validate ARIA attributes
  1292. if (rARIA$1.test(name) || rARIACamel$1.test(name)) {
  1293. return true;
  1294. }
  1295. if (lowerCasedName === 'innerhtml') {
  1296. error('Directly setting property `innerHTML` is not permitted. ' + 'For more information, lookup documentation on `dangerouslySetInnerHTML`.');
  1297. warnedProperties$1[name] = true;
  1298. return true;
  1299. }
  1300. if (lowerCasedName === 'aria') {
  1301. error('The `aria` attribute is reserved for future use in React. ' + 'Pass individual `aria-` attributes instead.');
  1302. warnedProperties$1[name] = true;
  1303. return true;
  1304. }
  1305. if (lowerCasedName === 'is' && value !== null && value !== undefined && typeof value !== 'string') {
  1306. error('Received a `%s` for a string attribute `is`. If this is expected, cast ' + 'the value to a string.', typeof value);
  1307. warnedProperties$1[name] = true;
  1308. return true;
  1309. }
  1310. if (typeof value === 'number' && isNaN(value)) {
  1311. error('Received NaN for the `%s` attribute. If this is expected, cast ' + 'the value to a string.', name);
  1312. warnedProperties$1[name] = true;
  1313. return true;
  1314. }
  1315. var propertyInfo = getPropertyInfo(name);
  1316. var isReserved = propertyInfo !== null && propertyInfo.type === RESERVED; // Known attributes should match the casing specified in the property config.
  1317. if (possibleStandardNames.hasOwnProperty(lowerCasedName)) {
  1318. var standardName = possibleStandardNames[lowerCasedName];
  1319. if (standardName !== name) {
  1320. error('Invalid DOM property `%s`. Did you mean `%s`?', name, standardName);
  1321. warnedProperties$1[name] = true;
  1322. return true;
  1323. }
  1324. } else if (!isReserved && name !== lowerCasedName) {
  1325. // Unknown attributes should have lowercase casing since that's how they
  1326. // will be cased anyway with server rendering.
  1327. 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);
  1328. warnedProperties$1[name] = true;
  1329. return true;
  1330. }
  1331. if (typeof value === 'boolean' && shouldRemoveAttributeWithWarning(name, value, propertyInfo, false)) {
  1332. if (value) {
  1333. 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);
  1334. } else {
  1335. 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);
  1336. }
  1337. warnedProperties$1[name] = true;
  1338. return true;
  1339. } // Now that we've validated casing, do not validate
  1340. // data types for reserved props
  1341. if (isReserved) {
  1342. return true;
  1343. } // Warn when a known attribute is a bad type
  1344. if (shouldRemoveAttributeWithWarning(name, value, propertyInfo, false)) {
  1345. warnedProperties$1[name] = true;
  1346. return false;
  1347. } // Warn when passing the strings 'false' or 'true' into a boolean prop
  1348. if ((value === 'false' || value === 'true') && propertyInfo !== null && propertyInfo.type === BOOLEAN) {
  1349. 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);
  1350. warnedProperties$1[name] = true;
  1351. return true;
  1352. }
  1353. return true;
  1354. };
  1355. }
  1356. var warnUnknownProperties = function (type, props, eventRegistry) {
  1357. {
  1358. var unknownProps = [];
  1359. for (var key in props) {
  1360. var isValid = validateProperty$1(type, key, props[key], eventRegistry);
  1361. if (!isValid) {
  1362. unknownProps.push(key);
  1363. }
  1364. }
  1365. var unknownPropString = unknownProps.map(function (prop) {
  1366. return '`' + prop + '`';
  1367. }).join(', ');
  1368. if (unknownProps.length === 1) {
  1369. 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);
  1370. } else if (unknownProps.length > 1) {
  1371. 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);
  1372. }
  1373. }
  1374. };
  1375. function validateProperties$2(type, props, eventRegistry) {
  1376. if (isCustomComponent(type, props)) {
  1377. return;
  1378. }
  1379. warnUnknownProperties(type, props, eventRegistry);
  1380. }
  1381. var warnValidStyle = function () {};
  1382. {
  1383. // 'msTransform' is correct, but the other prefixes should be capitalized
  1384. var badVendoredStyleNamePattern = /^(?:webkit|moz|o)[A-Z]/;
  1385. var msPattern = /^-ms-/;
  1386. var hyphenPattern = /-(.)/g; // style values shouldn't contain a semicolon
  1387. var badStyleValueWithSemicolonPattern = /;\s*$/;
  1388. var warnedStyleNames = {};
  1389. var warnedStyleValues = {};
  1390. var warnedForNaNValue = false;
  1391. var warnedForInfinityValue = false;
  1392. var camelize = function (string) {
  1393. return string.replace(hyphenPattern, function (_, character) {
  1394. return character.toUpperCase();
  1395. });
  1396. };
  1397. var warnHyphenatedStyleName = function (name) {
  1398. if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
  1399. return;
  1400. }
  1401. warnedStyleNames[name] = true;
  1402. error('Unsupported style property %s. Did you mean %s?', name, // As Andi Smith suggests
  1403. // (http://www.andismith.com/blog/2012/02/modernizr-prefixed/), an `-ms` prefix
  1404. // is converted to lowercase `ms`.
  1405. camelize(name.replace(msPattern, 'ms-')));
  1406. };
  1407. var warnBadVendoredStyleName = function (name) {
  1408. if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
  1409. return;
  1410. }
  1411. warnedStyleNames[name] = true;
  1412. error('Unsupported vendor-prefixed style property %s. Did you mean %s?', name, name.charAt(0).toUpperCase() + name.slice(1));
  1413. };
  1414. var warnStyleValueWithSemicolon = function (name, value) {
  1415. if (warnedStyleValues.hasOwnProperty(value) && warnedStyleValues[value]) {
  1416. return;
  1417. }
  1418. warnedStyleValues[value] = true;
  1419. error("Style property values shouldn't contain a semicolon. " + 'Try "%s: %s" instead.', name, value.replace(badStyleValueWithSemicolonPattern, ''));
  1420. };
  1421. var warnStyleValueIsNaN = function (name, value) {
  1422. if (warnedForNaNValue) {
  1423. return;
  1424. }
  1425. warnedForNaNValue = true;
  1426. error('`NaN` is an invalid value for the `%s` css style property.', name);
  1427. };
  1428. var warnStyleValueIsInfinity = function (name, value) {
  1429. if (warnedForInfinityValue) {
  1430. return;
  1431. }
  1432. warnedForInfinityValue = true;
  1433. error('`Infinity` is an invalid value for the `%s` css style property.', name);
  1434. };
  1435. warnValidStyle = function (name, value) {
  1436. if (name.indexOf('-') > -1) {
  1437. warnHyphenatedStyleName(name);
  1438. } else if (badVendoredStyleNamePattern.test(name)) {
  1439. warnBadVendoredStyleName(name);
  1440. } else if (badStyleValueWithSemicolonPattern.test(value)) {
  1441. warnStyleValueWithSemicolon(name, value);
  1442. }
  1443. if (typeof value === 'number') {
  1444. if (isNaN(value)) {
  1445. warnStyleValueIsNaN(name, value);
  1446. } else if (!isFinite(value)) {
  1447. warnStyleValueIsInfinity(name, value);
  1448. }
  1449. }
  1450. };
  1451. }
  1452. var warnValidStyle$1 = warnValidStyle;
  1453. // code copied and modified from escape-html
  1454. var matchHtmlRegExp = /["'&<>]/;
  1455. /**
  1456. * Escapes special characters and HTML entities in a given html string.
  1457. *
  1458. * @param {string} string HTML string to escape for later insertion
  1459. * @return {string}
  1460. * @public
  1461. */
  1462. function escapeHtml(string) {
  1463. {
  1464. checkHtmlStringCoercion(string);
  1465. }
  1466. var str = '' + string;
  1467. var match = matchHtmlRegExp.exec(str);
  1468. if (!match) {
  1469. return str;
  1470. }
  1471. var escape;
  1472. var html = '';
  1473. var index;
  1474. var lastIndex = 0;
  1475. for (index = match.index; index < str.length; index++) {
  1476. switch (str.charCodeAt(index)) {
  1477. case 34:
  1478. // "
  1479. escape = '&quot;';
  1480. break;
  1481. case 38:
  1482. // &
  1483. escape = '&amp;';
  1484. break;
  1485. case 39:
  1486. // '
  1487. escape = '&#x27;'; // modified from escape-html; used to be '&#39'
  1488. break;
  1489. case 60:
  1490. // <
  1491. escape = '&lt;';
  1492. break;
  1493. case 62:
  1494. // >
  1495. escape = '&gt;';
  1496. break;
  1497. default:
  1498. continue;
  1499. }
  1500. if (lastIndex !== index) {
  1501. html += str.substring(lastIndex, index);
  1502. }
  1503. lastIndex = index + 1;
  1504. html += escape;
  1505. }
  1506. return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
  1507. } // end code copied and modified from escape-html
  1508. /**
  1509. * Escapes text to prevent scripting attacks.
  1510. *
  1511. * @param {*} text Text value to escape.
  1512. * @return {string} An escaped string.
  1513. */
  1514. function escapeTextForBrowser(text) {
  1515. if (typeof text === 'boolean' || typeof text === 'number') {
  1516. // this shortcircuit helps perf for types that we know will never have
  1517. // special characters, especially given that this function is used often
  1518. // for numeric dom ids.
  1519. return '' + text;
  1520. }
  1521. return escapeHtml(text);
  1522. }
  1523. var uppercasePattern = /([A-Z])/g;
  1524. var msPattern$1 = /^ms-/;
  1525. /**
  1526. * Hyphenates a camelcased CSS property name, for example:
  1527. *
  1528. * > hyphenateStyleName('backgroundColor')
  1529. * < "background-color"
  1530. * > hyphenateStyleName('MozTransition')
  1531. * < "-moz-transition"
  1532. * > hyphenateStyleName('msTransition')
  1533. * < "-ms-transition"
  1534. *
  1535. * As Modernizr suggests (http://modernizr.com/docs/#prefixed), an `ms` prefix
  1536. * is converted to `-ms-`.
  1537. */
  1538. function hyphenateStyleName(name) {
  1539. return name.replace(uppercasePattern, '-$1').toLowerCase().replace(msPattern$1, '-ms-');
  1540. }
  1541. // and any newline or tab are filtered out as if they're not part of the URL.
  1542. // https://url.spec.whatwg.org/#url-parsing
  1543. // Tab or newline are defined as \r\n\t:
  1544. // https://infra.spec.whatwg.org/#ascii-tab-or-newline
  1545. // A C0 control is a code point in the range \u0000 NULL to \u001F
  1546. // INFORMATION SEPARATOR ONE, inclusive:
  1547. // https://infra.spec.whatwg.org/#c0-control-or-space
  1548. /* eslint-disable max-len */
  1549. 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;
  1550. var didWarn = false;
  1551. function sanitizeURL(url) {
  1552. {
  1553. if (!didWarn && isJavaScriptProtocol.test(url)) {
  1554. didWarn = true;
  1555. 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));
  1556. }
  1557. }
  1558. }
  1559. var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
  1560. function isArray(a) {
  1561. return isArrayImpl(a);
  1562. }
  1563. var startInlineScript = stringToPrecomputedChunk('<script>');
  1564. var endInlineScript = stringToPrecomputedChunk('</script>');
  1565. var startScriptSrc = stringToPrecomputedChunk('<script src="');
  1566. var startModuleSrc = stringToPrecomputedChunk('<script type="module" src="');
  1567. var endAsyncScript = stringToPrecomputedChunk('" async=""></script>');
  1568. /**
  1569. * This escaping function is designed to work with bootstrapScriptContent only.
  1570. * because we know we are escaping the entire script. We can avoid for instance
  1571. * escaping html comment string sequences that are valid javascript as well because
  1572. * if there are no sebsequent <script sequences the html parser will never enter
  1573. * script data double escaped state (see: https://www.w3.org/TR/html53/syntax.html#script-data-double-escaped-state)
  1574. *
  1575. * While untrusted script content should be made safe before using this api it will
  1576. * ensure that the script cannot be early terminated or never terminated state
  1577. */
  1578. function escapeBootstrapScriptContent(scriptText) {
  1579. {
  1580. checkHtmlStringCoercion(scriptText);
  1581. }
  1582. return ('' + scriptText).replace(scriptRegex, scriptReplacer);
  1583. }
  1584. var scriptRegex = /(<\/|<)(s)(cript)/gi;
  1585. var scriptReplacer = function (match, prefix, s, suffix) {
  1586. return "" + prefix + (s === 's' ? "\\u0073" : "\\u0053") + suffix;
  1587. }; // Allows us to keep track of what we've already written so we can refer back to it.
  1588. function createResponseState(identifierPrefix, nonce, bootstrapScriptContent, bootstrapScripts, bootstrapModules) {
  1589. var idPrefix = identifierPrefix === undefined ? '' : identifierPrefix;
  1590. var inlineScriptWithNonce = nonce === undefined ? startInlineScript : stringToPrecomputedChunk('<script nonce="' + escapeTextForBrowser(nonce) + '">');
  1591. var bootstrapChunks = [];
  1592. if (bootstrapScriptContent !== undefined) {
  1593. bootstrapChunks.push(inlineScriptWithNonce, stringToChunk(escapeBootstrapScriptContent(bootstrapScriptContent)), endInlineScript);
  1594. }
  1595. if (bootstrapScripts !== undefined) {
  1596. for (var i = 0; i < bootstrapScripts.length; i++) {
  1597. bootstrapChunks.push(startScriptSrc, stringToChunk(escapeTextForBrowser(bootstrapScripts[i])), endAsyncScript);
  1598. }
  1599. }
  1600. if (bootstrapModules !== undefined) {
  1601. for (var _i = 0; _i < bootstrapModules.length; _i++) {
  1602. bootstrapChunks.push(startModuleSrc, stringToChunk(escapeTextForBrowser(bootstrapModules[_i])), endAsyncScript);
  1603. }
  1604. }
  1605. return {
  1606. bootstrapChunks: bootstrapChunks,
  1607. startInlineScript: inlineScriptWithNonce,
  1608. placeholderPrefix: stringToPrecomputedChunk(idPrefix + 'P:'),
  1609. segmentPrefix: stringToPrecomputedChunk(idPrefix + 'S:'),
  1610. boundaryPrefix: idPrefix + 'B:',
  1611. idPrefix: idPrefix,
  1612. nextSuspenseID: 0,
  1613. sentCompleteSegmentFunction: false,
  1614. sentCompleteBoundaryFunction: false,
  1615. sentClientRenderFunction: false
  1616. };
  1617. } // Constants for the insertion mode we're currently writing in. We don't encode all HTML5 insertion
  1618. // modes. We only include the variants as they matter for the sake of our purposes.
  1619. // We don't actually provide the namespace therefore we use constants instead of the string.
  1620. var ROOT_HTML_MODE = 0; // Used for the root most element tag.
  1621. var HTML_MODE = 1;
  1622. var SVG_MODE = 2;
  1623. var MATHML_MODE = 3;
  1624. var HTML_TABLE_MODE = 4;
  1625. var HTML_TABLE_BODY_MODE = 5;
  1626. var HTML_TABLE_ROW_MODE = 6;
  1627. var HTML_COLGROUP_MODE = 7; // We have a greater than HTML_TABLE_MODE check elsewhere. If you add more cases here, make sure it
  1628. // still makes sense
  1629. function createFormatContext(insertionMode, selectedValue) {
  1630. return {
  1631. insertionMode: insertionMode,
  1632. selectedValue: selectedValue
  1633. };
  1634. }
  1635. function createRootFormatContext(namespaceURI) {
  1636. var insertionMode = namespaceURI === 'http://www.w3.org/2000/svg' ? SVG_MODE : namespaceURI === 'http://www.w3.org/1998/Math/MathML' ? MATHML_MODE : ROOT_HTML_MODE;
  1637. return createFormatContext(insertionMode, null);
  1638. }
  1639. function getChildFormatContext(parentContext, type, props) {
  1640. switch (type) {
  1641. case 'select':
  1642. return createFormatContext(HTML_MODE, props.value != null ? props.value : props.defaultValue);
  1643. case 'svg':
  1644. return createFormatContext(SVG_MODE, null);
  1645. case 'math':
  1646. return createFormatContext(MATHML_MODE, null);
  1647. case 'foreignObject':
  1648. return createFormatContext(HTML_MODE, null);
  1649. // Table parents are special in that their children can only be created at all if they're
  1650. // wrapped in a table parent. So we need to encode that we're entering this mode.
  1651. case 'table':
  1652. return createFormatContext(HTML_TABLE_MODE, null);
  1653. case 'thead':
  1654. case 'tbody':
  1655. case 'tfoot':
  1656. return createFormatContext(HTML_TABLE_BODY_MODE, null);
  1657. case 'colgroup':
  1658. return createFormatContext(HTML_COLGROUP_MODE, null);
  1659. case 'tr':
  1660. return createFormatContext(HTML_TABLE_ROW_MODE, null);
  1661. }
  1662. if (parentContext.insertionMode >= HTML_TABLE_MODE) {
  1663. // Whatever tag this was, it wasn't a table parent or other special parent, so we must have
  1664. // entered plain HTML again.
  1665. return createFormatContext(HTML_MODE, null);
  1666. }
  1667. if (parentContext.insertionMode === ROOT_HTML_MODE) {
  1668. // We've emitted the root and is now in plain HTML mode.
  1669. return createFormatContext(HTML_MODE, null);
  1670. }
  1671. return parentContext;
  1672. }
  1673. var UNINITIALIZED_SUSPENSE_BOUNDARY_ID = null;
  1674. function assignSuspenseBoundaryID(responseState) {
  1675. var generatedID = responseState.nextSuspenseID++;
  1676. return stringToPrecomputedChunk(responseState.boundaryPrefix + generatedID.toString(16));
  1677. }
  1678. function makeId(responseState, treeId, localId) {
  1679. var idPrefix = responseState.idPrefix;
  1680. var id = ':' + idPrefix + 'R' + treeId; // Unless this is the first id at this level, append a number at the end
  1681. // that represents the position of this useId hook among all the useId
  1682. // hooks for this fiber.
  1683. if (localId > 0) {
  1684. id += 'H' + localId.toString(32);
  1685. }
  1686. return id + ':';
  1687. }
  1688. function encodeHTMLTextNode(text) {
  1689. return escapeTextForBrowser(text);
  1690. }
  1691. var textSeparator = stringToPrecomputedChunk('<!-- -->');
  1692. function pushTextInstance(target, text, responseState, textEmbedded) {
  1693. if (text === '') {
  1694. // Empty text doesn't have a DOM node representation and the hydration is aware of this.
  1695. return textEmbedded;
  1696. }
  1697. if (textEmbedded) {
  1698. target.push(textSeparator);
  1699. }
  1700. target.push(stringToChunk(encodeHTMLTextNode(text)));
  1701. return true;
  1702. } // Called when Fizz is done with a Segment. Currently the only purpose is to conditionally
  1703. // emit a text separator when we don't know for sure it is safe to omit
  1704. function pushSegmentFinale(target, responseState, lastPushedText, textEmbedded) {
  1705. if (lastPushedText && textEmbedded) {
  1706. target.push(textSeparator);
  1707. }
  1708. }
  1709. var styleNameCache = new Map();
  1710. function processStyleName(styleName) {
  1711. var chunk = styleNameCache.get(styleName);
  1712. if (chunk !== undefined) {
  1713. return chunk;
  1714. }
  1715. var result = stringToPrecomputedChunk(escapeTextForBrowser(hyphenateStyleName(styleName)));
  1716. styleNameCache.set(styleName, result);
  1717. return result;
  1718. }
  1719. var styleAttributeStart = stringToPrecomputedChunk(' style="');
  1720. var styleAssign = stringToPrecomputedChunk(':');
  1721. var styleSeparator = stringToPrecomputedChunk(';');
  1722. function pushStyle(target, responseState, style) {
  1723. if (typeof style !== 'object') {
  1724. throw new Error('The `style` prop expects a mapping from style properties to values, ' + "not a string. For example, style={{marginRight: spacing + 'em'}} when " + 'using JSX.');
  1725. }
  1726. var isFirst = true;
  1727. for (var styleName in style) {
  1728. if (!hasOwnProperty.call(style, styleName)) {
  1729. continue;
  1730. } // If you provide unsafe user data here they can inject arbitrary CSS
  1731. // which may be problematic (I couldn't repro this):
  1732. // https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
  1733. // http://www.thespanner.co.uk/2007/11/26/ultimate-xss-css-injection/
  1734. // This is not an XSS hole but instead a potential CSS injection issue
  1735. // which has lead to a greater discussion about how we're going to
  1736. // trust URLs moving forward. See #2115901
  1737. var styleValue = style[styleName];
  1738. if (styleValue == null || typeof styleValue === 'boolean' || styleValue === '') {
  1739. // TODO: We used to set empty string as a style with an empty value. Does that ever make sense?
  1740. continue;
  1741. }
  1742. var nameChunk = void 0;
  1743. var valueChunk = void 0;
  1744. var isCustomProperty = styleName.indexOf('--') === 0;
  1745. if (isCustomProperty) {
  1746. nameChunk = stringToChunk(escapeTextForBrowser(styleName));
  1747. {
  1748. checkCSSPropertyStringCoercion(styleValue, styleName);
  1749. }
  1750. valueChunk = stringToChunk(escapeTextForBrowser(('' + styleValue).trim()));
  1751. } else {
  1752. {
  1753. warnValidStyle$1(styleName, styleValue);
  1754. }
  1755. nameChunk = processStyleName(styleName);
  1756. if (typeof styleValue === 'number') {
  1757. if (styleValue !== 0 && !hasOwnProperty.call(isUnitlessNumber, styleName)) {
  1758. valueChunk = stringToChunk(styleValue + 'px'); // Presumes implicit 'px' suffix for unitless numbers
  1759. } else {
  1760. valueChunk = stringToChunk('' + styleValue);
  1761. }
  1762. } else {
  1763. {
  1764. checkCSSPropertyStringCoercion(styleValue, styleName);
  1765. }
  1766. valueChunk = stringToChunk(escapeTextForBrowser(('' + styleValue).trim()));
  1767. }
  1768. }
  1769. if (isFirst) {
  1770. isFirst = false; // If it's first, we don't need any separators prefixed.
  1771. target.push(styleAttributeStart, nameChunk, styleAssign, valueChunk);
  1772. } else {
  1773. target.push(styleSeparator, nameChunk, styleAssign, valueChunk);
  1774. }
  1775. }
  1776. if (!isFirst) {
  1777. target.push(attributeEnd);
  1778. }
  1779. }
  1780. var attributeSeparator = stringToPrecomputedChunk(' ');
  1781. var attributeAssign = stringToPrecomputedChunk('="');
  1782. var attributeEnd = stringToPrecomputedChunk('"');
  1783. var attributeEmptyString = stringToPrecomputedChunk('=""');
  1784. function pushAttribute(target, responseState, name, value) {
  1785. switch (name) {
  1786. case 'style':
  1787. {
  1788. pushStyle(target, responseState, value);
  1789. return;
  1790. }
  1791. case 'defaultValue':
  1792. case 'defaultChecked': // These shouldn't be set as attributes on generic HTML elements.
  1793. case 'innerHTML': // Must use dangerouslySetInnerHTML instead.
  1794. case 'suppressContentEditableWarning':
  1795. case 'suppressHydrationWarning':
  1796. // Ignored. These are built-in to React on the client.
  1797. return;
  1798. }
  1799. if ( // shouldIgnoreAttribute
  1800. // We have already filtered out null/undefined and reserved words.
  1801. name.length > 2 && (name[0] === 'o' || name[0] === 'O') && (name[1] === 'n' || name[1] === 'N')) {
  1802. return;
  1803. }
  1804. var propertyInfo = getPropertyInfo(name);
  1805. if (propertyInfo !== null) {
  1806. // shouldRemoveAttribute
  1807. switch (typeof value) {
  1808. case 'function': // $FlowIssue symbol is perfectly valid here
  1809. case 'symbol':
  1810. // eslint-disable-line
  1811. return;
  1812. case 'boolean':
  1813. {
  1814. if (!propertyInfo.acceptsBooleans) {
  1815. return;
  1816. }
  1817. }
  1818. }
  1819. var attributeName = propertyInfo.attributeName;
  1820. var attributeNameChunk = stringToChunk(attributeName); // TODO: If it's known we can cache the chunk.
  1821. switch (propertyInfo.type) {
  1822. case BOOLEAN:
  1823. if (value) {
  1824. target.push(attributeSeparator, attributeNameChunk, attributeEmptyString);
  1825. }
  1826. return;
  1827. case OVERLOADED_BOOLEAN:
  1828. if (value === true) {
  1829. target.push(attributeSeparator, attributeNameChunk, attributeEmptyString);
  1830. } else if (value === false) ; else {
  1831. target.push(attributeSeparator, attributeNameChunk, attributeAssign, stringToChunk(escapeTextForBrowser(value)), attributeEnd);
  1832. }
  1833. return;
  1834. case NUMERIC:
  1835. if (!isNaN(value)) {
  1836. target.push(attributeSeparator, attributeNameChunk, attributeAssign, stringToChunk(escapeTextForBrowser(value)), attributeEnd);
  1837. }
  1838. break;
  1839. case POSITIVE_NUMERIC:
  1840. if (!isNaN(value) && value >= 1) {
  1841. target.push(attributeSeparator, attributeNameChunk, attributeAssign, stringToChunk(escapeTextForBrowser(value)), attributeEnd);
  1842. }
  1843. break;
  1844. default:
  1845. if (propertyInfo.sanitizeURL) {
  1846. {
  1847. checkAttributeStringCoercion(value, attributeName);
  1848. }
  1849. value = '' + value;
  1850. sanitizeURL(value);
  1851. }
  1852. target.push(attributeSeparator, attributeNameChunk, attributeAssign, stringToChunk(escapeTextForBrowser(value)), attributeEnd);
  1853. }
  1854. } else if (isAttributeNameSafe(name)) {
  1855. // shouldRemoveAttribute
  1856. switch (typeof value) {
  1857. case 'function': // $FlowIssue symbol is perfectly valid here
  1858. case 'symbol':
  1859. // eslint-disable-line
  1860. return;
  1861. case 'boolean':
  1862. {
  1863. var prefix = name.toLowerCase().slice(0, 5);
  1864. if (prefix !== 'data-' && prefix !== 'aria-') {
  1865. return;
  1866. }
  1867. }
  1868. }
  1869. target.push(attributeSeparator, stringToChunk(name), attributeAssign, stringToChunk(escapeTextForBrowser(value)), attributeEnd);
  1870. }
  1871. }
  1872. var endOfStartTag = stringToPrecomputedChunk('>');
  1873. var endOfStartTagSelfClosing = stringToPrecomputedChunk('/>');
  1874. function pushInnerHTML(target, innerHTML, children) {
  1875. if (innerHTML != null) {
  1876. if (children != null) {
  1877. throw new Error('Can only set one of `children` or `props.dangerouslySetInnerHTML`.');
  1878. }
  1879. if (typeof innerHTML !== 'object' || !('__html' in innerHTML)) {
  1880. throw new Error('`props.dangerouslySetInnerHTML` must be in the form `{__html: ...}`. ' + 'Please visit https://reactjs.org/link/dangerously-set-inner-html ' + 'for more information.');
  1881. }
  1882. var html = innerHTML.__html;
  1883. if (html !== null && html !== undefined) {
  1884. {
  1885. checkHtmlStringCoercion(html);
  1886. }
  1887. target.push(stringToChunk('' + html));
  1888. }
  1889. }
  1890. } // TODO: Move these to ResponseState so that we warn for every request.
  1891. // It would help debugging in stateful servers (e.g. service worker).
  1892. var didWarnDefaultInputValue = false;
  1893. var didWarnDefaultChecked = false;
  1894. var didWarnDefaultSelectValue = false;
  1895. var didWarnDefaultTextareaValue = false;
  1896. var didWarnInvalidOptionChildren = false;
  1897. var didWarnInvalidOptionInnerHTML = false;
  1898. var didWarnSelectedSetOnOption = false;
  1899. function checkSelectProp(props, propName) {
  1900. {
  1901. var value = props[propName];
  1902. if (value != null) {
  1903. var array = isArray(value);
  1904. if (props.multiple && !array) {
  1905. error('The `%s` prop supplied to <select> must be an array if ' + '`multiple` is true.', propName);
  1906. } else if (!props.multiple && array) {
  1907. error('The `%s` prop supplied to <select> must be a scalar ' + 'value if `multiple` is false.', propName);
  1908. }
  1909. }
  1910. }
  1911. }
  1912. function pushStartSelect(target, props, responseState) {
  1913. {
  1914. checkControlledValueProps('select', props);
  1915. checkSelectProp(props, 'value');
  1916. checkSelectProp(props, 'defaultValue');
  1917. if (props.value !== undefined && props.defaultValue !== undefined && !didWarnDefaultSelectValue) {
  1918. 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');
  1919. didWarnDefaultSelectValue = true;
  1920. }
  1921. }
  1922. target.push(startChunkForTag('select'));
  1923. var children = null;
  1924. var innerHTML = null;
  1925. for (var propKey in props) {
  1926. if (hasOwnProperty.call(props, propKey)) {
  1927. var propValue = props[propKey];
  1928. if (propValue == null) {
  1929. continue;
  1930. }
  1931. switch (propKey) {
  1932. case 'children':
  1933. children = propValue;
  1934. break;
  1935. case 'dangerouslySetInnerHTML':
  1936. // TODO: This doesn't really make sense for select since it can't use the controlled
  1937. // value in the innerHTML.
  1938. innerHTML = propValue;
  1939. break;
  1940. case 'defaultValue':
  1941. case 'value':
  1942. // These are set on the Context instead and applied to the nested options.
  1943. break;
  1944. default:
  1945. pushAttribute(target, responseState, propKey, propValue);
  1946. break;
  1947. }
  1948. }
  1949. }
  1950. target.push(endOfStartTag);
  1951. pushInnerHTML(target, innerHTML, children);
  1952. return children;
  1953. }
  1954. function flattenOptionChildren(children) {
  1955. var content = ''; // Flatten children and warn if they aren't strings or numbers;
  1956. // invalid types are ignored.
  1957. React.Children.forEach(children, function (child) {
  1958. if (child == null) {
  1959. return;
  1960. }
  1961. content += child;
  1962. {
  1963. if (!didWarnInvalidOptionChildren && typeof child !== 'string' && typeof child !== 'number') {
  1964. didWarnInvalidOptionChildren = true;
  1965. error('Cannot infer the option value of complex children. ' + 'Pass a `value` prop or use a plain string as children to <option>.');
  1966. }
  1967. }
  1968. });
  1969. return content;
  1970. }
  1971. var selectedMarkerAttribute = stringToPrecomputedChunk(' selected=""');
  1972. function pushStartOption(target, props, responseState, formatContext) {
  1973. var selectedValue = formatContext.selectedValue;
  1974. target.push(startChunkForTag('option'));
  1975. var children = null;
  1976. var value = null;
  1977. var selected = null;
  1978. var innerHTML = null;
  1979. for (var propKey in props) {
  1980. if (hasOwnProperty.call(props, propKey)) {
  1981. var propValue = props[propKey];
  1982. if (propValue == null) {
  1983. continue;
  1984. }
  1985. switch (propKey) {
  1986. case 'children':
  1987. children = propValue;
  1988. break;
  1989. case 'selected':
  1990. // ignore
  1991. selected = propValue;
  1992. {
  1993. // TODO: Remove support for `selected` in <option>.
  1994. if (!didWarnSelectedSetOnOption) {
  1995. error('Use the `defaultValue` or `value` props on <select> instead of ' + 'setting `selected` on <option>.');
  1996. didWarnSelectedSetOnOption = true;
  1997. }
  1998. }
  1999. break;
  2000. case 'dangerouslySetInnerHTML':
  2001. innerHTML = propValue;
  2002. break;
  2003. // eslint-disable-next-line-no-fallthrough
  2004. case 'value':
  2005. value = propValue;
  2006. // We intentionally fallthrough to also set the attribute on the node.
  2007. // eslint-disable-next-line-no-fallthrough
  2008. default:
  2009. pushAttribute(target, responseState, propKey, propValue);
  2010. break;
  2011. }
  2012. }
  2013. }
  2014. if (selectedValue != null) {
  2015. var stringValue;
  2016. if (value !== null) {
  2017. {
  2018. checkAttributeStringCoercion(value, 'value');
  2019. }
  2020. stringValue = '' + value;
  2021. } else {
  2022. {
  2023. if (innerHTML !== null) {
  2024. if (!didWarnInvalidOptionInnerHTML) {
  2025. didWarnInvalidOptionInnerHTML = true;
  2026. error('Pass a `value` prop if you set dangerouslyInnerHTML so React knows ' + 'which value should be selected.');
  2027. }
  2028. }
  2029. }
  2030. stringValue = flattenOptionChildren(children);
  2031. }
  2032. if (isArray(selectedValue)) {
  2033. // multiple
  2034. for (var i = 0; i < selectedValue.length; i++) {
  2035. {
  2036. checkAttributeStringCoercion(selectedValue[i], 'value');
  2037. }
  2038. var v = '' + selectedValue[i];
  2039. if (v === stringValue) {
  2040. target.push(selectedMarkerAttribute);
  2041. break;
  2042. }
  2043. }
  2044. } else {
  2045. {
  2046. checkAttributeStringCoercion(selectedValue, 'select.value');
  2047. }
  2048. if ('' + selectedValue === stringValue) {
  2049. target.push(selectedMarkerAttribute);
  2050. }
  2051. }
  2052. } else if (selected) {
  2053. target.push(selectedMarkerAttribute);
  2054. }
  2055. target.push(endOfStartTag);
  2056. pushInnerHTML(target, innerHTML, children);
  2057. return children;
  2058. }
  2059. function pushInput(target, props, responseState) {
  2060. {
  2061. checkControlledValueProps('input', props);
  2062. if (props.checked !== undefined && props.defaultChecked !== undefined && !didWarnDefaultChecked) {
  2063. 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', 'A component', props.type);
  2064. didWarnDefaultChecked = true;
  2065. }
  2066. if (props.value !== undefined && props.defaultValue !== undefined && !didWarnDefaultInputValue) {
  2067. 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', 'A component', props.type);
  2068. didWarnDefaultInputValue = true;
  2069. }
  2070. }
  2071. target.push(startChunkForTag('input'));
  2072. var value = null;
  2073. var defaultValue = null;
  2074. var checked = null;
  2075. var defaultChecked = null;
  2076. for (var propKey in props) {
  2077. if (hasOwnProperty.call(props, propKey)) {
  2078. var propValue = props[propKey];
  2079. if (propValue == null) {
  2080. continue;
  2081. }
  2082. switch (propKey) {
  2083. case 'children':
  2084. case 'dangerouslySetInnerHTML':
  2085. throw new Error('input' + " is a self-closing tag and must neither have `children` nor " + 'use `dangerouslySetInnerHTML`.');
  2086. // eslint-disable-next-line-no-fallthrough
  2087. case 'defaultChecked':
  2088. defaultChecked = propValue;
  2089. break;
  2090. case 'defaultValue':
  2091. defaultValue = propValue;
  2092. break;
  2093. case 'checked':
  2094. checked = propValue;
  2095. break;
  2096. case 'value':
  2097. value = propValue;
  2098. break;
  2099. default:
  2100. pushAttribute(target, responseState, propKey, propValue);
  2101. break;
  2102. }
  2103. }
  2104. }
  2105. if (checked !== null) {
  2106. pushAttribute(target, responseState, 'checked', checked);
  2107. } else if (defaultChecked !== null) {
  2108. pushAttribute(target, responseState, 'checked', defaultChecked);
  2109. }
  2110. if (value !== null) {
  2111. pushAttribute(target, responseState, 'value', value);
  2112. } else if (defaultValue !== null) {
  2113. pushAttribute(target, responseState, 'value', defaultValue);
  2114. }
  2115. target.push(endOfStartTagSelfClosing);
  2116. return null;
  2117. }
  2118. function pushStartTextArea(target, props, responseState) {
  2119. {
  2120. checkControlledValueProps('textarea', props);
  2121. if (props.value !== undefined && props.defaultValue !== undefined && !didWarnDefaultTextareaValue) {
  2122. error('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');
  2123. didWarnDefaultTextareaValue = true;
  2124. }
  2125. }
  2126. target.push(startChunkForTag('textarea'));
  2127. var value = null;
  2128. var defaultValue = null;
  2129. var children = null;
  2130. for (var propKey in props) {
  2131. if (hasOwnProperty.call(props, propKey)) {
  2132. var propValue = props[propKey];
  2133. if (propValue == null) {
  2134. continue;
  2135. }
  2136. switch (propKey) {
  2137. case 'children':
  2138. children = propValue;
  2139. break;
  2140. case 'value':
  2141. value = propValue;
  2142. break;
  2143. case 'defaultValue':
  2144. defaultValue = propValue;
  2145. break;
  2146. case 'dangerouslySetInnerHTML':
  2147. throw new Error('`dangerouslySetInnerHTML` does not make sense on <textarea>.');
  2148. // eslint-disable-next-line-no-fallthrough
  2149. default:
  2150. pushAttribute(target, responseState, propKey, propValue);
  2151. break;
  2152. }
  2153. }
  2154. }
  2155. if (value === null && defaultValue !== null) {
  2156. value = defaultValue;
  2157. }
  2158. target.push(endOfStartTag); // TODO (yungsters): Remove support for children content in <textarea>.
  2159. if (children != null) {
  2160. {
  2161. error('Use the `defaultValue` or `value` props instead of setting ' + 'children on <textarea>.');
  2162. }
  2163. if (value != null) {
  2164. throw new Error('If you supply `defaultValue` on a <textarea>, do not pass children.');
  2165. }
  2166. if (isArray(children)) {
  2167. if (children.length > 1) {
  2168. throw new Error('<textarea> can only have at most one child.');
  2169. } // TODO: remove the coercion and the DEV check below because it will
  2170. // always be overwritten by the coercion several lines below it. #22309
  2171. {
  2172. checkHtmlStringCoercion(children[0]);
  2173. }
  2174. value = '' + children[0];
  2175. }
  2176. {
  2177. checkHtmlStringCoercion(children);
  2178. }
  2179. value = '' + children;
  2180. }
  2181. if (typeof value === 'string' && value[0] === '\n') {
  2182. // text/html ignores the first character in these tags if it's a newline
  2183. // Prefer to break application/xml over text/html (for now) by adding
  2184. // a newline specifically to get eaten by the parser. (Alternately for
  2185. // textareas, replacing "^\n" with "\r\n" doesn't get eaten, and the first
  2186. // \r is normalized out by HTMLTextAreaElement#value.)
  2187. // See: <http://www.w3.org/TR/html-polyglot/#newlines-in-textarea-and-pre>
  2188. // See: <http://www.w3.org/TR/html5/syntax.html#element-restrictions>
  2189. // See: <http://www.w3.org/TR/html5/syntax.html#newlines>
  2190. // See: Parsing of "textarea" "listing" and "pre" elements
  2191. // from <http://www.w3.org/TR/html5/syntax.html#parsing-main-inbody>
  2192. target.push(leadingNewline);
  2193. } // ToString and push directly instead of recurse over children.
  2194. // We don't really support complex children in the value anyway.
  2195. // This also currently avoids a trailing comment node which breaks textarea.
  2196. if (value !== null) {
  2197. {
  2198. checkAttributeStringCoercion(value, 'value');
  2199. }
  2200. target.push(stringToChunk(encodeHTMLTextNode('' + value)));
  2201. }
  2202. return null;
  2203. }
  2204. function pushSelfClosing(target, props, tag, responseState) {
  2205. target.push(startChunkForTag(tag));
  2206. for (var propKey in props) {
  2207. if (hasOwnProperty.call(props, propKey)) {
  2208. var propValue = props[propKey];
  2209. if (propValue == null) {
  2210. continue;
  2211. }
  2212. switch (propKey) {
  2213. case 'children':
  2214. case 'dangerouslySetInnerHTML':
  2215. throw new Error(tag + " is a self-closing tag and must neither have `children` nor " + 'use `dangerouslySetInnerHTML`.');
  2216. // eslint-disable-next-line-no-fallthrough
  2217. default:
  2218. pushAttribute(target, responseState, propKey, propValue);
  2219. break;
  2220. }
  2221. }
  2222. }
  2223. target.push(endOfStartTagSelfClosing);
  2224. return null;
  2225. }
  2226. function pushStartMenuItem(target, props, responseState) {
  2227. target.push(startChunkForTag('menuitem'));
  2228. for (var propKey in props) {
  2229. if (hasOwnProperty.call(props, propKey)) {
  2230. var propValue = props[propKey];
  2231. if (propValue == null) {
  2232. continue;
  2233. }
  2234. switch (propKey) {
  2235. case 'children':
  2236. case 'dangerouslySetInnerHTML':
  2237. throw new Error('menuitems cannot have `children` nor `dangerouslySetInnerHTML`.');
  2238. // eslint-disable-next-line-no-fallthrough
  2239. default:
  2240. pushAttribute(target, responseState, propKey, propValue);
  2241. break;
  2242. }
  2243. }
  2244. }
  2245. target.push(endOfStartTag);
  2246. return null;
  2247. }
  2248. function pushStartTitle(target, props, responseState) {
  2249. target.push(startChunkForTag('title'));
  2250. var children = null;
  2251. for (var propKey in props) {
  2252. if (hasOwnProperty.call(props, propKey)) {
  2253. var propValue = props[propKey];
  2254. if (propValue == null) {
  2255. continue;
  2256. }
  2257. switch (propKey) {
  2258. case 'children':
  2259. children = propValue;
  2260. break;
  2261. case 'dangerouslySetInnerHTML':
  2262. throw new Error('`dangerouslySetInnerHTML` does not make sense on <title>.');
  2263. // eslint-disable-next-line-no-fallthrough
  2264. default:
  2265. pushAttribute(target, responseState, propKey, propValue);
  2266. break;
  2267. }
  2268. }
  2269. }
  2270. target.push(endOfStartTag);
  2271. {
  2272. var child = Array.isArray(children) && children.length < 2 ? children[0] || null : children;
  2273. if (Array.isArray(children) && children.length > 1) {
  2274. error('A title element received an array with more than 1 element as children. ' + 'In browsers title Elements can only have Text Nodes as children. If ' + 'the children being rendered output more than a single text node in aggregate the browser ' + 'will display markup and comments as text in the title and hydration will likely fail and ' + 'fall back to client rendering');
  2275. } else if (child != null && child.$$typeof != null) {
  2276. error('A title element received a React element for children. ' + 'In the browser title Elements can only have Text Nodes as children. If ' + 'the children being rendered output more than a single text node in aggregate the browser ' + 'will display markup and comments as text in the title and hydration will likely fail and ' + 'fall back to client rendering');
  2277. } else if (child != null && typeof child !== 'string' && typeof child !== 'number') {
  2278. error('A title element received a value that was not a string or number for children. ' + 'In the browser title Elements can only have Text Nodes as children. If ' + 'the children being rendered output more than a single text node in aggregate the browser ' + 'will display markup and comments as text in the title and hydration will likely fail and ' + 'fall back to client rendering');
  2279. }
  2280. }
  2281. return children;
  2282. }
  2283. function pushStartGenericElement(target, props, tag, responseState) {
  2284. target.push(startChunkForTag(tag));
  2285. var children = null;
  2286. var innerHTML = null;
  2287. for (var propKey in props) {
  2288. if (hasOwnProperty.call(props, propKey)) {
  2289. var propValue = props[propKey];
  2290. if (propValue == null) {
  2291. continue;
  2292. }
  2293. switch (propKey) {
  2294. case 'children':
  2295. children = propValue;
  2296. break;
  2297. case 'dangerouslySetInnerHTML':
  2298. innerHTML = propValue;
  2299. break;
  2300. default:
  2301. pushAttribute(target, responseState, propKey, propValue);
  2302. break;
  2303. }
  2304. }
  2305. }
  2306. target.push(endOfStartTag);
  2307. pushInnerHTML(target, innerHTML, children);
  2308. if (typeof children === 'string') {
  2309. // Special case children as a string to avoid the unnecessary comment.
  2310. // TODO: Remove this special case after the general optimization is in place.
  2311. target.push(stringToChunk(encodeHTMLTextNode(children)));
  2312. return null;
  2313. }
  2314. return children;
  2315. }
  2316. function pushStartCustomElement(target, props, tag, responseState) {
  2317. target.push(startChunkForTag(tag));
  2318. var children = null;
  2319. var innerHTML = null;
  2320. for (var propKey in props) {
  2321. if (hasOwnProperty.call(props, propKey)) {
  2322. var propValue = props[propKey];
  2323. if (propValue == null) {
  2324. continue;
  2325. }
  2326. switch (propKey) {
  2327. case 'children':
  2328. children = propValue;
  2329. break;
  2330. case 'dangerouslySetInnerHTML':
  2331. innerHTML = propValue;
  2332. break;
  2333. case 'style':
  2334. pushStyle(target, responseState, propValue);
  2335. break;
  2336. case 'suppressContentEditableWarning':
  2337. case 'suppressHydrationWarning':
  2338. // Ignored. These are built-in to React on the client.
  2339. break;
  2340. default:
  2341. if (isAttributeNameSafe(propKey) && typeof propValue !== 'function' && typeof propValue !== 'symbol') {
  2342. target.push(attributeSeparator, stringToChunk(propKey), attributeAssign, stringToChunk(escapeTextForBrowser(propValue)), attributeEnd);
  2343. }
  2344. break;
  2345. }
  2346. }
  2347. }
  2348. target.push(endOfStartTag);
  2349. pushInnerHTML(target, innerHTML, children);
  2350. return children;
  2351. }
  2352. var leadingNewline = stringToPrecomputedChunk('\n');
  2353. function pushStartPreformattedElement(target, props, tag, responseState) {
  2354. target.push(startChunkForTag(tag));
  2355. var children = null;
  2356. var innerHTML = null;
  2357. for (var propKey in props) {
  2358. if (hasOwnProperty.call(props, propKey)) {
  2359. var propValue = props[propKey];
  2360. if (propValue == null) {
  2361. continue;
  2362. }
  2363. switch (propKey) {
  2364. case 'children':
  2365. children = propValue;
  2366. break;
  2367. case 'dangerouslySetInnerHTML':
  2368. innerHTML = propValue;
  2369. break;
  2370. default:
  2371. pushAttribute(target, responseState, propKey, propValue);
  2372. break;
  2373. }
  2374. }
  2375. }
  2376. target.push(endOfStartTag); // text/html ignores the first character in these tags if it's a newline
  2377. // Prefer to break application/xml over text/html (for now) by adding
  2378. // a newline specifically to get eaten by the parser. (Alternately for
  2379. // textareas, replacing "^\n" with "\r\n" doesn't get eaten, and the first
  2380. // \r is normalized out by HTMLTextAreaElement#value.)
  2381. // See: <http://www.w3.org/TR/html-polyglot/#newlines-in-textarea-and-pre>
  2382. // See: <http://www.w3.org/TR/html5/syntax.html#element-restrictions>
  2383. // See: <http://www.w3.org/TR/html5/syntax.html#newlines>
  2384. // See: Parsing of "textarea" "listing" and "pre" elements
  2385. // from <http://www.w3.org/TR/html5/syntax.html#parsing-main-inbody>
  2386. // TODO: This doesn't deal with the case where the child is an array
  2387. // or component that returns a string.
  2388. if (innerHTML != null) {
  2389. if (children != null) {
  2390. throw new Error('Can only set one of `children` or `props.dangerouslySetInnerHTML`.');
  2391. }
  2392. if (typeof innerHTML !== 'object' || !('__html' in innerHTML)) {
  2393. throw new Error('`props.dangerouslySetInnerHTML` must be in the form `{__html: ...}`. ' + 'Please visit https://reactjs.org/link/dangerously-set-inner-html ' + 'for more information.');
  2394. }
  2395. var html = innerHTML.__html;
  2396. if (html !== null && html !== undefined) {
  2397. if (typeof html === 'string' && html.length > 0 && html[0] === '\n') {
  2398. target.push(leadingNewline, stringToChunk(html));
  2399. } else {
  2400. {
  2401. checkHtmlStringCoercion(html);
  2402. }
  2403. target.push(stringToChunk('' + html));
  2404. }
  2405. }
  2406. }
  2407. if (typeof children === 'string' && children[0] === '\n') {
  2408. target.push(leadingNewline);
  2409. }
  2410. return children;
  2411. } // We accept any tag to be rendered but since this gets injected into arbitrary
  2412. // HTML, we want to make sure that it's a safe tag.
  2413. // http://www.w3.org/TR/REC-xml/#NT-Name
  2414. var VALID_TAG_REGEX = /^[a-zA-Z][a-zA-Z:_\.\-\d]*$/; // Simplified subset
  2415. var validatedTagCache = new Map();
  2416. function startChunkForTag(tag) {
  2417. var tagStartChunk = validatedTagCache.get(tag);
  2418. if (tagStartChunk === undefined) {
  2419. if (!VALID_TAG_REGEX.test(tag)) {
  2420. throw new Error("Invalid tag: " + tag);
  2421. }
  2422. tagStartChunk = stringToPrecomputedChunk('<' + tag);
  2423. validatedTagCache.set(tag, tagStartChunk);
  2424. }
  2425. return tagStartChunk;
  2426. }
  2427. var DOCTYPE = stringToPrecomputedChunk('<!DOCTYPE html>');
  2428. function pushStartInstance(target, type, props, responseState, formatContext) {
  2429. {
  2430. validateProperties(type, props);
  2431. validateProperties$1(type, props);
  2432. validateProperties$2(type, props, null);
  2433. if (!props.suppressContentEditableWarning && props.contentEditable && props.children != null) {
  2434. 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.');
  2435. }
  2436. if (formatContext.insertionMode !== SVG_MODE && formatContext.insertionMode !== MATHML_MODE) {
  2437. if (type.indexOf('-') === -1 && typeof props.is !== 'string' && type.toLowerCase() !== type) {
  2438. error('<%s /> is using incorrect casing. ' + 'Use PascalCase for React components, ' + 'or lowercase for HTML elements.', type);
  2439. }
  2440. }
  2441. }
  2442. switch (type) {
  2443. // Special tags
  2444. case 'select':
  2445. return pushStartSelect(target, props, responseState);
  2446. case 'option':
  2447. return pushStartOption(target, props, responseState, formatContext);
  2448. case 'textarea':
  2449. return pushStartTextArea(target, props, responseState);
  2450. case 'input':
  2451. return pushInput(target, props, responseState);
  2452. case 'menuitem':
  2453. return pushStartMenuItem(target, props, responseState);
  2454. case 'title':
  2455. return pushStartTitle(target, props, responseState);
  2456. // Newline eating tags
  2457. case 'listing':
  2458. case 'pre':
  2459. {
  2460. return pushStartPreformattedElement(target, props, type, responseState);
  2461. }
  2462. // Omitted close tags
  2463. case 'area':
  2464. case 'base':
  2465. case 'br':
  2466. case 'col':
  2467. case 'embed':
  2468. case 'hr':
  2469. case 'img':
  2470. case 'keygen':
  2471. case 'link':
  2472. case 'meta':
  2473. case 'param':
  2474. case 'source':
  2475. case 'track':
  2476. case 'wbr':
  2477. {
  2478. return pushSelfClosing(target, props, type, responseState);
  2479. }
  2480. // These are reserved SVG and MathML elements, that are never custom elements.
  2481. // https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
  2482. case 'annotation-xml':
  2483. case 'color-profile':
  2484. case 'font-face':
  2485. case 'font-face-src':
  2486. case 'font-face-uri':
  2487. case 'font-face-format':
  2488. case 'font-face-name':
  2489. case 'missing-glyph':
  2490. {
  2491. return pushStartGenericElement(target, props, type, responseState);
  2492. }
  2493. case 'html':
  2494. {
  2495. if (formatContext.insertionMode === ROOT_HTML_MODE) {
  2496. // If we're rendering the html tag and we're at the root (i.e. not in foreignObject)
  2497. // then we also emit the DOCTYPE as part of the root content as a convenience for
  2498. // rendering the whole document.
  2499. target.push(DOCTYPE);
  2500. }
  2501. return pushStartGenericElement(target, props, type, responseState);
  2502. }
  2503. default:
  2504. {
  2505. if (type.indexOf('-') === -1 && typeof props.is !== 'string') {
  2506. // Generic element
  2507. return pushStartGenericElement(target, props, type, responseState);
  2508. } else {
  2509. // Custom element
  2510. return pushStartCustomElement(target, props, type, responseState);
  2511. }
  2512. }
  2513. }
  2514. }
  2515. var endTag1 = stringToPrecomputedChunk('</');
  2516. var endTag2 = stringToPrecomputedChunk('>');
  2517. function pushEndInstance(target, type, props) {
  2518. switch (type) {
  2519. // Omitted close tags
  2520. // TODO: Instead of repeating this switch we could try to pass a flag from above.
  2521. // That would require returning a tuple. Which might be ok if it gets inlined.
  2522. case 'area':
  2523. case 'base':
  2524. case 'br':
  2525. case 'col':
  2526. case 'embed':
  2527. case 'hr':
  2528. case 'img':
  2529. case 'input':
  2530. case 'keygen':
  2531. case 'link':
  2532. case 'meta':
  2533. case 'param':
  2534. case 'source':
  2535. case 'track':
  2536. case 'wbr':
  2537. {
  2538. // No close tag needed.
  2539. break;
  2540. }
  2541. default:
  2542. {
  2543. target.push(endTag1, stringToChunk(type), endTag2);
  2544. }
  2545. }
  2546. }
  2547. function writeCompletedRoot(destination, responseState) {
  2548. var bootstrapChunks = responseState.bootstrapChunks;
  2549. var i = 0;
  2550. for (; i < bootstrapChunks.length - 1; i++) {
  2551. writeChunk(destination, bootstrapChunks[i]);
  2552. }
  2553. if (i < bootstrapChunks.length) {
  2554. return writeChunkAndReturn(destination, bootstrapChunks[i]);
  2555. }
  2556. return true;
  2557. } // Structural Nodes
  2558. // A placeholder is a node inside a hidden partial tree that can be filled in later, but before
  2559. // display. It's never visible to users. We use the template tag because it can be used in every
  2560. // type of parent. <script> tags also work in every other tag except <colgroup>.
  2561. var placeholder1 = stringToPrecomputedChunk('<template id="');
  2562. var placeholder2 = stringToPrecomputedChunk('"></template>');
  2563. function writePlaceholder(destination, responseState, id) {
  2564. writeChunk(destination, placeholder1);
  2565. writeChunk(destination, responseState.placeholderPrefix);
  2566. var formattedID = stringToChunk(id.toString(16));
  2567. writeChunk(destination, formattedID);
  2568. return writeChunkAndReturn(destination, placeholder2);
  2569. } // Suspense boundaries are encoded as comments.
  2570. var startCompletedSuspenseBoundary = stringToPrecomputedChunk('<!--$-->');
  2571. var startPendingSuspenseBoundary1 = stringToPrecomputedChunk('<!--$?--><template id="');
  2572. var startPendingSuspenseBoundary2 = stringToPrecomputedChunk('"></template>');
  2573. var startClientRenderedSuspenseBoundary = stringToPrecomputedChunk('<!--$!-->');
  2574. var endSuspenseBoundary = stringToPrecomputedChunk('<!--/$-->');
  2575. var clientRenderedSuspenseBoundaryError1 = stringToPrecomputedChunk('<template');
  2576. var clientRenderedSuspenseBoundaryErrorAttrInterstitial = stringToPrecomputedChunk('"');
  2577. var clientRenderedSuspenseBoundaryError1A = stringToPrecomputedChunk(' data-dgst="');
  2578. var clientRenderedSuspenseBoundaryError1B = stringToPrecomputedChunk(' data-msg="');
  2579. var clientRenderedSuspenseBoundaryError1C = stringToPrecomputedChunk(' data-stck="');
  2580. var clientRenderedSuspenseBoundaryError2 = stringToPrecomputedChunk('></template>');
  2581. function writeStartCompletedSuspenseBoundary(destination, responseState) {
  2582. return writeChunkAndReturn(destination, startCompletedSuspenseBoundary);
  2583. }
  2584. function writeStartPendingSuspenseBoundary(destination, responseState, id) {
  2585. writeChunk(destination, startPendingSuspenseBoundary1);
  2586. if (id === null) {
  2587. throw new Error('An ID must have been assigned before we can complete the boundary.');
  2588. }
  2589. writeChunk(destination, id);
  2590. return writeChunkAndReturn(destination, startPendingSuspenseBoundary2);
  2591. }
  2592. function writeStartClientRenderedSuspenseBoundary(destination, responseState, errorDigest, errorMesssage, errorComponentStack) {
  2593. var result;
  2594. result = writeChunkAndReturn(destination, startClientRenderedSuspenseBoundary);
  2595. writeChunk(destination, clientRenderedSuspenseBoundaryError1);
  2596. if (errorDigest) {
  2597. writeChunk(destination, clientRenderedSuspenseBoundaryError1A);
  2598. writeChunk(destination, stringToChunk(escapeTextForBrowser(errorDigest)));
  2599. writeChunk(destination, clientRenderedSuspenseBoundaryErrorAttrInterstitial);
  2600. }
  2601. {
  2602. if (errorMesssage) {
  2603. writeChunk(destination, clientRenderedSuspenseBoundaryError1B);
  2604. writeChunk(destination, stringToChunk(escapeTextForBrowser(errorMesssage)));
  2605. writeChunk(destination, clientRenderedSuspenseBoundaryErrorAttrInterstitial);
  2606. }
  2607. if (errorComponentStack) {
  2608. writeChunk(destination, clientRenderedSuspenseBoundaryError1C);
  2609. writeChunk(destination, stringToChunk(escapeTextForBrowser(errorComponentStack)));
  2610. writeChunk(destination, clientRenderedSuspenseBoundaryErrorAttrInterstitial);
  2611. }
  2612. }
  2613. result = writeChunkAndReturn(destination, clientRenderedSuspenseBoundaryError2);
  2614. return result;
  2615. }
  2616. function writeEndCompletedSuspenseBoundary(destination, responseState) {
  2617. return writeChunkAndReturn(destination, endSuspenseBoundary);
  2618. }
  2619. function writeEndPendingSuspenseBoundary(destination, responseState) {
  2620. return writeChunkAndReturn(destination, endSuspenseBoundary);
  2621. }
  2622. function writeEndClientRenderedSuspenseBoundary(destination, responseState) {
  2623. return writeChunkAndReturn(destination, endSuspenseBoundary);
  2624. }
  2625. var startSegmentHTML = stringToPrecomputedChunk('<div hidden id="');
  2626. var startSegmentHTML2 = stringToPrecomputedChunk('">');
  2627. var endSegmentHTML = stringToPrecomputedChunk('</div>');
  2628. var startSegmentSVG = stringToPrecomputedChunk('<svg aria-hidden="true" style="display:none" id="');
  2629. var startSegmentSVG2 = stringToPrecomputedChunk('">');
  2630. var endSegmentSVG = stringToPrecomputedChunk('</svg>');
  2631. var startSegmentMathML = stringToPrecomputedChunk('<math aria-hidden="true" style="display:none" id="');
  2632. var startSegmentMathML2 = stringToPrecomputedChunk('">');
  2633. var endSegmentMathML = stringToPrecomputedChunk('</math>');
  2634. var startSegmentTable = stringToPrecomputedChunk('<table hidden id="');
  2635. var startSegmentTable2 = stringToPrecomputedChunk('">');
  2636. var endSegmentTable = stringToPrecomputedChunk('</table>');
  2637. var startSegmentTableBody = stringToPrecomputedChunk('<table hidden><tbody id="');
  2638. var startSegmentTableBody2 = stringToPrecomputedChunk('">');
  2639. var endSegmentTableBody = stringToPrecomputedChunk('</tbody></table>');
  2640. var startSegmentTableRow = stringToPrecomputedChunk('<table hidden><tr id="');
  2641. var startSegmentTableRow2 = stringToPrecomputedChunk('">');
  2642. var endSegmentTableRow = stringToPrecomputedChunk('</tr></table>');
  2643. var startSegmentColGroup = stringToPrecomputedChunk('<table hidden><colgroup id="');
  2644. var startSegmentColGroup2 = stringToPrecomputedChunk('">');
  2645. var endSegmentColGroup = stringToPrecomputedChunk('</colgroup></table>');
  2646. function writeStartSegment(destination, responseState, formatContext, id) {
  2647. switch (formatContext.insertionMode) {
  2648. case ROOT_HTML_MODE:
  2649. case HTML_MODE:
  2650. {
  2651. writeChunk(destination, startSegmentHTML);
  2652. writeChunk(destination, responseState.segmentPrefix);
  2653. writeChunk(destination, stringToChunk(id.toString(16)));
  2654. return writeChunkAndReturn(destination, startSegmentHTML2);
  2655. }
  2656. case SVG_MODE:
  2657. {
  2658. writeChunk(destination, startSegmentSVG);
  2659. writeChunk(destination, responseState.segmentPrefix);
  2660. writeChunk(destination, stringToChunk(id.toString(16)));
  2661. return writeChunkAndReturn(destination, startSegmentSVG2);
  2662. }
  2663. case MATHML_MODE:
  2664. {
  2665. writeChunk(destination, startSegmentMathML);
  2666. writeChunk(destination, responseState.segmentPrefix);
  2667. writeChunk(destination, stringToChunk(id.toString(16)));
  2668. return writeChunkAndReturn(destination, startSegmentMathML2);
  2669. }
  2670. case HTML_TABLE_MODE:
  2671. {
  2672. writeChunk(destination, startSegmentTable);
  2673. writeChunk(destination, responseState.segmentPrefix);
  2674. writeChunk(destination, stringToChunk(id.toString(16)));
  2675. return writeChunkAndReturn(destination, startSegmentTable2);
  2676. }
  2677. // TODO: For the rest of these, there will be extra wrapper nodes that never
  2678. // get deleted from the document. We need to delete the table too as part
  2679. // of the injected scripts. They are invisible though so it's not too terrible
  2680. // and it's kind of an edge case to suspend in a table. Totally supported though.
  2681. case HTML_TABLE_BODY_MODE:
  2682. {
  2683. writeChunk(destination, startSegmentTableBody);
  2684. writeChunk(destination, responseState.segmentPrefix);
  2685. writeChunk(destination, stringToChunk(id.toString(16)));
  2686. return writeChunkAndReturn(destination, startSegmentTableBody2);
  2687. }
  2688. case HTML_TABLE_ROW_MODE:
  2689. {
  2690. writeChunk(destination, startSegmentTableRow);
  2691. writeChunk(destination, responseState.segmentPrefix);
  2692. writeChunk(destination, stringToChunk(id.toString(16)));
  2693. return writeChunkAndReturn(destination, startSegmentTableRow2);
  2694. }
  2695. case HTML_COLGROUP_MODE:
  2696. {
  2697. writeChunk(destination, startSegmentColGroup);
  2698. writeChunk(destination, responseState.segmentPrefix);
  2699. writeChunk(destination, stringToChunk(id.toString(16)));
  2700. return writeChunkAndReturn(destination, startSegmentColGroup2);
  2701. }
  2702. default:
  2703. {
  2704. throw new Error('Unknown insertion mode. This is a bug in React.');
  2705. }
  2706. }
  2707. }
  2708. function writeEndSegment(destination, formatContext) {
  2709. switch (formatContext.insertionMode) {
  2710. case ROOT_HTML_MODE:
  2711. case HTML_MODE:
  2712. {
  2713. return writeChunkAndReturn(destination, endSegmentHTML);
  2714. }
  2715. case SVG_MODE:
  2716. {
  2717. return writeChunkAndReturn(destination, endSegmentSVG);
  2718. }
  2719. case MATHML_MODE:
  2720. {
  2721. return writeChunkAndReturn(destination, endSegmentMathML);
  2722. }
  2723. case HTML_TABLE_MODE:
  2724. {
  2725. return writeChunkAndReturn(destination, endSegmentTable);
  2726. }
  2727. case HTML_TABLE_BODY_MODE:
  2728. {
  2729. return writeChunkAndReturn(destination, endSegmentTableBody);
  2730. }
  2731. case HTML_TABLE_ROW_MODE:
  2732. {
  2733. return writeChunkAndReturn(destination, endSegmentTableRow);
  2734. }
  2735. case HTML_COLGROUP_MODE:
  2736. {
  2737. return writeChunkAndReturn(destination, endSegmentColGroup);
  2738. }
  2739. default:
  2740. {
  2741. throw new Error('Unknown insertion mode. This is a bug in React.');
  2742. }
  2743. }
  2744. } // Instruction Set
  2745. // The following code is the source scripts that we then minify and inline below,
  2746. // with renamed function names that we hope don't collide:
  2747. // const COMMENT_NODE = 8;
  2748. // const SUSPENSE_START_DATA = '$';
  2749. // const SUSPENSE_END_DATA = '/$';
  2750. // const SUSPENSE_PENDING_START_DATA = '$?';
  2751. // const SUSPENSE_FALLBACK_START_DATA = '$!';
  2752. //
  2753. // function clientRenderBoundary(suspenseBoundaryID, errorDigest, errorMsg, errorComponentStack) {
  2754. // // Find the fallback's first element.
  2755. // const suspenseIdNode = document.getElementById(suspenseBoundaryID);
  2756. // if (!suspenseIdNode) {
  2757. // // The user must have already navigated away from this tree.
  2758. // // E.g. because the parent was hydrated.
  2759. // return;
  2760. // }
  2761. // // Find the boundary around the fallback. This is always the previous node.
  2762. // const suspenseNode = suspenseIdNode.previousSibling;
  2763. // // Tag it to be client rendered.
  2764. // suspenseNode.data = SUSPENSE_FALLBACK_START_DATA;
  2765. // // assign error metadata to first sibling
  2766. // let dataset = suspenseIdNode.dataset;
  2767. // if (errorDigest) dataset.dgst = errorDigest;
  2768. // if (errorMsg) dataset.msg = errorMsg;
  2769. // if (errorComponentStack) dataset.stck = errorComponentStack;
  2770. // // Tell React to retry it if the parent already hydrated.
  2771. // if (suspenseNode._reactRetry) {
  2772. // suspenseNode._reactRetry();
  2773. // }
  2774. // }
  2775. //
  2776. // function completeBoundary(suspenseBoundaryID, contentID) {
  2777. // // Find the fallback's first element.
  2778. // const suspenseIdNode = document.getElementById(suspenseBoundaryID);
  2779. // const contentNode = document.getElementById(contentID);
  2780. // // We'll detach the content node so that regardless of what happens next we don't leave in the tree.
  2781. // // This might also help by not causing recalcing each time we move a child from here to the target.
  2782. // contentNode.parentNode.removeChild(contentNode);
  2783. // if (!suspenseIdNode) {
  2784. // // The user must have already navigated away from this tree.
  2785. // // E.g. because the parent was hydrated. That's fine there's nothing to do
  2786. // // but we have to make sure that we already deleted the container node.
  2787. // return;
  2788. // }
  2789. // // Find the boundary around the fallback. This is always the previous node.
  2790. // const suspenseNode = suspenseIdNode.previousSibling;
  2791. //
  2792. // // Clear all the existing children. This is complicated because
  2793. // // there can be embedded Suspense boundaries in the fallback.
  2794. // // This is similar to clearSuspenseBoundary in ReactDOMHostConfig.
  2795. // // TODO: We could avoid this if we never emitted suspense boundaries in fallback trees.
  2796. // // They never hydrate anyway. However, currently we support incrementally loading the fallback.
  2797. // const parentInstance = suspenseNode.parentNode;
  2798. // let node = suspenseNode.nextSibling;
  2799. // let depth = 0;
  2800. // do {
  2801. // if (node && node.nodeType === COMMENT_NODE) {
  2802. // const data = node.data;
  2803. // if (data === SUSPENSE_END_DATA) {
  2804. // if (depth === 0) {
  2805. // break;
  2806. // } else {
  2807. // depth--;
  2808. // }
  2809. // } else if (
  2810. // data === SUSPENSE_START_DATA ||
  2811. // data === SUSPENSE_PENDING_START_DATA ||
  2812. // data === SUSPENSE_FALLBACK_START_DATA
  2813. // ) {
  2814. // depth++;
  2815. // }
  2816. // }
  2817. //
  2818. // const nextNode = node.nextSibling;
  2819. // parentInstance.removeChild(node);
  2820. // node = nextNode;
  2821. // } while (node);
  2822. //
  2823. // const endOfBoundary = node;
  2824. //
  2825. // // Insert all the children from the contentNode between the start and end of suspense boundary.
  2826. // while (contentNode.firstChild) {
  2827. // parentInstance.insertBefore(contentNode.firstChild, endOfBoundary);
  2828. // }
  2829. // suspenseNode.data = SUSPENSE_START_DATA;
  2830. // if (suspenseNode._reactRetry) {
  2831. // suspenseNode._reactRetry();
  2832. // }
  2833. // }
  2834. //
  2835. // function completeSegment(containerID, placeholderID) {
  2836. // const segmentContainer = document.getElementById(containerID);
  2837. // const placeholderNode = document.getElementById(placeholderID);
  2838. // // We always expect both nodes to exist here because, while we might
  2839. // // have navigated away from the main tree, we still expect the detached
  2840. // // tree to exist.
  2841. // segmentContainer.parentNode.removeChild(segmentContainer);
  2842. // while (segmentContainer.firstChild) {
  2843. // placeholderNode.parentNode.insertBefore(
  2844. // segmentContainer.firstChild,
  2845. // placeholderNode,
  2846. // );
  2847. // }
  2848. // placeholderNode.parentNode.removeChild(placeholderNode);
  2849. // }
  2850. var completeSegmentFunction = 'function $RS(a,b){a=document.getElementById(a);b=document.getElementById(b);for(a.parentNode.removeChild(a);a.firstChild;)b.parentNode.insertBefore(a.firstChild,b);b.parentNode.removeChild(b)}';
  2851. var completeBoundaryFunction = 'function $RC(a,b){a=document.getElementById(a);b=document.getElementById(b);b.parentNode.removeChild(b);if(a){a=a.previousSibling;var f=a.parentNode,c=a.nextSibling,e=0;do{if(c&&8===c.nodeType){var d=c.data;if("/$"===d)if(0===e)break;else e--;else"$"!==d&&"$?"!==d&&"$!"!==d||e++}d=c.nextSibling;f.removeChild(c);c=d}while(c);for(;b.firstChild;)f.insertBefore(b.firstChild,c);a.data="$";a._reactRetry&&a._reactRetry()}}';
  2852. var clientRenderFunction = 'function $RX(b,c,d,e){var a=document.getElementById(b);a&&(b=a.previousSibling,b.data="$!",a=a.dataset,c&&(a.dgst=c),d&&(a.msg=d),e&&(a.stck=e),b._reactRetry&&b._reactRetry())}';
  2853. var completeSegmentScript1Full = stringToPrecomputedChunk(completeSegmentFunction + ';$RS("');
  2854. var completeSegmentScript1Partial = stringToPrecomputedChunk('$RS("');
  2855. var completeSegmentScript2 = stringToPrecomputedChunk('","');
  2856. var completeSegmentScript3 = stringToPrecomputedChunk('")</script>');
  2857. function writeCompletedSegmentInstruction(destination, responseState, contentSegmentID) {
  2858. writeChunk(destination, responseState.startInlineScript);
  2859. if (!responseState.sentCompleteSegmentFunction) {
  2860. // The first time we write this, we'll need to include the full implementation.
  2861. responseState.sentCompleteSegmentFunction = true;
  2862. writeChunk(destination, completeSegmentScript1Full);
  2863. } else {
  2864. // Future calls can just reuse the same function.
  2865. writeChunk(destination, completeSegmentScript1Partial);
  2866. }
  2867. writeChunk(destination, responseState.segmentPrefix);
  2868. var formattedID = stringToChunk(contentSegmentID.toString(16));
  2869. writeChunk(destination, formattedID);
  2870. writeChunk(destination, completeSegmentScript2);
  2871. writeChunk(destination, responseState.placeholderPrefix);
  2872. writeChunk(destination, formattedID);
  2873. return writeChunkAndReturn(destination, completeSegmentScript3);
  2874. }
  2875. var completeBoundaryScript1Full = stringToPrecomputedChunk(completeBoundaryFunction + ';$RC("');
  2876. var completeBoundaryScript1Partial = stringToPrecomputedChunk('$RC("');
  2877. var completeBoundaryScript2 = stringToPrecomputedChunk('","');
  2878. var completeBoundaryScript3 = stringToPrecomputedChunk('")</script>');
  2879. function writeCompletedBoundaryInstruction(destination, responseState, boundaryID, contentSegmentID) {
  2880. writeChunk(destination, responseState.startInlineScript);
  2881. if (!responseState.sentCompleteBoundaryFunction) {
  2882. // The first time we write this, we'll need to include the full implementation.
  2883. responseState.sentCompleteBoundaryFunction = true;
  2884. writeChunk(destination, completeBoundaryScript1Full);
  2885. } else {
  2886. // Future calls can just reuse the same function.
  2887. writeChunk(destination, completeBoundaryScript1Partial);
  2888. }
  2889. if (boundaryID === null) {
  2890. throw new Error('An ID must have been assigned before we can complete the boundary.');
  2891. }
  2892. var formattedContentID = stringToChunk(contentSegmentID.toString(16));
  2893. writeChunk(destination, boundaryID);
  2894. writeChunk(destination, completeBoundaryScript2);
  2895. writeChunk(destination, responseState.segmentPrefix);
  2896. writeChunk(destination, formattedContentID);
  2897. return writeChunkAndReturn(destination, completeBoundaryScript3);
  2898. }
  2899. var clientRenderScript1Full = stringToPrecomputedChunk(clientRenderFunction + ';$RX("');
  2900. var clientRenderScript1Partial = stringToPrecomputedChunk('$RX("');
  2901. var clientRenderScript1A = stringToPrecomputedChunk('"');
  2902. var clientRenderScript2 = stringToPrecomputedChunk(')</script>');
  2903. var clientRenderErrorScriptArgInterstitial = stringToPrecomputedChunk(',');
  2904. function writeClientRenderBoundaryInstruction(destination, responseState, boundaryID, errorDigest, errorMessage, errorComponentStack) {
  2905. writeChunk(destination, responseState.startInlineScript);
  2906. if (!responseState.sentClientRenderFunction) {
  2907. // The first time we write this, we'll need to include the full implementation.
  2908. responseState.sentClientRenderFunction = true;
  2909. writeChunk(destination, clientRenderScript1Full);
  2910. } else {
  2911. // Future calls can just reuse the same function.
  2912. writeChunk(destination, clientRenderScript1Partial);
  2913. }
  2914. if (boundaryID === null) {
  2915. throw new Error('An ID must have been assigned before we can complete the boundary.');
  2916. }
  2917. writeChunk(destination, boundaryID);
  2918. writeChunk(destination, clientRenderScript1A);
  2919. if (errorDigest || errorMessage || errorComponentStack) {
  2920. writeChunk(destination, clientRenderErrorScriptArgInterstitial);
  2921. writeChunk(destination, stringToChunk(escapeJSStringsForInstructionScripts(errorDigest || '')));
  2922. }
  2923. if (errorMessage || errorComponentStack) {
  2924. writeChunk(destination, clientRenderErrorScriptArgInterstitial);
  2925. writeChunk(destination, stringToChunk(escapeJSStringsForInstructionScripts(errorMessage || '')));
  2926. }
  2927. if (errorComponentStack) {
  2928. writeChunk(destination, clientRenderErrorScriptArgInterstitial);
  2929. writeChunk(destination, stringToChunk(escapeJSStringsForInstructionScripts(errorComponentStack)));
  2930. }
  2931. return writeChunkAndReturn(destination, clientRenderScript2);
  2932. }
  2933. var regexForJSStringsInScripts = /[<\u2028\u2029]/g;
  2934. function escapeJSStringsForInstructionScripts(input) {
  2935. var escaped = JSON.stringify(input);
  2936. return escaped.replace(regexForJSStringsInScripts, function (match) {
  2937. switch (match) {
  2938. // santizing breaking out of strings and script tags
  2939. case '<':
  2940. return "\\u003c";
  2941. case "\u2028":
  2942. return "\\u2028";
  2943. case "\u2029":
  2944. return "\\u2029";
  2945. default:
  2946. {
  2947. // eslint-disable-next-line react-internal/prod-error-codes
  2948. throw new Error('escapeJSStringsForInstructionScripts encountered a match it does not know how to replace. this means the match regex and the replacement characters are no longer in sync. This is a bug in React');
  2949. }
  2950. }
  2951. });
  2952. }
  2953. var assign = Object.assign;
  2954. // ATTENTION
  2955. // When adding new symbols to this file,
  2956. // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
  2957. // The Symbol used to tag the ReactElement-like types.
  2958. var REACT_ELEMENT_TYPE = Symbol.for('react.element');
  2959. var REACT_PORTAL_TYPE = Symbol.for('react.portal');
  2960. var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
  2961. var REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');
  2962. var REACT_PROFILER_TYPE = Symbol.for('react.profiler');
  2963. var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
  2964. var REACT_CONTEXT_TYPE = Symbol.for('react.context');
  2965. var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
  2966. var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
  2967. var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
  2968. var REACT_MEMO_TYPE = Symbol.for('react.memo');
  2969. var REACT_LAZY_TYPE = Symbol.for('react.lazy');
  2970. var REACT_SCOPE_TYPE = Symbol.for('react.scope');
  2971. var REACT_DEBUG_TRACING_MODE_TYPE = Symbol.for('react.debug_trace_mode');
  2972. var REACT_LEGACY_HIDDEN_TYPE = Symbol.for('react.legacy_hidden');
  2973. var REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = Symbol.for('react.default_value');
  2974. var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
  2975. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  2976. function getIteratorFn(maybeIterable) {
  2977. if (maybeIterable === null || typeof maybeIterable !== 'object') {
  2978. return null;
  2979. }
  2980. var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
  2981. if (typeof maybeIterator === 'function') {
  2982. return maybeIterator;
  2983. }
  2984. return null;
  2985. }
  2986. function getWrappedName(outerType, innerType, wrapperName) {
  2987. var displayName = outerType.displayName;
  2988. if (displayName) {
  2989. return displayName;
  2990. }
  2991. var functionName = innerType.displayName || innerType.name || '';
  2992. return functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName;
  2993. } // Keep in sync with react-reconciler/getComponentNameFromFiber
  2994. function getContextName(type) {
  2995. return type.displayName || 'Context';
  2996. } // Note that the reconciler package should generally prefer to use getComponentNameFromFiber() instead.
  2997. function getComponentNameFromType(type) {
  2998. if (type == null) {
  2999. // Host root, text node or just invalid type.
  3000. return null;
  3001. }
  3002. {
  3003. if (typeof type.tag === 'number') {
  3004. error('Received an unexpected object in getComponentNameFromType(). ' + 'This is likely a bug in React. Please file an issue.');
  3005. }
  3006. }
  3007. if (typeof type === 'function') {
  3008. return type.displayName || type.name || null;
  3009. }
  3010. if (typeof type === 'string') {
  3011. return type;
  3012. }
  3013. switch (type) {
  3014. case REACT_FRAGMENT_TYPE:
  3015. return 'Fragment';
  3016. case REACT_PORTAL_TYPE:
  3017. return 'Portal';
  3018. case REACT_PROFILER_TYPE:
  3019. return 'Profiler';
  3020. case REACT_STRICT_MODE_TYPE:
  3021. return 'StrictMode';
  3022. case REACT_SUSPENSE_TYPE:
  3023. return 'Suspense';
  3024. case REACT_SUSPENSE_LIST_TYPE:
  3025. return 'SuspenseList';
  3026. }
  3027. if (typeof type === 'object') {
  3028. switch (type.$$typeof) {
  3029. case REACT_CONTEXT_TYPE:
  3030. var context = type;
  3031. return getContextName(context) + '.Consumer';
  3032. case REACT_PROVIDER_TYPE:
  3033. var provider = type;
  3034. return getContextName(provider._context) + '.Provider';
  3035. case REACT_FORWARD_REF_TYPE:
  3036. return getWrappedName(type, type.render, 'ForwardRef');
  3037. case REACT_MEMO_TYPE:
  3038. var outerName = type.displayName || null;
  3039. if (outerName !== null) {
  3040. return outerName;
  3041. }
  3042. return getComponentNameFromType(type.type) || 'Memo';
  3043. case REACT_LAZY_TYPE:
  3044. {
  3045. var lazyComponent = type;
  3046. var payload = lazyComponent._payload;
  3047. var init = lazyComponent._init;
  3048. try {
  3049. return getComponentNameFromType(init(payload));
  3050. } catch (x) {
  3051. return null;
  3052. }
  3053. }
  3054. // eslint-disable-next-line no-fallthrough
  3055. }
  3056. }
  3057. return null;
  3058. }
  3059. // Helpers to patch console.logs to avoid logging during side-effect free
  3060. // replaying on render function. This currently only patches the object
  3061. // lazily which won't cover if the log function was extracted eagerly.
  3062. // We could also eagerly patch the method.
  3063. var disabledDepth = 0;
  3064. var prevLog;
  3065. var prevInfo;
  3066. var prevWarn;
  3067. var prevError;
  3068. var prevGroup;
  3069. var prevGroupCollapsed;
  3070. var prevGroupEnd;
  3071. function disabledLog() {}
  3072. disabledLog.__reactDisabledLog = true;
  3073. function disableLogs() {
  3074. {
  3075. if (disabledDepth === 0) {
  3076. /* eslint-disable react-internal/no-production-logging */
  3077. prevLog = console.log;
  3078. prevInfo = console.info;
  3079. prevWarn = console.warn;
  3080. prevError = console.error;
  3081. prevGroup = console.group;
  3082. prevGroupCollapsed = console.groupCollapsed;
  3083. prevGroupEnd = console.groupEnd; // https://github.com/facebook/react/issues/19099
  3084. var props = {
  3085. configurable: true,
  3086. enumerable: true,
  3087. value: disabledLog,
  3088. writable: true
  3089. }; // $FlowFixMe Flow thinks console is immutable.
  3090. Object.defineProperties(console, {
  3091. info: props,
  3092. log: props,
  3093. warn: props,
  3094. error: props,
  3095. group: props,
  3096. groupCollapsed: props,
  3097. groupEnd: props
  3098. });
  3099. /* eslint-enable react-internal/no-production-logging */
  3100. }
  3101. disabledDepth++;
  3102. }
  3103. }
  3104. function reenableLogs() {
  3105. {
  3106. disabledDepth--;
  3107. if (disabledDepth === 0) {
  3108. /* eslint-disable react-internal/no-production-logging */
  3109. var props = {
  3110. configurable: true,
  3111. enumerable: true,
  3112. writable: true
  3113. }; // $FlowFixMe Flow thinks console is immutable.
  3114. Object.defineProperties(console, {
  3115. log: assign({}, props, {
  3116. value: prevLog
  3117. }),
  3118. info: assign({}, props, {
  3119. value: prevInfo
  3120. }),
  3121. warn: assign({}, props, {
  3122. value: prevWarn
  3123. }),
  3124. error: assign({}, props, {
  3125. value: prevError
  3126. }),
  3127. group: assign({}, props, {
  3128. value: prevGroup
  3129. }),
  3130. groupCollapsed: assign({}, props, {
  3131. value: prevGroupCollapsed
  3132. }),
  3133. groupEnd: assign({}, props, {
  3134. value: prevGroupEnd
  3135. })
  3136. });
  3137. /* eslint-enable react-internal/no-production-logging */
  3138. }
  3139. if (disabledDepth < 0) {
  3140. error('disabledDepth fell below zero. ' + 'This is a bug in React. Please file an issue.');
  3141. }
  3142. }
  3143. }
  3144. var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
  3145. var prefix;
  3146. function describeBuiltInComponentFrame(name, source, ownerFn) {
  3147. {
  3148. if (prefix === undefined) {
  3149. // Extract the VM specific prefix used by each line.
  3150. try {
  3151. throw Error();
  3152. } catch (x) {
  3153. var match = x.stack.trim().match(/\n( *(at )?)/);
  3154. prefix = match && match[1] || '';
  3155. }
  3156. } // We use the prefix to ensure our stacks line up with native stack frames.
  3157. return '\n' + prefix + name;
  3158. }
  3159. }
  3160. var reentry = false;
  3161. var componentFrameCache;
  3162. {
  3163. var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
  3164. componentFrameCache = new PossiblyWeakMap();
  3165. }
  3166. function describeNativeComponentFrame(fn, construct) {
  3167. // If something asked for a stack inside a fake render, it should get ignored.
  3168. if ( !fn || reentry) {
  3169. return '';
  3170. }
  3171. {
  3172. var frame = componentFrameCache.get(fn);
  3173. if (frame !== undefined) {
  3174. return frame;
  3175. }
  3176. }
  3177. var control;
  3178. reentry = true;
  3179. var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe It does accept undefined.
  3180. Error.prepareStackTrace = undefined;
  3181. var previousDispatcher;
  3182. {
  3183. previousDispatcher = ReactCurrentDispatcher.current; // Set the dispatcher in DEV because this might be call in the render function
  3184. // for warnings.
  3185. ReactCurrentDispatcher.current = null;
  3186. disableLogs();
  3187. }
  3188. try {
  3189. // This should throw.
  3190. if (construct) {
  3191. // Something should be setting the props in the constructor.
  3192. var Fake = function () {
  3193. throw Error();
  3194. }; // $FlowFixMe
  3195. Object.defineProperty(Fake.prototype, 'props', {
  3196. set: function () {
  3197. // We use a throwing setter instead of frozen or non-writable props
  3198. // because that won't throw in a non-strict mode function.
  3199. throw Error();
  3200. }
  3201. });
  3202. if (typeof Reflect === 'object' && Reflect.construct) {
  3203. // We construct a different control for this case to include any extra
  3204. // frames added by the construct call.
  3205. try {
  3206. Reflect.construct(Fake, []);
  3207. } catch (x) {
  3208. control = x;
  3209. }
  3210. Reflect.construct(fn, [], Fake);
  3211. } else {
  3212. try {
  3213. Fake.call();
  3214. } catch (x) {
  3215. control = x;
  3216. }
  3217. fn.call(Fake.prototype);
  3218. }
  3219. } else {
  3220. try {
  3221. throw Error();
  3222. } catch (x) {
  3223. control = x;
  3224. }
  3225. fn();
  3226. }
  3227. } catch (sample) {
  3228. // This is inlined manually because closure doesn't do it for us.
  3229. if (sample && control && typeof sample.stack === 'string') {
  3230. // This extracts the first frame from the sample that isn't also in the control.
  3231. // Skipping one frame that we assume is the frame that calls the two.
  3232. var sampleLines = sample.stack.split('\n');
  3233. var controlLines = control.stack.split('\n');
  3234. var s = sampleLines.length - 1;
  3235. var c = controlLines.length - 1;
  3236. while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) {
  3237. // We expect at least one stack frame to be shared.
  3238. // Typically this will be the root most one. However, stack frames may be
  3239. // cut off due to maximum stack limits. In this case, one maybe cut off
  3240. // earlier than the other. We assume that the sample is longer or the same
  3241. // and there for cut off earlier. So we should find the root most frame in
  3242. // the sample somewhere in the control.
  3243. c--;
  3244. }
  3245. for (; s >= 1 && c >= 0; s--, c--) {
  3246. // Next we find the first one that isn't the same which should be the
  3247. // frame that called our sample function and the control.
  3248. if (sampleLines[s] !== controlLines[c]) {
  3249. // In V8, the first line is describing the message but other VMs don't.
  3250. // If we're about to return the first line, and the control is also on the same
  3251. // line, that's a pretty good indicator that our sample threw at same line as
  3252. // the control. I.e. before we entered the sample frame. So we ignore this result.
  3253. // This can happen if you passed a class to function component, or non-function.
  3254. if (s !== 1 || c !== 1) {
  3255. do {
  3256. s--;
  3257. c--; // We may still have similar intermediate frames from the construct call.
  3258. // The next one that isn't the same should be our match though.
  3259. if (c < 0 || sampleLines[s] !== controlLines[c]) {
  3260. // V8 adds a "new" prefix for native classes. Let's remove it to make it prettier.
  3261. var _frame = '\n' + sampleLines[s].replace(' at new ', ' at '); // If our component frame is labeled "<anonymous>"
  3262. // but we have a user-provided "displayName"
  3263. // splice it in to make the stack more readable.
  3264. if (fn.displayName && _frame.includes('<anonymous>')) {
  3265. _frame = _frame.replace('<anonymous>', fn.displayName);
  3266. }
  3267. {
  3268. if (typeof fn === 'function') {
  3269. componentFrameCache.set(fn, _frame);
  3270. }
  3271. } // Return the line we found.
  3272. return _frame;
  3273. }
  3274. } while (s >= 1 && c >= 0);
  3275. }
  3276. break;
  3277. }
  3278. }
  3279. }
  3280. } finally {
  3281. reentry = false;
  3282. {
  3283. ReactCurrentDispatcher.current = previousDispatcher;
  3284. reenableLogs();
  3285. }
  3286. Error.prepareStackTrace = previousPrepareStackTrace;
  3287. } // Fallback to just using the name if we couldn't make it throw.
  3288. var name = fn ? fn.displayName || fn.name : '';
  3289. var syntheticFrame = name ? describeBuiltInComponentFrame(name) : '';
  3290. {
  3291. if (typeof fn === 'function') {
  3292. componentFrameCache.set(fn, syntheticFrame);
  3293. }
  3294. }
  3295. return syntheticFrame;
  3296. }
  3297. function describeClassComponentFrame(ctor, source, ownerFn) {
  3298. {
  3299. return describeNativeComponentFrame(ctor, true);
  3300. }
  3301. }
  3302. function describeFunctionComponentFrame(fn, source, ownerFn) {
  3303. {
  3304. return describeNativeComponentFrame(fn, false);
  3305. }
  3306. }
  3307. function shouldConstruct(Component) {
  3308. var prototype = Component.prototype;
  3309. return !!(prototype && prototype.isReactComponent);
  3310. }
  3311. function describeUnknownElementTypeFrameInDEV(type, source, ownerFn) {
  3312. if (type == null) {
  3313. return '';
  3314. }
  3315. if (typeof type === 'function') {
  3316. {
  3317. return describeNativeComponentFrame(type, shouldConstruct(type));
  3318. }
  3319. }
  3320. if (typeof type === 'string') {
  3321. return describeBuiltInComponentFrame(type);
  3322. }
  3323. switch (type) {
  3324. case REACT_SUSPENSE_TYPE:
  3325. return describeBuiltInComponentFrame('Suspense');
  3326. case REACT_SUSPENSE_LIST_TYPE:
  3327. return describeBuiltInComponentFrame('SuspenseList');
  3328. }
  3329. if (typeof type === 'object') {
  3330. switch (type.$$typeof) {
  3331. case REACT_FORWARD_REF_TYPE:
  3332. return describeFunctionComponentFrame(type.render);
  3333. case REACT_MEMO_TYPE:
  3334. // Memo may contain any component type so we recursively resolve it.
  3335. return describeUnknownElementTypeFrameInDEV(type.type, source, ownerFn);
  3336. case REACT_LAZY_TYPE:
  3337. {
  3338. var lazyComponent = type;
  3339. var payload = lazyComponent._payload;
  3340. var init = lazyComponent._init;
  3341. try {
  3342. // Lazy may contain any component type so we recursively resolve it.
  3343. return describeUnknownElementTypeFrameInDEV(init(payload), source, ownerFn);
  3344. } catch (x) {}
  3345. }
  3346. }
  3347. }
  3348. return '';
  3349. }
  3350. var loggedTypeFailures = {};
  3351. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  3352. function setCurrentlyValidatingElement(element) {
  3353. {
  3354. if (element) {
  3355. var owner = element._owner;
  3356. var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
  3357. ReactDebugCurrentFrame.setExtraStackFrame(stack);
  3358. } else {
  3359. ReactDebugCurrentFrame.setExtraStackFrame(null);
  3360. }
  3361. }
  3362. }
  3363. function checkPropTypes(typeSpecs, values, location, componentName, element) {
  3364. {
  3365. // $FlowFixMe This is okay but Flow doesn't know it.
  3366. var has = Function.call.bind(hasOwnProperty);
  3367. for (var typeSpecName in typeSpecs) {
  3368. if (has(typeSpecs, typeSpecName)) {
  3369. var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
  3370. // fail the render phase where it didn't fail before. So we log it.
  3371. // After these have been cleaned up, we'll let them throw.
  3372. try {
  3373. // This is intentionally an invariant that gets caught. It's the same
  3374. // behavior as without this statement except with a better message.
  3375. if (typeof typeSpecs[typeSpecName] !== 'function') {
  3376. // eslint-disable-next-line react-internal/prod-error-codes
  3377. 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`.');
  3378. err.name = 'Invariant Violation';
  3379. throw err;
  3380. }
  3381. error$1 = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED');
  3382. } catch (ex) {
  3383. error$1 = ex;
  3384. }
  3385. if (error$1 && !(error$1 instanceof Error)) {
  3386. setCurrentlyValidatingElement(element);
  3387. 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);
  3388. setCurrentlyValidatingElement(null);
  3389. }
  3390. if (error$1 instanceof Error && !(error$1.message in loggedTypeFailures)) {
  3391. // Only monitor this failure once because there tends to be a lot of the
  3392. // same error.
  3393. loggedTypeFailures[error$1.message] = true;
  3394. setCurrentlyValidatingElement(element);
  3395. error('Failed %s type: %s', location, error$1.message);
  3396. setCurrentlyValidatingElement(null);
  3397. }
  3398. }
  3399. }
  3400. }
  3401. }
  3402. var warnedAboutMissingGetChildContext;
  3403. {
  3404. warnedAboutMissingGetChildContext = {};
  3405. }
  3406. var emptyContextObject = {};
  3407. {
  3408. Object.freeze(emptyContextObject);
  3409. }
  3410. function getMaskedContext(type, unmaskedContext) {
  3411. {
  3412. var contextTypes = type.contextTypes;
  3413. if (!contextTypes) {
  3414. return emptyContextObject;
  3415. }
  3416. var context = {};
  3417. for (var key in contextTypes) {
  3418. context[key] = unmaskedContext[key];
  3419. }
  3420. {
  3421. var name = getComponentNameFromType(type) || 'Unknown';
  3422. checkPropTypes(contextTypes, context, 'context', name);
  3423. }
  3424. return context;
  3425. }
  3426. }
  3427. function processChildContext(instance, type, parentContext, childContextTypes) {
  3428. {
  3429. // TODO (bvaughn) Replace this behavior with an invariant() in the future.
  3430. // It has only been added in Fiber to match the (unintentional) behavior in Stack.
  3431. if (typeof instance.getChildContext !== 'function') {
  3432. {
  3433. var componentName = getComponentNameFromType(type) || 'Unknown';
  3434. if (!warnedAboutMissingGetChildContext[componentName]) {
  3435. warnedAboutMissingGetChildContext[componentName] = true;
  3436. 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);
  3437. }
  3438. }
  3439. return parentContext;
  3440. }
  3441. var childContext = instance.getChildContext();
  3442. for (var contextKey in childContext) {
  3443. if (!(contextKey in childContextTypes)) {
  3444. throw new Error((getComponentNameFromType(type) || 'Unknown') + ".getChildContext(): key \"" + contextKey + "\" is not defined in childContextTypes.");
  3445. }
  3446. }
  3447. {
  3448. var name = getComponentNameFromType(type) || 'Unknown';
  3449. checkPropTypes(childContextTypes, childContext, 'child context', name);
  3450. }
  3451. return assign({}, parentContext, childContext);
  3452. }
  3453. }
  3454. var rendererSigil;
  3455. {
  3456. // Use this to detect multiple renderers using the same context
  3457. rendererSigil = {};
  3458. } // Used to store the parent path of all context overrides in a shared linked list.
  3459. // Forming a reverse tree.
  3460. var rootContextSnapshot = null; // We assume that this runtime owns the "current" field on all ReactContext instances.
  3461. // This global (actually thread local) state represents what state all those "current",
  3462. // fields are currently in.
  3463. var currentActiveSnapshot = null;
  3464. function popNode(prev) {
  3465. {
  3466. prev.context._currentValue = prev.parentValue;
  3467. }
  3468. }
  3469. function pushNode(next) {
  3470. {
  3471. next.context._currentValue = next.value;
  3472. }
  3473. }
  3474. function popToNearestCommonAncestor(prev, next) {
  3475. if (prev === next) ; else {
  3476. popNode(prev);
  3477. var parentPrev = prev.parent;
  3478. var parentNext = next.parent;
  3479. if (parentPrev === null) {
  3480. if (parentNext !== null) {
  3481. throw new Error('The stacks must reach the root at the same time. This is a bug in React.');
  3482. }
  3483. } else {
  3484. if (parentNext === null) {
  3485. throw new Error('The stacks must reach the root at the same time. This is a bug in React.');
  3486. }
  3487. popToNearestCommonAncestor(parentPrev, parentNext);
  3488. } // On the way back, we push the new ones that weren't common.
  3489. pushNode(next);
  3490. }
  3491. }
  3492. function popAllPrevious(prev) {
  3493. popNode(prev);
  3494. var parentPrev = prev.parent;
  3495. if (parentPrev !== null) {
  3496. popAllPrevious(parentPrev);
  3497. }
  3498. }
  3499. function pushAllNext(next) {
  3500. var parentNext = next.parent;
  3501. if (parentNext !== null) {
  3502. pushAllNext(parentNext);
  3503. }
  3504. pushNode(next);
  3505. }
  3506. function popPreviousToCommonLevel(prev, next) {
  3507. popNode(prev);
  3508. var parentPrev = prev.parent;
  3509. if (parentPrev === null) {
  3510. throw new Error('The depth must equal at least at zero before reaching the root. This is a bug in React.');
  3511. }
  3512. if (parentPrev.depth === next.depth) {
  3513. // We found the same level. Now we just need to find a shared ancestor.
  3514. popToNearestCommonAncestor(parentPrev, next);
  3515. } else {
  3516. // We must still be deeper.
  3517. popPreviousToCommonLevel(parentPrev, next);
  3518. }
  3519. }
  3520. function popNextToCommonLevel(prev, next) {
  3521. var parentNext = next.parent;
  3522. if (parentNext === null) {
  3523. throw new Error('The depth must equal at least at zero before reaching the root. This is a bug in React.');
  3524. }
  3525. if (prev.depth === parentNext.depth) {
  3526. // We found the same level. Now we just need to find a shared ancestor.
  3527. popToNearestCommonAncestor(prev, parentNext);
  3528. } else {
  3529. // We must still be deeper.
  3530. popNextToCommonLevel(prev, parentNext);
  3531. }
  3532. pushNode(next);
  3533. } // Perform context switching to the new snapshot.
  3534. // To make it cheap to read many contexts, while not suspending, we make the switch eagerly by
  3535. // updating all the context's current values. That way reads, always just read the current value.
  3536. // At the cost of updating contexts even if they're never read by this subtree.
  3537. function switchContext(newSnapshot) {
  3538. // The basic algorithm we need to do is to pop back any contexts that are no longer on the stack.
  3539. // We also need to update any new contexts that are now on the stack with the deepest value.
  3540. // The easiest way to update new contexts is to just reapply them in reverse order from the
  3541. // perspective of the backpointers. To avoid allocating a lot when switching, we use the stack
  3542. // for that. Therefore this algorithm is recursive.
  3543. // 1) First we pop which ever snapshot tree was deepest. Popping old contexts as we go.
  3544. // 2) Then we find the nearest common ancestor from there. Popping old contexts as we go.
  3545. // 3) Then we reapply new contexts on the way back up the stack.
  3546. var prev = currentActiveSnapshot;
  3547. var next = newSnapshot;
  3548. if (prev !== next) {
  3549. if (prev === null) {
  3550. // $FlowFixMe: This has to be non-null since it's not equal to prev.
  3551. pushAllNext(next);
  3552. } else if (next === null) {
  3553. popAllPrevious(prev);
  3554. } else if (prev.depth === next.depth) {
  3555. popToNearestCommonAncestor(prev, next);
  3556. } else if (prev.depth > next.depth) {
  3557. popPreviousToCommonLevel(prev, next);
  3558. } else {
  3559. popNextToCommonLevel(prev, next);
  3560. }
  3561. currentActiveSnapshot = next;
  3562. }
  3563. }
  3564. function pushProvider(context, nextValue) {
  3565. var prevValue;
  3566. {
  3567. prevValue = context._currentValue;
  3568. context._currentValue = nextValue;
  3569. {
  3570. if (context._currentRenderer !== undefined && context._currentRenderer !== null && context._currentRenderer !== rendererSigil) {
  3571. error('Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.');
  3572. }
  3573. context._currentRenderer = rendererSigil;
  3574. }
  3575. }
  3576. var prevNode = currentActiveSnapshot;
  3577. var newNode = {
  3578. parent: prevNode,
  3579. depth: prevNode === null ? 0 : prevNode.depth + 1,
  3580. context: context,
  3581. parentValue: prevValue,
  3582. value: nextValue
  3583. };
  3584. currentActiveSnapshot = newNode;
  3585. return newNode;
  3586. }
  3587. function popProvider(context) {
  3588. var prevSnapshot = currentActiveSnapshot;
  3589. if (prevSnapshot === null) {
  3590. throw new Error('Tried to pop a Context at the root of the app. This is a bug in React.');
  3591. }
  3592. {
  3593. if (prevSnapshot.context !== context) {
  3594. error('The parent context is not the expected context. This is probably a bug in React.');
  3595. }
  3596. }
  3597. {
  3598. var value = prevSnapshot.parentValue;
  3599. if (value === REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED) {
  3600. prevSnapshot.context._currentValue = prevSnapshot.context._defaultValue;
  3601. } else {
  3602. prevSnapshot.context._currentValue = value;
  3603. }
  3604. {
  3605. if (context._currentRenderer !== undefined && context._currentRenderer !== null && context._currentRenderer !== rendererSigil) {
  3606. error('Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.');
  3607. }
  3608. context._currentRenderer = rendererSigil;
  3609. }
  3610. }
  3611. return currentActiveSnapshot = prevSnapshot.parent;
  3612. }
  3613. function getActiveContext() {
  3614. return currentActiveSnapshot;
  3615. }
  3616. function readContext(context) {
  3617. var value = context._currentValue ;
  3618. return value;
  3619. }
  3620. /**
  3621. * `ReactInstanceMap` maintains a mapping from a public facing stateful
  3622. * instance (key) and the internal representation (value). This allows public
  3623. * methods to accept the user facing instance as an argument and map them back
  3624. * to internal methods.
  3625. *
  3626. * Note that this module is currently shared and assumed to be stateless.
  3627. * If this becomes an actual Map, that will break.
  3628. */
  3629. function get(key) {
  3630. return key._reactInternals;
  3631. }
  3632. function set(key, value) {
  3633. key._reactInternals = value;
  3634. }
  3635. var didWarnAboutNoopUpdateForComponent = {};
  3636. var didWarnAboutDeprecatedWillMount = {};
  3637. var didWarnAboutUninitializedState;
  3638. var didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate;
  3639. var didWarnAboutLegacyLifecyclesAndDerivedState;
  3640. var didWarnAboutUndefinedDerivedState;
  3641. var warnOnUndefinedDerivedState;
  3642. var warnOnInvalidCallback;
  3643. var didWarnAboutDirectlyAssigningPropsToState;
  3644. var didWarnAboutContextTypeAndContextTypes;
  3645. var didWarnAboutInvalidateContextType;
  3646. {
  3647. didWarnAboutUninitializedState = new Set();
  3648. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate = new Set();
  3649. didWarnAboutLegacyLifecyclesAndDerivedState = new Set();
  3650. didWarnAboutDirectlyAssigningPropsToState = new Set();
  3651. didWarnAboutUndefinedDerivedState = new Set();
  3652. didWarnAboutContextTypeAndContextTypes = new Set();
  3653. didWarnAboutInvalidateContextType = new Set();
  3654. var didWarnOnInvalidCallback = new Set();
  3655. warnOnInvalidCallback = function (callback, callerName) {
  3656. if (callback === null || typeof callback === 'function') {
  3657. return;
  3658. }
  3659. var key = callerName + '_' + callback;
  3660. if (!didWarnOnInvalidCallback.has(key)) {
  3661. didWarnOnInvalidCallback.add(key);
  3662. error('%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback);
  3663. }
  3664. };
  3665. warnOnUndefinedDerivedState = function (type, partialState) {
  3666. if (partialState === undefined) {
  3667. var componentName = getComponentNameFromType(type) || 'Component';
  3668. if (!didWarnAboutUndefinedDerivedState.has(componentName)) {
  3669. didWarnAboutUndefinedDerivedState.add(componentName);
  3670. error('%s.getDerivedStateFromProps(): A valid state object (or null) must be returned. ' + 'You have returned undefined.', componentName);
  3671. }
  3672. }
  3673. };
  3674. }
  3675. function warnNoop(publicInstance, callerName) {
  3676. {
  3677. var _constructor = publicInstance.constructor;
  3678. var componentName = _constructor && getComponentNameFromType(_constructor) || 'ReactClass';
  3679. var warningKey = componentName + '.' + callerName;
  3680. if (didWarnAboutNoopUpdateForComponent[warningKey]) {
  3681. return;
  3682. }
  3683. error('%s(...): Can only update a mounting component. ' + 'This usually means you called %s() outside componentWillMount() on the server. ' + 'This is a no-op.\n\nPlease check the code for the %s component.', callerName, callerName, componentName);
  3684. didWarnAboutNoopUpdateForComponent[warningKey] = true;
  3685. }
  3686. }
  3687. var classComponentUpdater = {
  3688. isMounted: function (inst) {
  3689. return false;
  3690. },
  3691. enqueueSetState: function (inst, payload, callback) {
  3692. var internals = get(inst);
  3693. if (internals.queue === null) {
  3694. warnNoop(inst, 'setState');
  3695. } else {
  3696. internals.queue.push(payload);
  3697. {
  3698. if (callback !== undefined && callback !== null) {
  3699. warnOnInvalidCallback(callback, 'setState');
  3700. }
  3701. }
  3702. }
  3703. },
  3704. enqueueReplaceState: function (inst, payload, callback) {
  3705. var internals = get(inst);
  3706. internals.replace = true;
  3707. internals.queue = [payload];
  3708. {
  3709. if (callback !== undefined && callback !== null) {
  3710. warnOnInvalidCallback(callback, 'setState');
  3711. }
  3712. }
  3713. },
  3714. enqueueForceUpdate: function (inst, callback) {
  3715. var internals = get(inst);
  3716. if (internals.queue === null) {
  3717. warnNoop(inst, 'forceUpdate');
  3718. } else {
  3719. {
  3720. if (callback !== undefined && callback !== null) {
  3721. warnOnInvalidCallback(callback, 'setState');
  3722. }
  3723. }
  3724. }
  3725. }
  3726. };
  3727. function applyDerivedStateFromProps(instance, ctor, getDerivedStateFromProps, prevState, nextProps) {
  3728. var partialState = getDerivedStateFromProps(nextProps, prevState);
  3729. {
  3730. warnOnUndefinedDerivedState(ctor, partialState);
  3731. } // Merge the partial state and the previous state.
  3732. var newState = partialState === null || partialState === undefined ? prevState : assign({}, prevState, partialState);
  3733. return newState;
  3734. }
  3735. function constructClassInstance(ctor, props, maskedLegacyContext) {
  3736. var context = emptyContextObject;
  3737. var contextType = ctor.contextType;
  3738. {
  3739. if ('contextType' in ctor) {
  3740. var isValid = // Allow null for conditional declaration
  3741. contextType === null || contextType !== undefined && contextType.$$typeof === REACT_CONTEXT_TYPE && contextType._context === undefined; // Not a <Context.Consumer>
  3742. if (!isValid && !didWarnAboutInvalidateContextType.has(ctor)) {
  3743. didWarnAboutInvalidateContextType.add(ctor);
  3744. var addendum = '';
  3745. if (contextType === undefined) {
  3746. 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.';
  3747. } else if (typeof contextType !== 'object') {
  3748. addendum = ' However, it is set to a ' + typeof contextType + '.';
  3749. } else if (contextType.$$typeof === REACT_PROVIDER_TYPE) {
  3750. addendum = ' Did you accidentally pass the Context.Provider instead?';
  3751. } else if (contextType._context !== undefined) {
  3752. // <Context.Consumer>
  3753. addendum = ' Did you accidentally pass the Context.Consumer instead?';
  3754. } else {
  3755. addendum = ' However, it is set to an object with keys {' + Object.keys(contextType).join(', ') + '}.';
  3756. }
  3757. error('%s defines an invalid contextType. ' + 'contextType should point to the Context object returned by React.createContext().%s', getComponentNameFromType(ctor) || 'Component', addendum);
  3758. }
  3759. }
  3760. }
  3761. if (typeof contextType === 'object' && contextType !== null) {
  3762. context = readContext(contextType);
  3763. } else {
  3764. context = maskedLegacyContext;
  3765. }
  3766. var instance = new ctor(props, context);
  3767. {
  3768. if (typeof ctor.getDerivedStateFromProps === 'function' && (instance.state === null || instance.state === undefined)) {
  3769. var componentName = getComponentNameFromType(ctor) || 'Component';
  3770. if (!didWarnAboutUninitializedState.has(componentName)) {
  3771. didWarnAboutUninitializedState.add(componentName);
  3772. 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);
  3773. }
  3774. } // If new component APIs are defined, "unsafe" lifecycles won't be called.
  3775. // Warn about these lifecycles if they are present.
  3776. // Don't warn about react-lifecycles-compat polyfilled methods though.
  3777. if (typeof ctor.getDerivedStateFromProps === 'function' || typeof instance.getSnapshotBeforeUpdate === 'function') {
  3778. var foundWillMountName = null;
  3779. var foundWillReceivePropsName = null;
  3780. var foundWillUpdateName = null;
  3781. if (typeof instance.componentWillMount === 'function' && instance.componentWillMount.__suppressDeprecationWarning !== true) {
  3782. foundWillMountName = 'componentWillMount';
  3783. } else if (typeof instance.UNSAFE_componentWillMount === 'function') {
  3784. foundWillMountName = 'UNSAFE_componentWillMount';
  3785. }
  3786. if (typeof instance.componentWillReceiveProps === 'function' && instance.componentWillReceiveProps.__suppressDeprecationWarning !== true) {
  3787. foundWillReceivePropsName = 'componentWillReceiveProps';
  3788. } else if (typeof instance.UNSAFE_componentWillReceiveProps === 'function') {
  3789. foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
  3790. }
  3791. if (typeof instance.componentWillUpdate === 'function' && instance.componentWillUpdate.__suppressDeprecationWarning !== true) {
  3792. foundWillUpdateName = 'componentWillUpdate';
  3793. } else if (typeof instance.UNSAFE_componentWillUpdate === 'function') {
  3794. foundWillUpdateName = 'UNSAFE_componentWillUpdate';
  3795. }
  3796. if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
  3797. var _componentName = getComponentNameFromType(ctor) || 'Component';
  3798. var newApiName = typeof ctor.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
  3799. if (!didWarnAboutLegacyLifecyclesAndDerivedState.has(_componentName)) {
  3800. didWarnAboutLegacyLifecyclesAndDerivedState.add(_componentName);
  3801. 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 : '');
  3802. }
  3803. }
  3804. }
  3805. }
  3806. return instance;
  3807. }
  3808. function checkClassInstance(instance, ctor, newProps) {
  3809. {
  3810. var name = getComponentNameFromType(ctor) || 'Component';
  3811. var renderPresent = instance.render;
  3812. if (!renderPresent) {
  3813. if (ctor.prototype && typeof ctor.prototype.render === 'function') {
  3814. error('%s(...): No `render` method found on the returned component ' + 'instance: did you accidentally return an object from the constructor?', name);
  3815. } else {
  3816. error('%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', name);
  3817. }
  3818. }
  3819. if (instance.getInitialState && !instance.getInitialState.isReactClassApproved && !instance.state) {
  3820. 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);
  3821. }
  3822. if (instance.getDefaultProps && !instance.getDefaultProps.isReactClassApproved) {
  3823. 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);
  3824. }
  3825. if (instance.propTypes) {
  3826. error('propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', name);
  3827. }
  3828. if (instance.contextType) {
  3829. error('contextType was defined as an instance property on %s. Use a static ' + 'property to define contextType instead.', name);
  3830. }
  3831. {
  3832. if (instance.contextTypes) {
  3833. error('contextTypes was defined as an instance property on %s. Use a static ' + 'property to define contextTypes instead.', name);
  3834. }
  3835. if (ctor.contextType && ctor.contextTypes && !didWarnAboutContextTypeAndContextTypes.has(ctor)) {
  3836. didWarnAboutContextTypeAndContextTypes.add(ctor);
  3837. error('%s declares both contextTypes and contextType static properties. ' + 'The legacy contextTypes property will be ignored.', name);
  3838. }
  3839. }
  3840. if (typeof instance.componentShouldUpdate === 'function') {
  3841. 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);
  3842. }
  3843. if (ctor.prototype && ctor.prototype.isPureReactComponent && typeof instance.shouldComponentUpdate !== 'undefined') {
  3844. error('%s has a method called shouldComponentUpdate(). ' + 'shouldComponentUpdate should not be used when extending React.PureComponent. ' + 'Please extend React.Component if shouldComponentUpdate is used.', getComponentNameFromType(ctor) || 'A pure component');
  3845. }
  3846. if (typeof instance.componentDidUnmount === 'function') {
  3847. error('%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', name);
  3848. }
  3849. if (typeof instance.componentDidReceiveProps === 'function') {
  3850. 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);
  3851. }
  3852. if (typeof instance.componentWillRecieveProps === 'function') {
  3853. error('%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', name);
  3854. }
  3855. if (typeof instance.UNSAFE_componentWillRecieveProps === 'function') {
  3856. error('%s has a method called ' + 'UNSAFE_componentWillRecieveProps(). Did you mean UNSAFE_componentWillReceiveProps()?', name);
  3857. }
  3858. var hasMutatedProps = instance.props !== newProps;
  3859. if (instance.props !== undefined && hasMutatedProps) {
  3860. error('%s(...): When calling super() in `%s`, make sure to pass ' + "up the same props that your component's constructor was passed.", name, name);
  3861. }
  3862. if (instance.defaultProps) {
  3863. 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);
  3864. }
  3865. if (typeof instance.getSnapshotBeforeUpdate === 'function' && typeof instance.componentDidUpdate !== 'function' && !didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.has(ctor)) {
  3866. didWarnAboutGetSnapshotBeforeUpdateWithoutDidUpdate.add(ctor);
  3867. error('%s: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). ' + 'This component defines getSnapshotBeforeUpdate() only.', getComponentNameFromType(ctor));
  3868. }
  3869. if (typeof instance.getDerivedStateFromProps === 'function') {
  3870. error('%s: getDerivedStateFromProps() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name);
  3871. }
  3872. if (typeof instance.getDerivedStateFromError === 'function') {
  3873. error('%s: getDerivedStateFromError() is defined as an instance method ' + 'and will be ignored. Instead, declare it as a static method.', name);
  3874. }
  3875. if (typeof ctor.getSnapshotBeforeUpdate === 'function') {
  3876. error('%s: getSnapshotBeforeUpdate() is defined as a static method ' + 'and will be ignored. Instead, declare it as an instance method.', name);
  3877. }
  3878. var _state = instance.state;
  3879. if (_state && (typeof _state !== 'object' || isArray(_state))) {
  3880. error('%s.state: must be set to an object or null', name);
  3881. }
  3882. if (typeof instance.getChildContext === 'function' && typeof ctor.childContextTypes !== 'object') {
  3883. error('%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', name);
  3884. }
  3885. }
  3886. }
  3887. function callComponentWillMount(type, instance) {
  3888. var oldState = instance.state;
  3889. if (typeof instance.componentWillMount === 'function') {
  3890. {
  3891. if ( instance.componentWillMount.__suppressDeprecationWarning !== true) {
  3892. var componentName = getComponentNameFromType(type) || 'Unknown';
  3893. if (!didWarnAboutDeprecatedWillMount[componentName]) {
  3894. warn( // keep this warning in sync with ReactStrictModeWarning.js
  3895. 'componentWillMount has been renamed, and is not recommended for use. ' + 'See https://reactjs.org/link/unsafe-component-lifecycles for details.\n\n' + '* Move code from componentWillMount to componentDidMount (preferred in most cases) ' + 'or the constructor.\n' + '\nPlease update the following components: %s', componentName);
  3896. didWarnAboutDeprecatedWillMount[componentName] = true;
  3897. }
  3898. }
  3899. }
  3900. instance.componentWillMount();
  3901. }
  3902. if (typeof instance.UNSAFE_componentWillMount === 'function') {
  3903. instance.UNSAFE_componentWillMount();
  3904. }
  3905. if (oldState !== instance.state) {
  3906. {
  3907. error('%s.componentWillMount(): Assigning directly to this.state is ' + "deprecated (except inside a component's " + 'constructor). Use setState instead.', getComponentNameFromType(type) || 'Component');
  3908. }
  3909. classComponentUpdater.enqueueReplaceState(instance, instance.state, null);
  3910. }
  3911. }
  3912. function processUpdateQueue(internalInstance, inst, props, maskedLegacyContext) {
  3913. if (internalInstance.queue !== null && internalInstance.queue.length > 0) {
  3914. var oldQueue = internalInstance.queue;
  3915. var oldReplace = internalInstance.replace;
  3916. internalInstance.queue = null;
  3917. internalInstance.replace = false;
  3918. if (oldReplace && oldQueue.length === 1) {
  3919. inst.state = oldQueue[0];
  3920. } else {
  3921. var nextState = oldReplace ? oldQueue[0] : inst.state;
  3922. var dontMutate = true;
  3923. for (var i = oldReplace ? 1 : 0; i < oldQueue.length; i++) {
  3924. var partial = oldQueue[i];
  3925. var partialState = typeof partial === 'function' ? partial.call(inst, nextState, props, maskedLegacyContext) : partial;
  3926. if (partialState != null) {
  3927. if (dontMutate) {
  3928. dontMutate = false;
  3929. nextState = assign({}, nextState, partialState);
  3930. } else {
  3931. assign(nextState, partialState);
  3932. }
  3933. }
  3934. }
  3935. inst.state = nextState;
  3936. }
  3937. } else {
  3938. internalInstance.queue = null;
  3939. }
  3940. } // Invokes the mount life-cycles on a previously never rendered instance.
  3941. function mountClassInstance(instance, ctor, newProps, maskedLegacyContext) {
  3942. {
  3943. checkClassInstance(instance, ctor, newProps);
  3944. }
  3945. var initialState = instance.state !== undefined ? instance.state : null;
  3946. instance.updater = classComponentUpdater;
  3947. instance.props = newProps;
  3948. instance.state = initialState; // We don't bother initializing the refs object on the server, since we're not going to resolve them anyway.
  3949. // The internal instance will be used to manage updates that happen during this mount.
  3950. var internalInstance = {
  3951. queue: [],
  3952. replace: false
  3953. };
  3954. set(instance, internalInstance);
  3955. var contextType = ctor.contextType;
  3956. if (typeof contextType === 'object' && contextType !== null) {
  3957. instance.context = readContext(contextType);
  3958. } else {
  3959. instance.context = maskedLegacyContext;
  3960. }
  3961. {
  3962. if (instance.state === newProps) {
  3963. var componentName = getComponentNameFromType(ctor) || 'Component';
  3964. if (!didWarnAboutDirectlyAssigningPropsToState.has(componentName)) {
  3965. didWarnAboutDirectlyAssigningPropsToState.add(componentName);
  3966. 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);
  3967. }
  3968. }
  3969. }
  3970. var getDerivedStateFromProps = ctor.getDerivedStateFromProps;
  3971. if (typeof getDerivedStateFromProps === 'function') {
  3972. instance.state = applyDerivedStateFromProps(instance, ctor, getDerivedStateFromProps, initialState, newProps);
  3973. } // In order to support react-lifecycles-compat polyfilled components,
  3974. // Unsafe lifecycles should not be invoked for components using the new APIs.
  3975. if (typeof ctor.getDerivedStateFromProps !== 'function' && typeof instance.getSnapshotBeforeUpdate !== 'function' && (typeof instance.UNSAFE_componentWillMount === 'function' || typeof instance.componentWillMount === 'function')) {
  3976. callComponentWillMount(ctor, instance); // If we had additional state updates during this life-cycle, let's
  3977. // process them now.
  3978. processUpdateQueue(internalInstance, instance, newProps, maskedLegacyContext);
  3979. }
  3980. }
  3981. // Ids are base 32 strings whose binary representation corresponds to the
  3982. // position of a node in a tree.
  3983. // Every time the tree forks into multiple children, we add additional bits to
  3984. // the left of the sequence that represent the position of the child within the
  3985. // current level of children.
  3986. //
  3987. // 00101 00010001011010101
  3988. // ╰─┬─╯ ╰───────┬───────╯
  3989. // Fork 5 of 20 Parent id
  3990. //
  3991. // The leading 0s are important. In the above example, you only need 3 bits to
  3992. // represent slot 5. However, you need 5 bits to represent all the forks at
  3993. // the current level, so we must account for the empty bits at the end.
  3994. //
  3995. // For this same reason, slots are 1-indexed instead of 0-indexed. Otherwise,
  3996. // the zeroth id at a level would be indistinguishable from its parent.
  3997. //
  3998. // If a node has only one child, and does not materialize an id (i.e. does not
  3999. // contain a useId hook), then we don't need to allocate any space in the
  4000. // sequence. It's treated as a transparent indirection. For example, these two
  4001. // trees produce the same ids:
  4002. //
  4003. // <> <>
  4004. // <Indirection> <A />
  4005. // <A /> <B />
  4006. // </Indirection> </>
  4007. // <B />
  4008. // </>
  4009. //
  4010. // However, we cannot skip any node that materializes an id. Otherwise, a parent
  4011. // id that does not fork would be indistinguishable from its child id. For
  4012. // example, this tree does not fork, but the parent and child must have
  4013. // different ids.
  4014. //
  4015. // <Parent>
  4016. // <Child />
  4017. // </Parent>
  4018. //
  4019. // To handle this scenario, every time we materialize an id, we allocate a
  4020. // new level with a single slot. You can think of this as a fork with only one
  4021. // prong, or an array of children with length 1.
  4022. //
  4023. // It's possible for the size of the sequence to exceed 32 bits, the max
  4024. // size for bitwise operations. When this happens, we make more room by
  4025. // converting the right part of the id to a string and storing it in an overflow
  4026. // variable. We use a base 32 string representation, because 32 is the largest
  4027. // power of 2 that is supported by toString(). We want the base to be large so
  4028. // that the resulting ids are compact, and we want the base to be a power of 2
  4029. // because every log2(base) bits corresponds to a single character, i.e. every
  4030. // log2(32) = 5 bits. That means we can lop bits off the end 5 at a time without
  4031. // affecting the final result.
  4032. var emptyTreeContext = {
  4033. id: 1,
  4034. overflow: ''
  4035. };
  4036. function getTreeId(context) {
  4037. var overflow = context.overflow;
  4038. var idWithLeadingBit = context.id;
  4039. var id = idWithLeadingBit & ~getLeadingBit(idWithLeadingBit);
  4040. return id.toString(32) + overflow;
  4041. }
  4042. function pushTreeContext(baseContext, totalChildren, index) {
  4043. var baseIdWithLeadingBit = baseContext.id;
  4044. var baseOverflow = baseContext.overflow; // The leftmost 1 marks the end of the sequence, non-inclusive. It's not part
  4045. // of the id; we use it to account for leading 0s.
  4046. var baseLength = getBitLength(baseIdWithLeadingBit) - 1;
  4047. var baseId = baseIdWithLeadingBit & ~(1 << baseLength);
  4048. var slot = index + 1;
  4049. var length = getBitLength(totalChildren) + baseLength; // 30 is the max length we can store without overflowing, taking into
  4050. // consideration the leading 1 we use to mark the end of the sequence.
  4051. if (length > 30) {
  4052. // We overflowed the bitwise-safe range. Fall back to slower algorithm.
  4053. // This branch assumes the length of the base id is greater than 5; it won't
  4054. // work for smaller ids, because you need 5 bits per character.
  4055. //
  4056. // We encode the id in multiple steps: first the base id, then the
  4057. // remaining digits.
  4058. //
  4059. // Each 5 bit sequence corresponds to a single base 32 character. So for
  4060. // example, if the current id is 23 bits long, we can convert 20 of those
  4061. // bits into a string of 4 characters, with 3 bits left over.
  4062. //
  4063. // First calculate how many bits in the base id represent a complete
  4064. // sequence of characters.
  4065. var numberOfOverflowBits = baseLength - baseLength % 5; // Then create a bitmask that selects only those bits.
  4066. var newOverflowBits = (1 << numberOfOverflowBits) - 1; // Select the bits, and convert them to a base 32 string.
  4067. var newOverflow = (baseId & newOverflowBits).toString(32); // Now we can remove those bits from the base id.
  4068. var restOfBaseId = baseId >> numberOfOverflowBits;
  4069. var restOfBaseLength = baseLength - numberOfOverflowBits; // Finally, encode the rest of the bits using the normal algorithm. Because
  4070. // we made more room, this time it won't overflow.
  4071. var restOfLength = getBitLength(totalChildren) + restOfBaseLength;
  4072. var restOfNewBits = slot << restOfBaseLength;
  4073. var id = restOfNewBits | restOfBaseId;
  4074. var overflow = newOverflow + baseOverflow;
  4075. return {
  4076. id: 1 << restOfLength | id,
  4077. overflow: overflow
  4078. };
  4079. } else {
  4080. // Normal path
  4081. var newBits = slot << baseLength;
  4082. var _id = newBits | baseId;
  4083. var _overflow = baseOverflow;
  4084. return {
  4085. id: 1 << length | _id,
  4086. overflow: _overflow
  4087. };
  4088. }
  4089. }
  4090. function getBitLength(number) {
  4091. return 32 - clz32(number);
  4092. }
  4093. function getLeadingBit(id) {
  4094. return 1 << getBitLength(id) - 1;
  4095. } // TODO: Math.clz32 is supported in Node 12+. Maybe we can drop the fallback.
  4096. var clz32 = Math.clz32 ? Math.clz32 : clz32Fallback; // Count leading zeros.
  4097. // Based on:
  4098. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
  4099. var log = Math.log;
  4100. var LN2 = Math.LN2;
  4101. function clz32Fallback(x) {
  4102. var asUint = x >>> 0;
  4103. if (asUint === 0) {
  4104. return 32;
  4105. }
  4106. return 31 - (log(asUint) / LN2 | 0) | 0;
  4107. }
  4108. /**
  4109. * inlined Object.is polyfill to avoid requiring consumers ship their own
  4110. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  4111. */
  4112. function is(x, y) {
  4113. return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
  4114. ;
  4115. }
  4116. var objectIs = typeof Object.is === 'function' ? Object.is : is;
  4117. var currentlyRenderingComponent = null;
  4118. var currentlyRenderingTask = null;
  4119. var firstWorkInProgressHook = null;
  4120. var workInProgressHook = null; // Whether the work-in-progress hook is a re-rendered hook
  4121. var isReRender = false; // Whether an update was scheduled during the currently executing render pass.
  4122. var didScheduleRenderPhaseUpdate = false; // Counts the number of useId hooks in this component
  4123. var localIdCounter = 0; // Lazily created map of render-phase updates
  4124. var renderPhaseUpdates = null; // Counter to prevent infinite loops.
  4125. var numberOfReRenders = 0;
  4126. var RE_RENDER_LIMIT = 25;
  4127. var isInHookUserCodeInDev = false; // In DEV, this is the name of the currently executing primitive hook
  4128. var currentHookNameInDev;
  4129. function resolveCurrentlyRenderingComponent() {
  4130. if (currentlyRenderingComponent === null) {
  4131. throw new 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:\n' + '1. You might have mismatching versions of React and the renderer (such as React DOM)\n' + '2. You might be breaking the Rules of Hooks\n' + '3. You might have more than one copy of React in the same app\n' + 'See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.');
  4132. }
  4133. {
  4134. if (isInHookUserCodeInDev) {
  4135. 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');
  4136. }
  4137. }
  4138. return currentlyRenderingComponent;
  4139. }
  4140. function areHookInputsEqual(nextDeps, prevDeps) {
  4141. if (prevDeps === null) {
  4142. {
  4143. 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);
  4144. }
  4145. return false;
  4146. }
  4147. {
  4148. // Don't bother comparing lengths in prod because these arrays should be
  4149. // passed inline.
  4150. if (nextDeps.length !== prevDeps.length) {
  4151. 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, "[" + nextDeps.join(', ') + "]", "[" + prevDeps.join(', ') + "]");
  4152. }
  4153. }
  4154. for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) {
  4155. if (objectIs(nextDeps[i], prevDeps[i])) {
  4156. continue;
  4157. }
  4158. return false;
  4159. }
  4160. return true;
  4161. }
  4162. function createHook() {
  4163. if (numberOfReRenders > 0) {
  4164. throw new Error('Rendered more hooks than during the previous render');
  4165. }
  4166. return {
  4167. memoizedState: null,
  4168. queue: null,
  4169. next: null
  4170. };
  4171. }
  4172. function createWorkInProgressHook() {
  4173. if (workInProgressHook === null) {
  4174. // This is the first hook in the list
  4175. if (firstWorkInProgressHook === null) {
  4176. isReRender = false;
  4177. firstWorkInProgressHook = workInProgressHook = createHook();
  4178. } else {
  4179. // There's already a work-in-progress. Reuse it.
  4180. isReRender = true;
  4181. workInProgressHook = firstWorkInProgressHook;
  4182. }
  4183. } else {
  4184. if (workInProgressHook.next === null) {
  4185. isReRender = false; // Append to the end of the list
  4186. workInProgressHook = workInProgressHook.next = createHook();
  4187. } else {
  4188. // There's already a work-in-progress. Reuse it.
  4189. isReRender = true;
  4190. workInProgressHook = workInProgressHook.next;
  4191. }
  4192. }
  4193. return workInProgressHook;
  4194. }
  4195. function prepareToUseHooks(task, componentIdentity) {
  4196. currentlyRenderingComponent = componentIdentity;
  4197. currentlyRenderingTask = task;
  4198. {
  4199. isInHookUserCodeInDev = false;
  4200. } // The following should have already been reset
  4201. // didScheduleRenderPhaseUpdate = false;
  4202. // localIdCounter = 0;
  4203. // firstWorkInProgressHook = null;
  4204. // numberOfReRenders = 0;
  4205. // renderPhaseUpdates = null;
  4206. // workInProgressHook = null;
  4207. localIdCounter = 0;
  4208. }
  4209. function finishHooks(Component, props, children, refOrContext) {
  4210. // This must be called after every function component to prevent hooks from
  4211. // being used in classes.
  4212. while (didScheduleRenderPhaseUpdate) {
  4213. // Updates were scheduled during the render phase. They are stored in
  4214. // the `renderPhaseUpdates` map. Call the component again, reusing the
  4215. // work-in-progress hooks and applying the additional updates on top. Keep
  4216. // restarting until no more updates are scheduled.
  4217. didScheduleRenderPhaseUpdate = false;
  4218. localIdCounter = 0;
  4219. numberOfReRenders += 1; // Start over from the beginning of the list
  4220. workInProgressHook = null;
  4221. children = Component(props, refOrContext);
  4222. }
  4223. resetHooksState();
  4224. return children;
  4225. }
  4226. function checkDidRenderIdHook() {
  4227. // This should be called immediately after every finishHooks call.
  4228. // Conceptually, it's part of the return value of finishHooks; it's only a
  4229. // separate function to avoid using an array tuple.
  4230. var didRenderIdHook = localIdCounter !== 0;
  4231. return didRenderIdHook;
  4232. } // Reset the internal hooks state if an error occurs while rendering a component
  4233. function resetHooksState() {
  4234. {
  4235. isInHookUserCodeInDev = false;
  4236. }
  4237. currentlyRenderingComponent = null;
  4238. currentlyRenderingTask = null;
  4239. didScheduleRenderPhaseUpdate = false;
  4240. firstWorkInProgressHook = null;
  4241. numberOfReRenders = 0;
  4242. renderPhaseUpdates = null;
  4243. workInProgressHook = null;
  4244. }
  4245. function readContext$1(context) {
  4246. {
  4247. if (isInHookUserCodeInDev) {
  4248. 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().');
  4249. }
  4250. }
  4251. return readContext(context);
  4252. }
  4253. function useContext(context) {
  4254. {
  4255. currentHookNameInDev = 'useContext';
  4256. }
  4257. resolveCurrentlyRenderingComponent();
  4258. return readContext(context);
  4259. }
  4260. function basicStateReducer(state, action) {
  4261. // $FlowFixMe: Flow doesn't like mixed types
  4262. return typeof action === 'function' ? action(state) : action;
  4263. }
  4264. function useState(initialState) {
  4265. {
  4266. currentHookNameInDev = 'useState';
  4267. }
  4268. return useReducer(basicStateReducer, // useReducer has a special case to support lazy useState initializers
  4269. initialState);
  4270. }
  4271. function useReducer(reducer, initialArg, init) {
  4272. {
  4273. if (reducer !== basicStateReducer) {
  4274. currentHookNameInDev = 'useReducer';
  4275. }
  4276. }
  4277. currentlyRenderingComponent = resolveCurrentlyRenderingComponent();
  4278. workInProgressHook = createWorkInProgressHook();
  4279. if (isReRender) {
  4280. // This is a re-render. Apply the new render phase updates to the previous
  4281. // current hook.
  4282. var queue = workInProgressHook.queue;
  4283. var dispatch = queue.dispatch;
  4284. if (renderPhaseUpdates !== null) {
  4285. // Render phase updates are stored in a map of queue -> linked list
  4286. var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
  4287. if (firstRenderPhaseUpdate !== undefined) {
  4288. renderPhaseUpdates.delete(queue);
  4289. var newState = workInProgressHook.memoizedState;
  4290. var update = firstRenderPhaseUpdate;
  4291. do {
  4292. // Process this render phase update. We don't have to check the
  4293. // priority because it will always be the same as the current
  4294. // render's.
  4295. var action = update.action;
  4296. {
  4297. isInHookUserCodeInDev = true;
  4298. }
  4299. newState = reducer(newState, action);
  4300. {
  4301. isInHookUserCodeInDev = false;
  4302. }
  4303. update = update.next;
  4304. } while (update !== null);
  4305. workInProgressHook.memoizedState = newState;
  4306. return [newState, dispatch];
  4307. }
  4308. }
  4309. return [workInProgressHook.memoizedState, dispatch];
  4310. } else {
  4311. {
  4312. isInHookUserCodeInDev = true;
  4313. }
  4314. var initialState;
  4315. if (reducer === basicStateReducer) {
  4316. // Special case for `useState`.
  4317. initialState = typeof initialArg === 'function' ? initialArg() : initialArg;
  4318. } else {
  4319. initialState = init !== undefined ? init(initialArg) : initialArg;
  4320. }
  4321. {
  4322. isInHookUserCodeInDev = false;
  4323. }
  4324. workInProgressHook.memoizedState = initialState;
  4325. var _queue = workInProgressHook.queue = {
  4326. last: null,
  4327. dispatch: null
  4328. };
  4329. var _dispatch = _queue.dispatch = dispatchAction.bind(null, currentlyRenderingComponent, _queue);
  4330. return [workInProgressHook.memoizedState, _dispatch];
  4331. }
  4332. }
  4333. function useMemo(nextCreate, deps) {
  4334. currentlyRenderingComponent = resolveCurrentlyRenderingComponent();
  4335. workInProgressHook = createWorkInProgressHook();
  4336. var nextDeps = deps === undefined ? null : deps;
  4337. if (workInProgressHook !== null) {
  4338. var prevState = workInProgressHook.memoizedState;
  4339. if (prevState !== null) {
  4340. if (nextDeps !== null) {
  4341. var prevDeps = prevState[1];
  4342. if (areHookInputsEqual(nextDeps, prevDeps)) {
  4343. return prevState[0];
  4344. }
  4345. }
  4346. }
  4347. }
  4348. {
  4349. isInHookUserCodeInDev = true;
  4350. }
  4351. var nextValue = nextCreate();
  4352. {
  4353. isInHookUserCodeInDev = false;
  4354. }
  4355. workInProgressHook.memoizedState = [nextValue, nextDeps];
  4356. return nextValue;
  4357. }
  4358. function useRef(initialValue) {
  4359. currentlyRenderingComponent = resolveCurrentlyRenderingComponent();
  4360. workInProgressHook = createWorkInProgressHook();
  4361. var previousRef = workInProgressHook.memoizedState;
  4362. if (previousRef === null) {
  4363. var ref = {
  4364. current: initialValue
  4365. };
  4366. {
  4367. Object.seal(ref);
  4368. }
  4369. workInProgressHook.memoizedState = ref;
  4370. return ref;
  4371. } else {
  4372. return previousRef;
  4373. }
  4374. }
  4375. function useLayoutEffect(create, inputs) {
  4376. {
  4377. currentHookNameInDev = 'useLayoutEffect';
  4378. error('useLayoutEffect does nothing on the server, because its effect cannot ' + "be encoded into the server renderer's output format. This will lead " + 'to a mismatch between the initial, non-hydrated UI and the intended ' + 'UI. To avoid this, useLayoutEffect should only be used in ' + 'components that render exclusively on the client. ' + 'See https://reactjs.org/link/uselayouteffect-ssr for common fixes.');
  4379. }
  4380. }
  4381. function dispatchAction(componentIdentity, queue, action) {
  4382. if (numberOfReRenders >= RE_RENDER_LIMIT) {
  4383. throw new Error('Too many re-renders. React limits the number of renders to prevent ' + 'an infinite loop.');
  4384. }
  4385. if (componentIdentity === currentlyRenderingComponent) {
  4386. // This is a render phase update. Stash it in a lazily-created map of
  4387. // queue -> linked list of updates. After this render pass, we'll restart
  4388. // and apply the stashed updates on top of the work-in-progress hook.
  4389. didScheduleRenderPhaseUpdate = true;
  4390. var update = {
  4391. action: action,
  4392. next: null
  4393. };
  4394. if (renderPhaseUpdates === null) {
  4395. renderPhaseUpdates = new Map();
  4396. }
  4397. var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
  4398. if (firstRenderPhaseUpdate === undefined) {
  4399. renderPhaseUpdates.set(queue, update);
  4400. } else {
  4401. // Append the update to the end of the list.
  4402. var lastRenderPhaseUpdate = firstRenderPhaseUpdate;
  4403. while (lastRenderPhaseUpdate.next !== null) {
  4404. lastRenderPhaseUpdate = lastRenderPhaseUpdate.next;
  4405. }
  4406. lastRenderPhaseUpdate.next = update;
  4407. }
  4408. }
  4409. }
  4410. function useCallback(callback, deps) {
  4411. return useMemo(function () {
  4412. return callback;
  4413. }, deps);
  4414. } // TODO Decide on how to implement this hook for server rendering.
  4415. // If a mutation occurs during render, consider triggering a Suspense boundary
  4416. // and falling back to client rendering.
  4417. function useMutableSource(source, getSnapshot, subscribe) {
  4418. resolveCurrentlyRenderingComponent();
  4419. return getSnapshot(source._source);
  4420. }
  4421. function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
  4422. if (getServerSnapshot === undefined) {
  4423. throw new Error('Missing getServerSnapshot, which is required for ' + 'server-rendered content. Will revert to client rendering.');
  4424. }
  4425. return getServerSnapshot();
  4426. }
  4427. function useDeferredValue(value) {
  4428. resolveCurrentlyRenderingComponent();
  4429. return value;
  4430. }
  4431. function unsupportedStartTransition() {
  4432. throw new Error('startTransition cannot be called during server rendering.');
  4433. }
  4434. function useTransition() {
  4435. resolveCurrentlyRenderingComponent();
  4436. return [false, unsupportedStartTransition];
  4437. }
  4438. function useId() {
  4439. var task = currentlyRenderingTask;
  4440. var treeId = getTreeId(task.treeContext);
  4441. var responseState = currentResponseState;
  4442. if (responseState === null) {
  4443. throw new Error('Invalid hook call. Hooks can only be called inside of the body of a function component.');
  4444. }
  4445. var localId = localIdCounter++;
  4446. return makeId(responseState, treeId, localId);
  4447. }
  4448. function noop() {}
  4449. var Dispatcher = {
  4450. readContext: readContext$1,
  4451. useContext: useContext,
  4452. useMemo: useMemo,
  4453. useReducer: useReducer,
  4454. useRef: useRef,
  4455. useState: useState,
  4456. useInsertionEffect: noop,
  4457. useLayoutEffect: useLayoutEffect,
  4458. useCallback: useCallback,
  4459. // useImperativeHandle is not run in the server environment
  4460. useImperativeHandle: noop,
  4461. // Effects are not run in the server environment.
  4462. useEffect: noop,
  4463. // Debugging effect
  4464. useDebugValue: noop,
  4465. useDeferredValue: useDeferredValue,
  4466. useTransition: useTransition,
  4467. useId: useId,
  4468. // Subscriptions are not setup in a server environment.
  4469. useMutableSource: useMutableSource,
  4470. useSyncExternalStore: useSyncExternalStore
  4471. };
  4472. var currentResponseState = null;
  4473. function setCurrentResponseState(responseState) {
  4474. currentResponseState = responseState;
  4475. }
  4476. function getStackByComponentStackNode(componentStack) {
  4477. try {
  4478. var info = '';
  4479. var node = componentStack;
  4480. do {
  4481. switch (node.tag) {
  4482. case 0:
  4483. info += describeBuiltInComponentFrame(node.type, null, null);
  4484. break;
  4485. case 1:
  4486. info += describeFunctionComponentFrame(node.type, null, null);
  4487. break;
  4488. case 2:
  4489. info += describeClassComponentFrame(node.type, null, null);
  4490. break;
  4491. }
  4492. node = node.parent;
  4493. } while (node);
  4494. return info;
  4495. } catch (x) {
  4496. return '\nError generating stack: ' + x.message + '\n' + x.stack;
  4497. }
  4498. }
  4499. var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher;
  4500. var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
  4501. var PENDING = 0;
  4502. var COMPLETED = 1;
  4503. var FLUSHED = 2;
  4504. var ABORTED = 3;
  4505. var ERRORED = 4;
  4506. var OPEN = 0;
  4507. var CLOSING = 1;
  4508. var CLOSED = 2;
  4509. // This is a default heuristic for how to split up the HTML content into progressive
  4510. // loading. Our goal is to be able to display additional new content about every 500ms.
  4511. // Faster than that is unnecessary and should be throttled on the client. It also
  4512. // adds unnecessary overhead to do more splits. We don't know if it's a higher or lower
  4513. // end device but higher end suffer less from the overhead than lower end does from
  4514. // not getting small enough pieces. We error on the side of low end.
  4515. // We base this on low end 3G speeds which is about 500kbits per second. We assume
  4516. // that there can be a reasonable drop off from max bandwidth which leaves you with
  4517. // as little as 80%. We can receive half of that each 500ms - at best. In practice,
  4518. // a little bandwidth is lost to processing and contention - e.g. CSS and images that
  4519. // are downloaded along with the main content. So we estimate about half of that to be
  4520. // the lower end throughput. In other words, we expect that you can at least show
  4521. // about 12.5kb of content per 500ms. Not counting starting latency for the first
  4522. // paint.
  4523. // 500 * 1024 / 8 * .8 * 0.5 / 2
  4524. var DEFAULT_PROGRESSIVE_CHUNK_SIZE = 12800;
  4525. function defaultErrorHandler(error) {
  4526. console['error'](error); // Don't transform to our wrapper
  4527. return null;
  4528. }
  4529. function noop$1() {}
  4530. function createRequest(children, responseState, rootFormatContext, progressiveChunkSize, onError, onAllReady, onShellReady, onShellError, onFatalError) {
  4531. var pingedTasks = [];
  4532. var abortSet = new Set();
  4533. var request = {
  4534. destination: null,
  4535. responseState: responseState,
  4536. progressiveChunkSize: progressiveChunkSize === undefined ? DEFAULT_PROGRESSIVE_CHUNK_SIZE : progressiveChunkSize,
  4537. status: OPEN,
  4538. fatalError: null,
  4539. nextSegmentId: 0,
  4540. allPendingTasks: 0,
  4541. pendingRootTasks: 0,
  4542. completedRootSegment: null,
  4543. abortableTasks: abortSet,
  4544. pingedTasks: pingedTasks,
  4545. clientRenderedBoundaries: [],
  4546. completedBoundaries: [],
  4547. partialBoundaries: [],
  4548. onError: onError === undefined ? defaultErrorHandler : onError,
  4549. onAllReady: onAllReady === undefined ? noop$1 : onAllReady,
  4550. onShellReady: onShellReady === undefined ? noop$1 : onShellReady,
  4551. onShellError: onShellError === undefined ? noop$1 : onShellError,
  4552. onFatalError: onFatalError === undefined ? noop$1 : onFatalError
  4553. }; // This segment represents the root fallback.
  4554. var rootSegment = createPendingSegment(request, 0, null, rootFormatContext, // Root segments are never embedded in Text on either edge
  4555. false, false); // There is no parent so conceptually, we're unblocked to flush this segment.
  4556. rootSegment.parentFlushed = true;
  4557. var rootTask = createTask(request, children, null, rootSegment, abortSet, emptyContextObject, rootContextSnapshot, emptyTreeContext);
  4558. pingedTasks.push(rootTask);
  4559. return request;
  4560. }
  4561. function pingTask(request, task) {
  4562. var pingedTasks = request.pingedTasks;
  4563. pingedTasks.push(task);
  4564. if (pingedTasks.length === 1) {
  4565. scheduleWork(function () {
  4566. return performWork(request);
  4567. });
  4568. }
  4569. }
  4570. function createSuspenseBoundary(request, fallbackAbortableTasks) {
  4571. return {
  4572. id: UNINITIALIZED_SUSPENSE_BOUNDARY_ID,
  4573. rootSegmentID: -1,
  4574. parentFlushed: false,
  4575. pendingTasks: 0,
  4576. forceClientRender: false,
  4577. completedSegments: [],
  4578. byteSize: 0,
  4579. fallbackAbortableTasks: fallbackAbortableTasks,
  4580. errorDigest: null
  4581. };
  4582. }
  4583. function createTask(request, node, blockedBoundary, blockedSegment, abortSet, legacyContext, context, treeContext) {
  4584. request.allPendingTasks++;
  4585. if (blockedBoundary === null) {
  4586. request.pendingRootTasks++;
  4587. } else {
  4588. blockedBoundary.pendingTasks++;
  4589. }
  4590. var task = {
  4591. node: node,
  4592. ping: function () {
  4593. return pingTask(request, task);
  4594. },
  4595. blockedBoundary: blockedBoundary,
  4596. blockedSegment: blockedSegment,
  4597. abortSet: abortSet,
  4598. legacyContext: legacyContext,
  4599. context: context,
  4600. treeContext: treeContext
  4601. };
  4602. {
  4603. task.componentStack = null;
  4604. }
  4605. abortSet.add(task);
  4606. return task;
  4607. }
  4608. function createPendingSegment(request, index, boundary, formatContext, lastPushedText, textEmbedded) {
  4609. return {
  4610. status: PENDING,
  4611. id: -1,
  4612. // lazily assigned later
  4613. index: index,
  4614. parentFlushed: false,
  4615. chunks: [],
  4616. children: [],
  4617. formatContext: formatContext,
  4618. boundary: boundary,
  4619. lastPushedText: lastPushedText,
  4620. textEmbedded: textEmbedded
  4621. };
  4622. } // DEV-only global reference to the currently executing task
  4623. var currentTaskInDEV = null;
  4624. function getCurrentStackInDEV() {
  4625. {
  4626. if (currentTaskInDEV === null || currentTaskInDEV.componentStack === null) {
  4627. return '';
  4628. }
  4629. return getStackByComponentStackNode(currentTaskInDEV.componentStack);
  4630. }
  4631. }
  4632. function pushBuiltInComponentStackInDEV(task, type) {
  4633. {
  4634. task.componentStack = {
  4635. tag: 0,
  4636. parent: task.componentStack,
  4637. type: type
  4638. };
  4639. }
  4640. }
  4641. function pushFunctionComponentStackInDEV(task, type) {
  4642. {
  4643. task.componentStack = {
  4644. tag: 1,
  4645. parent: task.componentStack,
  4646. type: type
  4647. };
  4648. }
  4649. }
  4650. function pushClassComponentStackInDEV(task, type) {
  4651. {
  4652. task.componentStack = {
  4653. tag: 2,
  4654. parent: task.componentStack,
  4655. type: type
  4656. };
  4657. }
  4658. }
  4659. function popComponentStackInDEV(task) {
  4660. {
  4661. if (task.componentStack === null) {
  4662. error('Unexpectedly popped too many stack frames. This is a bug in React.');
  4663. } else {
  4664. task.componentStack = task.componentStack.parent;
  4665. }
  4666. }
  4667. } // stash the component stack of an unwinding error until it is processed
  4668. var lastBoundaryErrorComponentStackDev = null;
  4669. function captureBoundaryErrorDetailsDev(boundary, error) {
  4670. {
  4671. var errorMessage;
  4672. if (typeof error === 'string') {
  4673. errorMessage = error;
  4674. } else if (error && typeof error.message === 'string') {
  4675. errorMessage = error.message;
  4676. } else {
  4677. // eslint-disable-next-line react-internal/safe-string-coercion
  4678. errorMessage = String(error);
  4679. }
  4680. var errorComponentStack = lastBoundaryErrorComponentStackDev || getCurrentStackInDEV();
  4681. lastBoundaryErrorComponentStackDev = null;
  4682. boundary.errorMessage = errorMessage;
  4683. boundary.errorComponentStack = errorComponentStack;
  4684. }
  4685. }
  4686. function logRecoverableError(request, error) {
  4687. // If this callback errors, we intentionally let that error bubble up to become a fatal error
  4688. // so that someone fixes the error reporting instead of hiding it.
  4689. var errorDigest = request.onError(error);
  4690. if (errorDigest != null && typeof errorDigest !== 'string') {
  4691. // eslint-disable-next-line react-internal/prod-error-codes
  4692. throw new Error("onError returned something with a type other than \"string\". onError should return a string and may return null or undefined but must not return anything else. It received something of type \"" + typeof errorDigest + "\" instead");
  4693. }
  4694. return errorDigest;
  4695. }
  4696. function fatalError(request, error) {
  4697. // This is called outside error handling code such as if the root errors outside
  4698. // a suspense boundary or if the root suspense boundary's fallback errors.
  4699. // It's also called if React itself or its host configs errors.
  4700. var onShellError = request.onShellError;
  4701. onShellError(error);
  4702. var onFatalError = request.onFatalError;
  4703. onFatalError(error);
  4704. if (request.destination !== null) {
  4705. request.status = CLOSED;
  4706. closeWithError(request.destination, error);
  4707. } else {
  4708. request.status = CLOSING;
  4709. request.fatalError = error;
  4710. }
  4711. }
  4712. function renderSuspenseBoundary(request, task, props) {
  4713. pushBuiltInComponentStackInDEV(task, 'Suspense');
  4714. var parentBoundary = task.blockedBoundary;
  4715. var parentSegment = task.blockedSegment; // Each time we enter a suspense boundary, we split out into a new segment for
  4716. // the fallback so that we can later replace that segment with the content.
  4717. // This also lets us split out the main content even if it doesn't suspend,
  4718. // in case it ends up generating a large subtree of content.
  4719. var fallback = props.fallback;
  4720. var content = props.children;
  4721. var fallbackAbortSet = new Set();
  4722. var newBoundary = createSuspenseBoundary(request, fallbackAbortSet);
  4723. var insertionIndex = parentSegment.chunks.length; // The children of the boundary segment is actually the fallback.
  4724. var boundarySegment = createPendingSegment(request, insertionIndex, newBoundary, parentSegment.formatContext, // boundaries never require text embedding at their edges because comment nodes bound them
  4725. false, false);
  4726. parentSegment.children.push(boundarySegment); // The parentSegment has a child Segment at this index so we reset the lastPushedText marker on the parent
  4727. parentSegment.lastPushedText = false; // This segment is the actual child content. We can start rendering that immediately.
  4728. var contentRootSegment = createPendingSegment(request, 0, null, parentSegment.formatContext, // boundaries never require text embedding at their edges because comment nodes bound them
  4729. false, false); // We mark the root segment as having its parent flushed. It's not really flushed but there is
  4730. // no parent segment so there's nothing to wait on.
  4731. contentRootSegment.parentFlushed = true; // Currently this is running synchronously. We could instead schedule this to pingedTasks.
  4732. // I suspect that there might be some efficiency benefits from not creating the suspended task
  4733. // and instead just using the stack if possible.
  4734. // TODO: Call this directly instead of messing with saving and restoring contexts.
  4735. // We can reuse the current context and task to render the content immediately without
  4736. // context switching. We just need to temporarily switch which boundary and which segment
  4737. // we're writing to. If something suspends, it'll spawn new suspended task with that context.
  4738. task.blockedBoundary = newBoundary;
  4739. task.blockedSegment = contentRootSegment;
  4740. try {
  4741. // We use the safe form because we don't handle suspending here. Only error handling.
  4742. renderNode(request, task, content);
  4743. pushSegmentFinale(contentRootSegment.chunks, request.responseState, contentRootSegment.lastPushedText, contentRootSegment.textEmbedded);
  4744. contentRootSegment.status = COMPLETED;
  4745. queueCompletedSegment(newBoundary, contentRootSegment);
  4746. if (newBoundary.pendingTasks === 0) {
  4747. // This must have been the last segment we were waiting on. This boundary is now complete.
  4748. // Therefore we won't need the fallback. We early return so that we don't have to create
  4749. // the fallback.
  4750. popComponentStackInDEV(task);
  4751. return;
  4752. }
  4753. } catch (error) {
  4754. contentRootSegment.status = ERRORED;
  4755. newBoundary.forceClientRender = true;
  4756. newBoundary.errorDigest = logRecoverableError(request, error);
  4757. {
  4758. captureBoundaryErrorDetailsDev(newBoundary, error);
  4759. } // We don't need to decrement any task numbers because we didn't spawn any new task.
  4760. // We don't need to schedule any task because we know the parent has written yet.
  4761. // We do need to fallthrough to create the fallback though.
  4762. } finally {
  4763. task.blockedBoundary = parentBoundary;
  4764. task.blockedSegment = parentSegment;
  4765. } // We create suspended task for the fallback because we don't want to actually work
  4766. // on it yet in case we finish the main content, so we queue for later.
  4767. var suspendedFallbackTask = createTask(request, fallback, parentBoundary, boundarySegment, fallbackAbortSet, task.legacyContext, task.context, task.treeContext);
  4768. {
  4769. suspendedFallbackTask.componentStack = task.componentStack;
  4770. } // TODO: This should be queued at a separate lower priority queue so that we only work
  4771. // on preparing fallbacks if we don't have any more main content to task on.
  4772. request.pingedTasks.push(suspendedFallbackTask);
  4773. popComponentStackInDEV(task);
  4774. }
  4775. function renderHostElement(request, task, type, props) {
  4776. pushBuiltInComponentStackInDEV(task, type);
  4777. var segment = task.blockedSegment;
  4778. var children = pushStartInstance(segment.chunks, type, props, request.responseState, segment.formatContext);
  4779. segment.lastPushedText = false;
  4780. var prevContext = segment.formatContext;
  4781. segment.formatContext = getChildFormatContext(prevContext, type, props); // We use the non-destructive form because if something suspends, we still
  4782. // need to pop back up and finish this subtree of HTML.
  4783. renderNode(request, task, children); // We expect that errors will fatal the whole task and that we don't need
  4784. // the correct context. Therefore this is not in a finally.
  4785. segment.formatContext = prevContext;
  4786. pushEndInstance(segment.chunks, type);
  4787. segment.lastPushedText = false;
  4788. popComponentStackInDEV(task);
  4789. }
  4790. function shouldConstruct$1(Component) {
  4791. return Component.prototype && Component.prototype.isReactComponent;
  4792. }
  4793. function renderWithHooks(request, task, Component, props, secondArg) {
  4794. var componentIdentity = {};
  4795. prepareToUseHooks(task, componentIdentity);
  4796. var result = Component(props, secondArg);
  4797. return finishHooks(Component, props, result, secondArg);
  4798. }
  4799. function finishClassComponent(request, task, instance, Component, props) {
  4800. var nextChildren = instance.render();
  4801. {
  4802. if (instance.props !== props) {
  4803. if (!didWarnAboutReassigningProps) {
  4804. error('It looks like %s is reassigning its own `this.props` while rendering. ' + 'This is not supported and can lead to confusing bugs.', getComponentNameFromType(Component) || 'a component');
  4805. }
  4806. didWarnAboutReassigningProps = true;
  4807. }
  4808. }
  4809. {
  4810. var childContextTypes = Component.childContextTypes;
  4811. if (childContextTypes !== null && childContextTypes !== undefined) {
  4812. var previousContext = task.legacyContext;
  4813. var mergedContext = processChildContext(instance, Component, previousContext, childContextTypes);
  4814. task.legacyContext = mergedContext;
  4815. renderNodeDestructive(request, task, nextChildren);
  4816. task.legacyContext = previousContext;
  4817. return;
  4818. }
  4819. }
  4820. renderNodeDestructive(request, task, nextChildren);
  4821. }
  4822. function renderClassComponent(request, task, Component, props) {
  4823. pushClassComponentStackInDEV(task, Component);
  4824. var maskedContext = getMaskedContext(Component, task.legacyContext) ;
  4825. var instance = constructClassInstance(Component, props, maskedContext);
  4826. mountClassInstance(instance, Component, props, maskedContext);
  4827. finishClassComponent(request, task, instance, Component, props);
  4828. popComponentStackInDEV(task);
  4829. }
  4830. var didWarnAboutBadClass = {};
  4831. var didWarnAboutModulePatternComponent = {};
  4832. var didWarnAboutContextTypeOnFunctionComponent = {};
  4833. var didWarnAboutGetDerivedStateOnFunctionComponent = {};
  4834. var didWarnAboutReassigningProps = false;
  4835. var didWarnAboutGenerators = false;
  4836. var didWarnAboutMaps = false;
  4837. var hasWarnedAboutUsingContextAsConsumer = false; // This would typically be a function component but we still support module pattern
  4838. // components for some reason.
  4839. function renderIndeterminateComponent(request, task, Component, props) {
  4840. var legacyContext;
  4841. {
  4842. legacyContext = getMaskedContext(Component, task.legacyContext);
  4843. }
  4844. pushFunctionComponentStackInDEV(task, Component);
  4845. {
  4846. if (Component.prototype && typeof Component.prototype.render === 'function') {
  4847. var componentName = getComponentNameFromType(Component) || 'Unknown';
  4848. if (!didWarnAboutBadClass[componentName]) {
  4849. 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);
  4850. didWarnAboutBadClass[componentName] = true;
  4851. }
  4852. }
  4853. }
  4854. var value = renderWithHooks(request, task, Component, props, legacyContext);
  4855. var hasId = checkDidRenderIdHook();
  4856. {
  4857. // Support for module components is deprecated and is removed behind a flag.
  4858. // Whether or not it would crash later, we want to show a good message in DEV first.
  4859. if (typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
  4860. var _componentName = getComponentNameFromType(Component) || 'Unknown';
  4861. if (!didWarnAboutModulePatternComponent[_componentName]) {
  4862. 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);
  4863. didWarnAboutModulePatternComponent[_componentName] = true;
  4864. }
  4865. }
  4866. }
  4867. if ( // Run these checks in production only if the flag is off.
  4868. // Eventually we'll delete this branch altogether.
  4869. typeof value === 'object' && value !== null && typeof value.render === 'function' && value.$$typeof === undefined) {
  4870. {
  4871. var _componentName2 = getComponentNameFromType(Component) || 'Unknown';
  4872. if (!didWarnAboutModulePatternComponent[_componentName2]) {
  4873. 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);
  4874. didWarnAboutModulePatternComponent[_componentName2] = true;
  4875. }
  4876. }
  4877. mountClassInstance(value, Component, props, legacyContext);
  4878. finishClassComponent(request, task, value, Component, props);
  4879. } else {
  4880. {
  4881. validateFunctionComponentInDev(Component);
  4882. } // We're now successfully past this task, and we don't have to pop back to
  4883. // the previous task every again, so we can use the destructive recursive form.
  4884. if (hasId) {
  4885. // This component materialized an id. We treat this as its own level, with
  4886. // a single "child" slot.
  4887. var prevTreeContext = task.treeContext;
  4888. var totalChildren = 1;
  4889. var index = 0;
  4890. task.treeContext = pushTreeContext(prevTreeContext, totalChildren, index);
  4891. try {
  4892. renderNodeDestructive(request, task, value);
  4893. } finally {
  4894. task.treeContext = prevTreeContext;
  4895. }
  4896. } else {
  4897. renderNodeDestructive(request, task, value);
  4898. }
  4899. }
  4900. popComponentStackInDEV(task);
  4901. }
  4902. function validateFunctionComponentInDev(Component) {
  4903. {
  4904. if (Component) {
  4905. if (Component.childContextTypes) {
  4906. error('%s(...): childContextTypes cannot be defined on a function component.', Component.displayName || Component.name || 'Component');
  4907. }
  4908. }
  4909. if (typeof Component.getDerivedStateFromProps === 'function') {
  4910. var _componentName3 = getComponentNameFromType(Component) || 'Unknown';
  4911. if (!didWarnAboutGetDerivedStateOnFunctionComponent[_componentName3]) {
  4912. error('%s: Function components do not support getDerivedStateFromProps.', _componentName3);
  4913. didWarnAboutGetDerivedStateOnFunctionComponent[_componentName3] = true;
  4914. }
  4915. }
  4916. if (typeof Component.contextType === 'object' && Component.contextType !== null) {
  4917. var _componentName4 = getComponentNameFromType(Component) || 'Unknown';
  4918. if (!didWarnAboutContextTypeOnFunctionComponent[_componentName4]) {
  4919. error('%s: Function components do not support contextType.', _componentName4);
  4920. didWarnAboutContextTypeOnFunctionComponent[_componentName4] = true;
  4921. }
  4922. }
  4923. }
  4924. }
  4925. function resolveDefaultProps(Component, baseProps) {
  4926. if (Component && Component.defaultProps) {
  4927. // Resolve default props. Taken from ReactElement
  4928. var props = assign({}, baseProps);
  4929. var defaultProps = Component.defaultProps;
  4930. for (var propName in defaultProps) {
  4931. if (props[propName] === undefined) {
  4932. props[propName] = defaultProps[propName];
  4933. }
  4934. }
  4935. return props;
  4936. }
  4937. return baseProps;
  4938. }
  4939. function renderForwardRef(request, task, type, props, ref) {
  4940. pushFunctionComponentStackInDEV(task, type.render);
  4941. var children = renderWithHooks(request, task, type.render, props, ref);
  4942. var hasId = checkDidRenderIdHook();
  4943. if (hasId) {
  4944. // This component materialized an id. We treat this as its own level, with
  4945. // a single "child" slot.
  4946. var prevTreeContext = task.treeContext;
  4947. var totalChildren = 1;
  4948. var index = 0;
  4949. task.treeContext = pushTreeContext(prevTreeContext, totalChildren, index);
  4950. try {
  4951. renderNodeDestructive(request, task, children);
  4952. } finally {
  4953. task.treeContext = prevTreeContext;
  4954. }
  4955. } else {
  4956. renderNodeDestructive(request, task, children);
  4957. }
  4958. popComponentStackInDEV(task);
  4959. }
  4960. function renderMemo(request, task, type, props, ref) {
  4961. var innerType = type.type;
  4962. var resolvedProps = resolveDefaultProps(innerType, props);
  4963. renderElement(request, task, innerType, resolvedProps, ref);
  4964. }
  4965. function renderContextConsumer(request, task, context, props) {
  4966. // The logic below for Context differs depending on PROD or DEV mode. In
  4967. // DEV mode, we create a separate object for Context.Consumer that acts
  4968. // like a proxy to Context. This proxy object adds unnecessary code in PROD
  4969. // so we use the old behaviour (Context.Consumer references Context) to
  4970. // reduce size and overhead. The separate object references context via
  4971. // a property called "_context", which also gives us the ability to check
  4972. // in DEV mode if this property exists or not and warn if it does not.
  4973. {
  4974. if (context._context === undefined) {
  4975. // This may be because it's a Context (rather than a Consumer).
  4976. // Or it may be because it's older React where they're the same thing.
  4977. // We only want to warn if we're sure it's a new React.
  4978. if (context !== context.Consumer) {
  4979. if (!hasWarnedAboutUsingContextAsConsumer) {
  4980. hasWarnedAboutUsingContextAsConsumer = true;
  4981. error('Rendering <Context> directly is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Consumer> instead?');
  4982. }
  4983. }
  4984. } else {
  4985. context = context._context;
  4986. }
  4987. }
  4988. var render = props.children;
  4989. {
  4990. if (typeof render !== 'function') {
  4991. 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.');
  4992. }
  4993. }
  4994. var newValue = readContext(context);
  4995. var newChildren = render(newValue);
  4996. renderNodeDestructive(request, task, newChildren);
  4997. }
  4998. function renderContextProvider(request, task, type, props) {
  4999. var context = type._context;
  5000. var value = props.value;
  5001. var children = props.children;
  5002. var prevSnapshot;
  5003. {
  5004. prevSnapshot = task.context;
  5005. }
  5006. task.context = pushProvider(context, value);
  5007. renderNodeDestructive(request, task, children);
  5008. task.context = popProvider(context);
  5009. {
  5010. if (prevSnapshot !== task.context) {
  5011. error('Popping the context provider did not return back to the original snapshot. This is a bug in React.');
  5012. }
  5013. }
  5014. }
  5015. function renderLazyComponent(request, task, lazyComponent, props, ref) {
  5016. pushBuiltInComponentStackInDEV(task, 'Lazy');
  5017. var payload = lazyComponent._payload;
  5018. var init = lazyComponent._init;
  5019. var Component = init(payload);
  5020. var resolvedProps = resolveDefaultProps(Component, props);
  5021. renderElement(request, task, Component, resolvedProps, ref);
  5022. popComponentStackInDEV(task);
  5023. }
  5024. function renderElement(request, task, type, props, ref) {
  5025. if (typeof type === 'function') {
  5026. if (shouldConstruct$1(type)) {
  5027. renderClassComponent(request, task, type, props);
  5028. return;
  5029. } else {
  5030. renderIndeterminateComponent(request, task, type, props);
  5031. return;
  5032. }
  5033. }
  5034. if (typeof type === 'string') {
  5035. renderHostElement(request, task, type, props);
  5036. return;
  5037. }
  5038. switch (type) {
  5039. // TODO: LegacyHidden acts the same as a fragment. This only works
  5040. // because we currently assume that every instance of LegacyHidden is
  5041. // accompanied by a host component wrapper. In the hidden mode, the host
  5042. // component is given a `hidden` attribute, which ensures that the
  5043. // initial HTML is not visible. To support the use of LegacyHidden as a
  5044. // true fragment, without an extra DOM node, we would have to hide the
  5045. // initial HTML in some other way.
  5046. // TODO: Add REACT_OFFSCREEN_TYPE here too with the same capability.
  5047. case REACT_LEGACY_HIDDEN_TYPE:
  5048. case REACT_DEBUG_TRACING_MODE_TYPE:
  5049. case REACT_STRICT_MODE_TYPE:
  5050. case REACT_PROFILER_TYPE:
  5051. case REACT_FRAGMENT_TYPE:
  5052. {
  5053. renderNodeDestructive(request, task, props.children);
  5054. return;
  5055. }
  5056. case REACT_SUSPENSE_LIST_TYPE:
  5057. {
  5058. pushBuiltInComponentStackInDEV(task, 'SuspenseList'); // TODO: SuspenseList should control the boundaries.
  5059. renderNodeDestructive(request, task, props.children);
  5060. popComponentStackInDEV(task);
  5061. return;
  5062. }
  5063. case REACT_SCOPE_TYPE:
  5064. {
  5065. throw new Error('ReactDOMServer does not yet support scope components.');
  5066. }
  5067. // eslint-disable-next-line-no-fallthrough
  5068. case REACT_SUSPENSE_TYPE:
  5069. {
  5070. {
  5071. renderSuspenseBoundary(request, task, props);
  5072. }
  5073. return;
  5074. }
  5075. }
  5076. if (typeof type === 'object' && type !== null) {
  5077. switch (type.$$typeof) {
  5078. case REACT_FORWARD_REF_TYPE:
  5079. {
  5080. renderForwardRef(request, task, type, props, ref);
  5081. return;
  5082. }
  5083. case REACT_MEMO_TYPE:
  5084. {
  5085. renderMemo(request, task, type, props, ref);
  5086. return;
  5087. }
  5088. case REACT_PROVIDER_TYPE:
  5089. {
  5090. renderContextProvider(request, task, type, props);
  5091. return;
  5092. }
  5093. case REACT_CONTEXT_TYPE:
  5094. {
  5095. renderContextConsumer(request, task, type, props);
  5096. return;
  5097. }
  5098. case REACT_LAZY_TYPE:
  5099. {
  5100. renderLazyComponent(request, task, type, props);
  5101. return;
  5102. }
  5103. }
  5104. }
  5105. var info = '';
  5106. {
  5107. if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
  5108. 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.';
  5109. }
  5110. }
  5111. throw new 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));
  5112. }
  5113. function validateIterable(iterable, iteratorFn) {
  5114. {
  5115. // We don't support rendering Generators because it's a mutation.
  5116. // See https://github.com/facebook/react/issues/12995
  5117. if (typeof Symbol === 'function' && // $FlowFixMe Flow doesn't know about toStringTag
  5118. iterable[Symbol.toStringTag] === 'Generator') {
  5119. if (!didWarnAboutGenerators) {
  5120. 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.');
  5121. }
  5122. didWarnAboutGenerators = true;
  5123. } // Warn about using Maps as children
  5124. if (iterable.entries === iteratorFn) {
  5125. if (!didWarnAboutMaps) {
  5126. error('Using Maps as children is not supported. ' + 'Use an array of keyed ReactElements instead.');
  5127. }
  5128. didWarnAboutMaps = true;
  5129. }
  5130. }
  5131. }
  5132. function renderNodeDestructive(request, task, node) {
  5133. {
  5134. // In Dev we wrap renderNodeDestructiveImpl in a try / catch so we can capture
  5135. // a component stack at the right place in the tree. We don't do this in renderNode
  5136. // becuase it is not called at every layer of the tree and we may lose frames
  5137. try {
  5138. return renderNodeDestructiveImpl(request, task, node);
  5139. } catch (x) {
  5140. if (typeof x === 'object' && x !== null && typeof x.then === 'function') ; else {
  5141. // This is an error, stash the component stack if it is null.
  5142. lastBoundaryErrorComponentStackDev = lastBoundaryErrorComponentStackDev !== null ? lastBoundaryErrorComponentStackDev : getCurrentStackInDEV();
  5143. } // rethrow so normal suspense logic can handle thrown value accordingly
  5144. throw x;
  5145. }
  5146. }
  5147. } // This function by it self renders a node and consumes the task by mutating it
  5148. // to update the current execution state.
  5149. function renderNodeDestructiveImpl(request, task, node) {
  5150. // Stash the node we're working on. We'll pick up from this task in case
  5151. // something suspends.
  5152. task.node = node; // Handle object types
  5153. if (typeof node === 'object' && node !== null) {
  5154. switch (node.$$typeof) {
  5155. case REACT_ELEMENT_TYPE:
  5156. {
  5157. var element = node;
  5158. var type = element.type;
  5159. var props = element.props;
  5160. var ref = element.ref;
  5161. renderElement(request, task, type, props, ref);
  5162. return;
  5163. }
  5164. case REACT_PORTAL_TYPE:
  5165. throw new Error('Portals are not currently supported by the server renderer. ' + 'Render them conditionally so that they only appear on the client render.');
  5166. // eslint-disable-next-line-no-fallthrough
  5167. case REACT_LAZY_TYPE:
  5168. {
  5169. var lazyNode = node;
  5170. var payload = lazyNode._payload;
  5171. var init = lazyNode._init;
  5172. var resolvedNode;
  5173. {
  5174. try {
  5175. resolvedNode = init(payload);
  5176. } catch (x) {
  5177. if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
  5178. // this Lazy initializer is suspending. push a temporary frame onto the stack so it can be
  5179. // popped off in spawnNewSuspendedTask. This aligns stack behavior between Lazy in element position
  5180. // vs Component position. We do not want the frame for Errors so we exclusively do this in
  5181. // the wakeable branch
  5182. pushBuiltInComponentStackInDEV(task, 'Lazy');
  5183. }
  5184. throw x;
  5185. }
  5186. }
  5187. renderNodeDestructive(request, task, resolvedNode);
  5188. return;
  5189. }
  5190. }
  5191. if (isArray(node)) {
  5192. renderChildrenArray(request, task, node);
  5193. return;
  5194. }
  5195. var iteratorFn = getIteratorFn(node);
  5196. if (iteratorFn) {
  5197. {
  5198. validateIterable(node, iteratorFn);
  5199. }
  5200. var iterator = iteratorFn.call(node);
  5201. if (iterator) {
  5202. // We need to know how many total children are in this set, so that we
  5203. // can allocate enough id slots to acommodate them. So we must exhaust
  5204. // the iterator before we start recursively rendering the children.
  5205. // TODO: This is not great but I think it's inherent to the id
  5206. // generation algorithm.
  5207. var step = iterator.next(); // If there are not entries, we need to push an empty so we start by checking that.
  5208. if (!step.done) {
  5209. var children = [];
  5210. do {
  5211. children.push(step.value);
  5212. step = iterator.next();
  5213. } while (!step.done);
  5214. renderChildrenArray(request, task, children);
  5215. return;
  5216. }
  5217. return;
  5218. }
  5219. }
  5220. var childString = Object.prototype.toString.call(node);
  5221. throw new Error("Objects are not valid as a React child (found: " + (childString === '[object Object]' ? 'object with keys {' + Object.keys(node).join(', ') + '}' : childString) + "). " + 'If you meant to render a collection of children, use an array ' + 'instead.');
  5222. }
  5223. if (typeof node === 'string') {
  5224. var segment = task.blockedSegment;
  5225. segment.lastPushedText = pushTextInstance(task.blockedSegment.chunks, node, request.responseState, segment.lastPushedText);
  5226. return;
  5227. }
  5228. if (typeof node === 'number') {
  5229. var _segment = task.blockedSegment;
  5230. _segment.lastPushedText = pushTextInstance(task.blockedSegment.chunks, '' + node, request.responseState, _segment.lastPushedText);
  5231. return;
  5232. }
  5233. {
  5234. if (typeof node === 'function') {
  5235. 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.');
  5236. }
  5237. }
  5238. }
  5239. function renderChildrenArray(request, task, children) {
  5240. var totalChildren = children.length;
  5241. for (var i = 0; i < totalChildren; i++) {
  5242. var prevTreeContext = task.treeContext;
  5243. task.treeContext = pushTreeContext(prevTreeContext, totalChildren, i);
  5244. try {
  5245. // We need to use the non-destructive form so that we can safely pop back
  5246. // up and render the sibling if something suspends.
  5247. renderNode(request, task, children[i]);
  5248. } finally {
  5249. task.treeContext = prevTreeContext;
  5250. }
  5251. }
  5252. }
  5253. function spawnNewSuspendedTask(request, task, x) {
  5254. // Something suspended, we'll need to create a new segment and resolve it later.
  5255. var segment = task.blockedSegment;
  5256. var insertionIndex = segment.chunks.length;
  5257. var newSegment = createPendingSegment(request, insertionIndex, null, segment.formatContext, // Adopt the parent segment's leading text embed
  5258. segment.lastPushedText, // Assume we are text embedded at the trailing edge
  5259. true);
  5260. segment.children.push(newSegment); // Reset lastPushedText for current Segment since the new Segment "consumed" it
  5261. segment.lastPushedText = false;
  5262. var newTask = createTask(request, task.node, task.blockedBoundary, newSegment, task.abortSet, task.legacyContext, task.context, task.treeContext);
  5263. {
  5264. if (task.componentStack !== null) {
  5265. // We pop one task off the stack because the node that suspended will be tried again,
  5266. // which will add it back onto the stack.
  5267. newTask.componentStack = task.componentStack.parent;
  5268. }
  5269. }
  5270. var ping = newTask.ping;
  5271. x.then(ping, ping);
  5272. } // This is a non-destructive form of rendering a node. If it suspends it spawns
  5273. // a new task and restores the context of this task to what it was before.
  5274. function renderNode(request, task, node) {
  5275. // TODO: Store segment.children.length here and reset it in case something
  5276. // suspended partially through writing something.
  5277. // Snapshot the current context in case something throws to interrupt the
  5278. // process.
  5279. var previousFormatContext = task.blockedSegment.formatContext;
  5280. var previousLegacyContext = task.legacyContext;
  5281. var previousContext = task.context;
  5282. var previousComponentStack = null;
  5283. {
  5284. previousComponentStack = task.componentStack;
  5285. }
  5286. try {
  5287. return renderNodeDestructive(request, task, node);
  5288. } catch (x) {
  5289. resetHooksState();
  5290. if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
  5291. spawnNewSuspendedTask(request, task, x); // Restore the context. We assume that this will be restored by the inner
  5292. // functions in case nothing throws so we don't use "finally" here.
  5293. task.blockedSegment.formatContext = previousFormatContext;
  5294. task.legacyContext = previousLegacyContext;
  5295. task.context = previousContext; // Restore all active ReactContexts to what they were before.
  5296. switchContext(previousContext);
  5297. {
  5298. task.componentStack = previousComponentStack;
  5299. }
  5300. return;
  5301. } else {
  5302. // Restore the context. We assume that this will be restored by the inner
  5303. // functions in case nothing throws so we don't use "finally" here.
  5304. task.blockedSegment.formatContext = previousFormatContext;
  5305. task.legacyContext = previousLegacyContext;
  5306. task.context = previousContext; // Restore all active ReactContexts to what they were before.
  5307. switchContext(previousContext);
  5308. {
  5309. task.componentStack = previousComponentStack;
  5310. } // We assume that we don't need the correct context.
  5311. // Let's terminate the rest of the tree and don't render any siblings.
  5312. throw x;
  5313. }
  5314. }
  5315. }
  5316. function erroredTask(request, boundary, segment, error) {
  5317. // Report the error to a global handler.
  5318. var errorDigest = logRecoverableError(request, error);
  5319. if (boundary === null) {
  5320. fatalError(request, error);
  5321. } else {
  5322. boundary.pendingTasks--;
  5323. if (!boundary.forceClientRender) {
  5324. boundary.forceClientRender = true;
  5325. boundary.errorDigest = errorDigest;
  5326. {
  5327. captureBoundaryErrorDetailsDev(boundary, error);
  5328. } // Regardless of what happens next, this boundary won't be displayed,
  5329. // so we can flush it, if the parent already flushed.
  5330. if (boundary.parentFlushed) {
  5331. // We don't have a preference where in the queue this goes since it's likely
  5332. // to error on the client anyway. However, intentionally client-rendered
  5333. // boundaries should be flushed earlier so that they can start on the client.
  5334. // We reuse the same queue for errors.
  5335. request.clientRenderedBoundaries.push(boundary);
  5336. }
  5337. }
  5338. }
  5339. request.allPendingTasks--;
  5340. if (request.allPendingTasks === 0) {
  5341. var onAllReady = request.onAllReady;
  5342. onAllReady();
  5343. }
  5344. }
  5345. function abortTaskSoft(task) {
  5346. // This aborts task without aborting the parent boundary that it blocks.
  5347. // It's used for when we didn't need this task to complete the tree.
  5348. // If task was needed, then it should use abortTask instead.
  5349. var request = this;
  5350. var boundary = task.blockedBoundary;
  5351. var segment = task.blockedSegment;
  5352. segment.status = ABORTED;
  5353. finishedTask(request, boundary, segment);
  5354. }
  5355. function abortTask(task, request, reason) {
  5356. // This aborts the task and aborts the parent that it blocks, putting it into
  5357. // client rendered mode.
  5358. var boundary = task.blockedBoundary;
  5359. var segment = task.blockedSegment;
  5360. segment.status = ABORTED;
  5361. if (boundary === null) {
  5362. request.allPendingTasks--; // We didn't complete the root so we have nothing to show. We can close
  5363. // the request;
  5364. if (request.status !== CLOSED) {
  5365. request.status = CLOSED;
  5366. if (request.destination !== null) {
  5367. close(request.destination);
  5368. }
  5369. }
  5370. } else {
  5371. boundary.pendingTasks--;
  5372. if (!boundary.forceClientRender) {
  5373. boundary.forceClientRender = true;
  5374. var _error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
  5375. boundary.errorDigest = request.onError(_error);
  5376. {
  5377. var errorPrefix = 'The server did not finish this Suspense boundary: ';
  5378. if (_error && typeof _error.message === 'string') {
  5379. _error = errorPrefix + _error.message;
  5380. } else {
  5381. // eslint-disable-next-line react-internal/safe-string-coercion
  5382. _error = errorPrefix + String(_error);
  5383. }
  5384. var previousTaskInDev = currentTaskInDEV;
  5385. currentTaskInDEV = task;
  5386. try {
  5387. captureBoundaryErrorDetailsDev(boundary, _error);
  5388. } finally {
  5389. currentTaskInDEV = previousTaskInDev;
  5390. }
  5391. }
  5392. if (boundary.parentFlushed) {
  5393. request.clientRenderedBoundaries.push(boundary);
  5394. }
  5395. } // If this boundary was still pending then we haven't already cancelled its fallbacks.
  5396. // We'll need to abort the fallbacks, which will also error that parent boundary.
  5397. boundary.fallbackAbortableTasks.forEach(function (fallbackTask) {
  5398. return abortTask(fallbackTask, request, reason);
  5399. });
  5400. boundary.fallbackAbortableTasks.clear();
  5401. request.allPendingTasks--;
  5402. if (request.allPendingTasks === 0) {
  5403. var onAllReady = request.onAllReady;
  5404. onAllReady();
  5405. }
  5406. }
  5407. }
  5408. function queueCompletedSegment(boundary, segment) {
  5409. if (segment.chunks.length === 0 && segment.children.length === 1 && segment.children[0].boundary === null) {
  5410. // This is an empty segment. There's nothing to write, so we can instead transfer the ID
  5411. // to the child. That way any existing references point to the child.
  5412. var childSegment = segment.children[0];
  5413. childSegment.id = segment.id;
  5414. childSegment.parentFlushed = true;
  5415. if (childSegment.status === COMPLETED) {
  5416. queueCompletedSegment(boundary, childSegment);
  5417. }
  5418. } else {
  5419. var completedSegments = boundary.completedSegments;
  5420. completedSegments.push(segment);
  5421. }
  5422. }
  5423. function finishedTask(request, boundary, segment) {
  5424. if (boundary === null) {
  5425. if (segment.parentFlushed) {
  5426. if (request.completedRootSegment !== null) {
  5427. throw new Error('There can only be one root segment. This is a bug in React.');
  5428. }
  5429. request.completedRootSegment = segment;
  5430. }
  5431. request.pendingRootTasks--;
  5432. if (request.pendingRootTasks === 0) {
  5433. // We have completed the shell so the shell can't error anymore.
  5434. request.onShellError = noop$1;
  5435. var onShellReady = request.onShellReady;
  5436. onShellReady();
  5437. }
  5438. } else {
  5439. boundary.pendingTasks--;
  5440. if (boundary.forceClientRender) ; else if (boundary.pendingTasks === 0) {
  5441. // This must have been the last segment we were waiting on. This boundary is now complete.
  5442. if (segment.parentFlushed) {
  5443. // Our parent segment already flushed, so we need to schedule this segment to be emitted.
  5444. // If it is a segment that was aborted, we'll write other content instead so we don't need
  5445. // to emit it.
  5446. if (segment.status === COMPLETED) {
  5447. queueCompletedSegment(boundary, segment);
  5448. }
  5449. }
  5450. if (boundary.parentFlushed) {
  5451. // The segment might be part of a segment that didn't flush yet, but if the boundary's
  5452. // parent flushed, we need to schedule the boundary to be emitted.
  5453. request.completedBoundaries.push(boundary);
  5454. } // We can now cancel any pending task on the fallback since we won't need to show it anymore.
  5455. // This needs to happen after we read the parentFlushed flags because aborting can finish
  5456. // work which can trigger user code, which can start flushing, which can change those flags.
  5457. boundary.fallbackAbortableTasks.forEach(abortTaskSoft, request);
  5458. boundary.fallbackAbortableTasks.clear();
  5459. } else {
  5460. if (segment.parentFlushed) {
  5461. // Our parent already flushed, so we need to schedule this segment to be emitted.
  5462. // If it is a segment that was aborted, we'll write other content instead so we don't need
  5463. // to emit it.
  5464. if (segment.status === COMPLETED) {
  5465. queueCompletedSegment(boundary, segment);
  5466. var completedSegments = boundary.completedSegments;
  5467. if (completedSegments.length === 1) {
  5468. // This is the first time since we last flushed that we completed anything.
  5469. // We can schedule this boundary to emit its partially completed segments early
  5470. // in case the parent has already been flushed.
  5471. if (boundary.parentFlushed) {
  5472. request.partialBoundaries.push(boundary);
  5473. }
  5474. }
  5475. }
  5476. }
  5477. }
  5478. }
  5479. request.allPendingTasks--;
  5480. if (request.allPendingTasks === 0) {
  5481. // This needs to be called at the very end so that we can synchronously write the result
  5482. // in the callback if needed.
  5483. var onAllReady = request.onAllReady;
  5484. onAllReady();
  5485. }
  5486. }
  5487. function retryTask(request, task) {
  5488. var segment = task.blockedSegment;
  5489. if (segment.status !== PENDING) {
  5490. // We completed this by other means before we had a chance to retry it.
  5491. return;
  5492. } // We restore the context to what it was when we suspended.
  5493. // We don't restore it after we leave because it's likely that we'll end up
  5494. // needing a very similar context soon again.
  5495. switchContext(task.context);
  5496. var prevTaskInDEV = null;
  5497. {
  5498. prevTaskInDEV = currentTaskInDEV;
  5499. currentTaskInDEV = task;
  5500. }
  5501. try {
  5502. // We call the destructive form that mutates this task. That way if something
  5503. // suspends again, we can reuse the same task instead of spawning a new one.
  5504. renderNodeDestructive(request, task, task.node);
  5505. pushSegmentFinale(segment.chunks, request.responseState, segment.lastPushedText, segment.textEmbedded);
  5506. task.abortSet.delete(task);
  5507. segment.status = COMPLETED;
  5508. finishedTask(request, task.blockedBoundary, segment);
  5509. } catch (x) {
  5510. resetHooksState();
  5511. if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
  5512. // Something suspended again, let's pick it back up later.
  5513. var ping = task.ping;
  5514. x.then(ping, ping);
  5515. } else {
  5516. task.abortSet.delete(task);
  5517. segment.status = ERRORED;
  5518. erroredTask(request, task.blockedBoundary, segment, x);
  5519. }
  5520. } finally {
  5521. {
  5522. currentTaskInDEV = prevTaskInDEV;
  5523. }
  5524. }
  5525. }
  5526. function performWork(request) {
  5527. if (request.status === CLOSED) {
  5528. return;
  5529. }
  5530. var prevContext = getActiveContext();
  5531. var prevDispatcher = ReactCurrentDispatcher$1.current;
  5532. ReactCurrentDispatcher$1.current = Dispatcher;
  5533. var prevGetCurrentStackImpl;
  5534. {
  5535. prevGetCurrentStackImpl = ReactDebugCurrentFrame$1.getCurrentStack;
  5536. ReactDebugCurrentFrame$1.getCurrentStack = getCurrentStackInDEV;
  5537. }
  5538. var prevResponseState = currentResponseState;
  5539. setCurrentResponseState(request.responseState);
  5540. try {
  5541. var pingedTasks = request.pingedTasks;
  5542. var i;
  5543. for (i = 0; i < pingedTasks.length; i++) {
  5544. var task = pingedTasks[i];
  5545. retryTask(request, task);
  5546. }
  5547. pingedTasks.splice(0, i);
  5548. if (request.destination !== null) {
  5549. flushCompletedQueues(request, request.destination);
  5550. }
  5551. } catch (error) {
  5552. logRecoverableError(request, error);
  5553. fatalError(request, error);
  5554. } finally {
  5555. setCurrentResponseState(prevResponseState);
  5556. ReactCurrentDispatcher$1.current = prevDispatcher;
  5557. {
  5558. ReactDebugCurrentFrame$1.getCurrentStack = prevGetCurrentStackImpl;
  5559. }
  5560. if (prevDispatcher === Dispatcher) {
  5561. // This means that we were in a reentrant work loop. This could happen
  5562. // in a renderer that supports synchronous work like renderToString,
  5563. // when it's called from within another renderer.
  5564. // Normally we don't bother switching the contexts to their root/default
  5565. // values when leaving because we'll likely need the same or similar
  5566. // context again. However, when we're inside a synchronous loop like this
  5567. // we'll to restore the context to what it was before returning.
  5568. switchContext(prevContext);
  5569. }
  5570. }
  5571. }
  5572. function flushSubtree(request, destination, segment) {
  5573. segment.parentFlushed = true;
  5574. switch (segment.status) {
  5575. case PENDING:
  5576. {
  5577. // We're emitting a placeholder for this segment to be filled in later.
  5578. // Therefore we'll need to assign it an ID - to refer to it by.
  5579. var segmentID = segment.id = request.nextSegmentId++; // When this segment finally completes it won't be embedded in text since it will flush separately
  5580. segment.lastPushedText = false;
  5581. segment.textEmbedded = false;
  5582. return writePlaceholder(destination, request.responseState, segmentID);
  5583. }
  5584. case COMPLETED:
  5585. {
  5586. segment.status = FLUSHED;
  5587. var r = true;
  5588. var chunks = segment.chunks;
  5589. var chunkIdx = 0;
  5590. var children = segment.children;
  5591. for (var childIdx = 0; childIdx < children.length; childIdx++) {
  5592. var nextChild = children[childIdx]; // Write all the chunks up until the next child.
  5593. for (; chunkIdx < nextChild.index; chunkIdx++) {
  5594. writeChunk(destination, chunks[chunkIdx]);
  5595. }
  5596. r = flushSegment(request, destination, nextChild);
  5597. } // Finally just write all the remaining chunks
  5598. for (; chunkIdx < chunks.length - 1; chunkIdx++) {
  5599. writeChunk(destination, chunks[chunkIdx]);
  5600. }
  5601. if (chunkIdx < chunks.length) {
  5602. r = writeChunkAndReturn(destination, chunks[chunkIdx]);
  5603. }
  5604. return r;
  5605. }
  5606. default:
  5607. {
  5608. throw new Error('Aborted, errored or already flushed boundaries should not be flushed again. This is a bug in React.');
  5609. }
  5610. }
  5611. }
  5612. function flushSegment(request, destination, segment) {
  5613. var boundary = segment.boundary;
  5614. if (boundary === null) {
  5615. // Not a suspense boundary.
  5616. return flushSubtree(request, destination, segment);
  5617. }
  5618. boundary.parentFlushed = true; // This segment is a Suspense boundary. We need to decide whether to
  5619. // emit the content or the fallback now.
  5620. if (boundary.forceClientRender) {
  5621. // Emit a client rendered suspense boundary wrapper.
  5622. // We never queue the inner boundary so we'll never emit its content or partial segments.
  5623. writeStartClientRenderedSuspenseBoundary(destination, request.responseState, boundary.errorDigest, boundary.errorMessage, boundary.errorComponentStack); // Flush the fallback.
  5624. flushSubtree(request, destination, segment);
  5625. return writeEndClientRenderedSuspenseBoundary(destination, request.responseState);
  5626. } else if (boundary.pendingTasks > 0) {
  5627. // This boundary is still loading. Emit a pending suspense boundary wrapper.
  5628. // Assign an ID to refer to the future content by.
  5629. boundary.rootSegmentID = request.nextSegmentId++;
  5630. if (boundary.completedSegments.length > 0) {
  5631. // If this is at least partially complete, we can queue it to be partially emitted early.
  5632. request.partialBoundaries.push(boundary);
  5633. } /// This is the first time we should have referenced this ID.
  5634. var id = boundary.id = assignSuspenseBoundaryID(request.responseState);
  5635. writeStartPendingSuspenseBoundary(destination, request.responseState, id); // Flush the fallback.
  5636. flushSubtree(request, destination, segment);
  5637. return writeEndPendingSuspenseBoundary(destination, request.responseState);
  5638. } else if (boundary.byteSize > request.progressiveChunkSize) {
  5639. // This boundary is large and will be emitted separately so that we can progressively show
  5640. // other content. We add it to the queue during the flush because we have to ensure that
  5641. // the parent flushes first so that there's something to inject it into.
  5642. // We also have to make sure that it's emitted into the queue in a deterministic slot.
  5643. // I.e. we can't insert it here when it completes.
  5644. // Assign an ID to refer to the future content by.
  5645. boundary.rootSegmentID = request.nextSegmentId++;
  5646. request.completedBoundaries.push(boundary); // Emit a pending rendered suspense boundary wrapper.
  5647. writeStartPendingSuspenseBoundary(destination, request.responseState, boundary.id); // Flush the fallback.
  5648. flushSubtree(request, destination, segment);
  5649. return writeEndPendingSuspenseBoundary(destination, request.responseState);
  5650. } else {
  5651. // We can inline this boundary's content as a complete boundary.
  5652. writeStartCompletedSuspenseBoundary(destination, request.responseState);
  5653. var completedSegments = boundary.completedSegments;
  5654. if (completedSegments.length !== 1) {
  5655. throw new Error('A previously unvisited boundary must have exactly one root segment. This is a bug in React.');
  5656. }
  5657. var contentSegment = completedSegments[0];
  5658. flushSegment(request, destination, contentSegment);
  5659. return writeEndCompletedSuspenseBoundary(destination, request.responseState);
  5660. }
  5661. }
  5662. function flushClientRenderedBoundary(request, destination, boundary) {
  5663. return writeClientRenderBoundaryInstruction(destination, request.responseState, boundary.id, boundary.errorDigest, boundary.errorMessage, boundary.errorComponentStack);
  5664. }
  5665. function flushSegmentContainer(request, destination, segment) {
  5666. writeStartSegment(destination, request.responseState, segment.formatContext, segment.id);
  5667. flushSegment(request, destination, segment);
  5668. return writeEndSegment(destination, segment.formatContext);
  5669. }
  5670. function flushCompletedBoundary(request, destination, boundary) {
  5671. var completedSegments = boundary.completedSegments;
  5672. var i = 0;
  5673. for (; i < completedSegments.length; i++) {
  5674. var segment = completedSegments[i];
  5675. flushPartiallyCompletedSegment(request, destination, boundary, segment);
  5676. }
  5677. completedSegments.length = 0;
  5678. return writeCompletedBoundaryInstruction(destination, request.responseState, boundary.id, boundary.rootSegmentID);
  5679. }
  5680. function flushPartialBoundary(request, destination, boundary) {
  5681. var completedSegments = boundary.completedSegments;
  5682. var i = 0;
  5683. for (; i < completedSegments.length; i++) {
  5684. var segment = completedSegments[i];
  5685. if (!flushPartiallyCompletedSegment(request, destination, boundary, segment)) {
  5686. i++;
  5687. completedSegments.splice(0, i); // Only write as much as the buffer wants. Something higher priority
  5688. // might want to write later.
  5689. return false;
  5690. }
  5691. }
  5692. completedSegments.splice(0, i);
  5693. return true;
  5694. }
  5695. function flushPartiallyCompletedSegment(request, destination, boundary, segment) {
  5696. if (segment.status === FLUSHED) {
  5697. // We've already flushed this inline.
  5698. return true;
  5699. }
  5700. var segmentID = segment.id;
  5701. if (segmentID === -1) {
  5702. // This segment wasn't previously referred to. This happens at the root of
  5703. // a boundary. We make kind of a leap here and assume this is the root.
  5704. var rootSegmentID = segment.id = boundary.rootSegmentID;
  5705. if (rootSegmentID === -1) {
  5706. throw new Error('A root segment ID must have been assigned by now. This is a bug in React.');
  5707. }
  5708. return flushSegmentContainer(request, destination, segment);
  5709. } else {
  5710. flushSegmentContainer(request, destination, segment);
  5711. return writeCompletedSegmentInstruction(destination, request.responseState, segmentID);
  5712. }
  5713. }
  5714. function flushCompletedQueues(request, destination) {
  5715. beginWriting();
  5716. try {
  5717. // The structure of this is to go through each queue one by one and write
  5718. // until the sink tells us to stop. When we should stop, we still finish writing
  5719. // that item fully and then yield. At that point we remove the already completed
  5720. // items up until the point we completed them.
  5721. // TODO: Emit preloading.
  5722. // TODO: It's kind of unfortunate to keep checking this array after we've already
  5723. // emitted the root.
  5724. var completedRootSegment = request.completedRootSegment;
  5725. if (completedRootSegment !== null && request.pendingRootTasks === 0) {
  5726. flushSegment(request, destination, completedRootSegment);
  5727. request.completedRootSegment = null;
  5728. writeCompletedRoot(destination, request.responseState);
  5729. } // We emit client rendering instructions for already emitted boundaries first.
  5730. // This is so that we can signal to the client to start client rendering them as
  5731. // soon as possible.
  5732. var clientRenderedBoundaries = request.clientRenderedBoundaries;
  5733. var i;
  5734. for (i = 0; i < clientRenderedBoundaries.length; i++) {
  5735. var boundary = clientRenderedBoundaries[i];
  5736. if (!flushClientRenderedBoundary(request, destination, boundary)) {
  5737. request.destination = null;
  5738. i++;
  5739. clientRenderedBoundaries.splice(0, i);
  5740. return;
  5741. }
  5742. }
  5743. clientRenderedBoundaries.splice(0, i); // Next we emit any complete boundaries. It's better to favor boundaries
  5744. // that are completely done since we can actually show them, than it is to emit
  5745. // any individual segments from a partially complete boundary.
  5746. var completedBoundaries = request.completedBoundaries;
  5747. for (i = 0; i < completedBoundaries.length; i++) {
  5748. var _boundary = completedBoundaries[i];
  5749. if (!flushCompletedBoundary(request, destination, _boundary)) {
  5750. request.destination = null;
  5751. i++;
  5752. completedBoundaries.splice(0, i);
  5753. return;
  5754. }
  5755. }
  5756. completedBoundaries.splice(0, i); // Allow anything written so far to flush to the underlying sink before
  5757. // we continue with lower priorities.
  5758. completeWriting(destination);
  5759. beginWriting(destination); // TODO: Here we'll emit data used by hydration.
  5760. // Next we emit any segments of any boundaries that are partially complete
  5761. // but not deeply complete.
  5762. var partialBoundaries = request.partialBoundaries;
  5763. for (i = 0; i < partialBoundaries.length; i++) {
  5764. var _boundary2 = partialBoundaries[i];
  5765. if (!flushPartialBoundary(request, destination, _boundary2)) {
  5766. request.destination = null;
  5767. i++;
  5768. partialBoundaries.splice(0, i);
  5769. return;
  5770. }
  5771. }
  5772. partialBoundaries.splice(0, i); // Next we check the completed boundaries again. This may have had
  5773. // boundaries added to it in case they were too larged to be inlined.
  5774. // New ones might be added in this loop.
  5775. var largeBoundaries = request.completedBoundaries;
  5776. for (i = 0; i < largeBoundaries.length; i++) {
  5777. var _boundary3 = largeBoundaries[i];
  5778. if (!flushCompletedBoundary(request, destination, _boundary3)) {
  5779. request.destination = null;
  5780. i++;
  5781. largeBoundaries.splice(0, i);
  5782. return;
  5783. }
  5784. }
  5785. largeBoundaries.splice(0, i);
  5786. } finally {
  5787. completeWriting(destination);
  5788. flushBuffered(destination);
  5789. if (request.allPendingTasks === 0 && request.pingedTasks.length === 0 && request.clientRenderedBoundaries.length === 0 && request.completedBoundaries.length === 0 // We don't need to check any partially completed segments because
  5790. // either they have pending task or they're complete.
  5791. ) {
  5792. {
  5793. if (request.abortableTasks.size !== 0) {
  5794. error('There was still abortable task at the root when we closed. This is a bug in React.');
  5795. }
  5796. } // We're done.
  5797. close(destination);
  5798. }
  5799. }
  5800. }
  5801. function startWork(request) {
  5802. scheduleWork(function () {
  5803. return performWork(request);
  5804. });
  5805. }
  5806. function startFlowing(request, destination) {
  5807. if (request.status === CLOSING) {
  5808. request.status = CLOSED;
  5809. closeWithError(destination, request.fatalError);
  5810. return;
  5811. }
  5812. if (request.status === CLOSED) {
  5813. return;
  5814. }
  5815. if (request.destination !== null) {
  5816. // We're already flowing.
  5817. return;
  5818. }
  5819. request.destination = destination;
  5820. try {
  5821. flushCompletedQueues(request, destination);
  5822. } catch (error) {
  5823. logRecoverableError(request, error);
  5824. fatalError(request, error);
  5825. }
  5826. } // This is called to early terminate a request. It puts all pending boundaries in client rendered state.
  5827. function abort(request, reason) {
  5828. try {
  5829. var abortableTasks = request.abortableTasks;
  5830. abortableTasks.forEach(function (task) {
  5831. return abortTask(task, request, reason);
  5832. });
  5833. abortableTasks.clear();
  5834. if (request.destination !== null) {
  5835. flushCompletedQueues(request, request.destination);
  5836. }
  5837. } catch (error) {
  5838. logRecoverableError(request, error);
  5839. fatalError(request, error);
  5840. }
  5841. }
  5842. function createDrainHandler(destination, request) {
  5843. return function () {
  5844. return startFlowing(request, destination);
  5845. };
  5846. }
  5847. function createAbortHandler(request, reason) {
  5848. return function () {
  5849. return abort(request, reason);
  5850. };
  5851. }
  5852. function createRequestImpl(children, options) {
  5853. return createRequest(children, createResponseState(options ? options.identifierPrefix : undefined, options ? options.nonce : undefined, options ? options.bootstrapScriptContent : undefined, options ? options.bootstrapScripts : undefined, options ? options.bootstrapModules : undefined), createRootFormatContext(options ? options.namespaceURI : undefined), options ? options.progressiveChunkSize : undefined, options ? options.onError : undefined, options ? options.onAllReady : undefined, options ? options.onShellReady : undefined, options ? options.onShellError : undefined, undefined);
  5854. }
  5855. function renderToPipeableStream(children, options) {
  5856. var request = createRequestImpl(children, options);
  5857. var hasStartedFlowing = false;
  5858. startWork(request);
  5859. return {
  5860. pipe: function (destination) {
  5861. if (hasStartedFlowing) {
  5862. throw new Error('React currently only supports piping to one writable stream.');
  5863. }
  5864. hasStartedFlowing = true;
  5865. startFlowing(request, destination);
  5866. destination.on('drain', createDrainHandler(destination, request));
  5867. destination.on('error', createAbortHandler(request, // eslint-disable-next-line react-internal/prod-error-codes
  5868. new Error('The destination stream errored while writing data.')));
  5869. destination.on('close', createAbortHandler(request, // eslint-disable-next-line react-internal/prod-error-codes
  5870. new Error('The destination stream closed early.')));
  5871. return destination;
  5872. },
  5873. abort: function (reason) {
  5874. abort(request, reason);
  5875. }
  5876. };
  5877. }
  5878. exports.renderToPipeableStream = renderToPipeableStream;
  5879. exports.version = ReactVersion;
  5880. })();
  5881. }