| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249 |
- import { createVaporSSRApp, delegateEvents } from '../src'
- import { nextTick, reactive, ref } from '@vue/runtime-dom'
- import { compileScript, parse } from '@vue/compiler-sfc'
- import * as runtimeVapor from '../src'
- import * as runtimeDom from '@vue/runtime-dom'
- import * as VueServerRenderer from '@vue/server-renderer'
- import {
- DYNAMIC_COMPONENT_ANCHOR_LABEL,
- FOR_ANCHOR_LABEL,
- IF_ANCHOR_LABEL,
- SLOT_ANCHOR_LABEL,
- isString,
- } from '@vue/shared'
- const Vue = { ...runtimeDom, ...runtimeVapor }
- function compile(
- sfc: string,
- data: runtimeDom.Ref<any>,
- components: Record<string, any> = {},
- { vapor = true, ssr = false } = {},
- ) {
- if (!sfc.includes(`<script`)) {
- sfc =
- `<script vapor>const data = _data; const components = _components;</script>` +
- sfc
- }
- const descriptor = parse(sfc).descriptor
- const script = compileScript(descriptor, {
- id: 'x',
- isProd: true,
- inlineTemplate: true,
- genDefaultAs: '__sfc__',
- vapor,
- templateOptions: {
- ssr,
- },
- })
- const code =
- script.content
- .replace(/\bimport {/g, 'const {')
- .replace(/ as _/g, ': _')
- .replace(/} from ['"]vue['"]/g, `} = Vue`)
- .replace(/} from "vue\/server-renderer"/g, '} = VueServerRenderer') +
- '\nreturn __sfc__'
- return new Function('Vue', 'VueServerRenderer', '_data', '_components', code)(
- Vue,
- VueServerRenderer,
- data,
- components,
- )
- }
- async function testHydrationInterop(
- code: string,
- components?: Record<string, string | { code: string; vapor: boolean }>,
- data?: any,
- ) {
- return testHydration(code, components, data, { interop: true, vapor: false })
- }
- async function testHydration(
- code: string,
- components: Record<string, string | { code: string; vapor: boolean }> = {},
- data: any = ref('foo'),
- { interop = false, vapor = true } = {},
- ) {
- const ssrComponents: any = {}
- const clientComponents: any = {}
- for (const key in components) {
- const comp = components[key]
- const code = isString(comp) ? comp : comp.code
- const isVaporComp = isString(comp) || !!comp.vapor
- clientComponents[key] = compile(code, data, clientComponents, {
- vapor: isVaporComp,
- ssr: false,
- })
- ssrComponents[key] = compile(code, data, ssrComponents, {
- vapor: isVaporComp,
- ssr: true,
- })
- }
- const serverComp = compile(code, data, ssrComponents, { vapor, ssr: true })
- const html = await VueServerRenderer.renderToString(
- runtimeDom.createSSRApp(serverComp),
- )
- const container = document.createElement('div')
- document.body.appendChild(container)
- container.innerHTML = html
- const clientComp = compile(code, data, clientComponents, {
- vapor,
- ssr: false,
- })
- let app
- if (interop) {
- app = runtimeDom.createSSRApp(clientComp)
- app.use(runtimeVapor.vaporInteropPlugin)
- } else {
- app = createVaporSSRApp(clientComp)
- }
- app.mount(container)
- return { data, container }
- }
- const triggerEvent = (type: string, el: Element) => {
- const event = new Event(type, { bubbles: true })
- el.dispatchEvent(event)
- }
- delegateEvents('click')
- beforeEach(() => {
- document.body.innerHTML = ''
- })
- describe('Vapor Mode hydration', () => {
- describe('text', () => {
- test('root text', async () => {
- const { data, container } = await testHydration(`
- <template>{{ data }}</template>
- `)
- expect(container.innerHTML).toMatchInlineSnapshot(`"foo"`)
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(`"bar"`)
- })
- test('consecutive text nodes', async () => {
- const { data, container } = await testHydration(`
- <template>{{ data }}{{ data }}</template>
- `)
- expect(container.innerHTML).toMatchInlineSnapshot(`"foofoo"`)
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(`"barbar"`)
- })
- test('consecutive text nodes with anchor insertion', async () => {
- const { data, container } = await testHydration(`
- <template><span/>{{ data }}{{ data }}<span/></template>
- `)
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<!--[--><span></span>foofoo<span></span><!--]-->"`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<!--[--><span></span>barbar<span></span><!--]-->"`,
- )
- })
- test('mixed text nodes', async () => {
- const { data, container } = await testHydration(`
- <template>{{ data }}A{{ data }}B{{ data }}</template>
- `)
- expect(container.innerHTML).toMatchInlineSnapshot(`"fooAfooBfoo"`)
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(`"barAbarBbar"`)
- })
- test('mixed text nodes with anchor insertion', async () => {
- const { data, container } = await testHydration(`
- <template><span/>{{ data }}A{{ data }}B{{ data }}<span/></template>
- `)
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<!--[--><span></span>fooAfooBfoo<span></span><!--]-->"`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<!--[--><span></span>barAbarBbar<span></span><!--]-->"`,
- )
- })
- })
- describe('element', () => {
- test('root comment', async () => {
- const { container } = await testHydration(`
- <template><!----></template>
- `)
- expect(container.innerHTML).toBe('<!---->')
- expect(`Hydration children mismatch in <div>`).not.toHaveBeenWarned()
- })
- test('root with mixed element and text', async () => {
- const { container, data } = await testHydration(`
- <template> A<span>{{ data }}</span>{{ data }}</template>
- `)
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<!--[--> A<span>foo</span>foo<!--]-->"`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<!--[--> A<span>bar</span>bar<!--]-->"`,
- )
- })
- test('empty element', async () => {
- const { container } = await testHydration(`
- <template><div/></template>
- `)
- expect(container.innerHTML).toBe('<div></div>')
- expect(`Hydration children mismatch in <div>`).not.toHaveBeenWarned()
- })
- test('element with binding and text children', async () => {
- const { container, data } = await testHydration(`
- <template><div :class="data">{{ data }}</div></template>
- `)
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div class="foo">foo</div>"`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div class="bar">bar</div>"`,
- )
- })
- test('element with elements children', async () => {
- const { container } = await testHydration(`
- <template>
- <div>
- <span>{{ data }}</span>
- <span :class="data" @click="data = 'bar'"/>
- </div>
- </template>
- `)
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div><span>foo</span><span class="foo"></span></div>"`,
- )
- // event handler
- triggerEvent('click', container.querySelector('.foo')!)
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div><span>bar</span><span class="bar"></span></div>"`,
- )
- })
- test('element with ref', async () => {
- const { data, container } = await testHydration(
- `<template>
- <div ref="data">hi</div>
- </template>
- `,
- {},
- ref(null),
- )
- expect(data.value).toBe(container.firstChild)
- })
- })
- describe('component', () => {
- test('basic component', async () => {
- const { container, data } = await testHydration(
- `
- <template><div><span></span><components.Child/></div></template>
- `,
- { Child: `<template>{{ data }}</template>` },
- )
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div><span></span>foo</div>"`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div><span></span>bar</div>"`,
- )
- })
- test('fragment component', async () => {
- const { container, data } = await testHydration(
- `
- <template><div><span></span><components.Child/></div></template>
- `,
- { Child: `<template><div>{{ data }}</div>-{{ data }}-</template>` },
- )
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div><span></span><!--[--><div>foo</div>-foo-<!--]--></div>"`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div><span></span><!--[--><div>bar</div>-bar-<!--]--></div>"`,
- )
- })
- test('fragment component with prepend', async () => {
- const { container, data } = await testHydration(
- `
- <template><div><components.Child/><span></span></div></template>
- `,
- { Child: `<template><div>{{ data }}</div>-{{ data }}-</template>` },
- )
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div><!--[--><div>foo</div>-foo-<!--]--><span></span></div>"`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div><!--[--><div>bar</div>-bar-<!--]--><span></span></div>"`,
- )
- })
- test('nested fragment components', async () => {
- const { container, data } = await testHydration(
- `
- <template><div><components.Parent/><span></span></div></template>
- `,
- {
- Parent: `<template><div/><components.Child/><div/></template>`,
- Child: `<template><div>{{ data }}</div>-{{ data }}-</template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[-->` +
- `<div></div>` +
- `<!--[--><div>foo</div>-foo-<!--]-->` +
- `<div></div>` +
- `<!--]-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[-->` +
- `<div></div>` +
- `<!--[--><div>bar</div>-bar-<!--]-->` +
- `<div></div>` +
- `<!--]-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('component with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span/>
- <components.Child/>
- <span/>
- </div>
- </template>
- `,
- {
- Child: `<template>{{ data }}</template>`,
- },
- )
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div><span></span>foo<span></span></div>"`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div><span></span>bar<span></span></div>"`,
- )
- })
- test('nested components with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `
- <template><components.Parent/></template>
- `,
- {
- Parent: `<template><div><span/><components.Child/><span/></div></template>`,
- Child: `<template><div>{{ data }}</div></template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div><span></span><div>foo</div><span></span></div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div><span></span><div>bar</div><span></span></div>`,
- )
- })
- test('nested components with multi level anchor insertion', async () => {
- const { container, data } = await testHydration(
- `
- <template><div><span></span><components.Parent/><span></span></div></template>
- `,
- {
- Parent: `<template><div><span/><components.Child/><span/></div></template>`,
- Child: `<template><div>{{ data }}</div></template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>` +
- `<span></span>` +
- `<div>foo</div>` +
- `<span></span>` +
- `</div>` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>` +
- `<span></span>` +
- `<div>bar</div>` +
- `<span></span>` +
- `</div>` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('consecutive components with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span/>
- <components.Child/>
- <components.Child/>
- <span/>
- </div>
- </template>
- `,
- {
- Child: `<template>{{ data }}</template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `foo` +
- `<!--[[-->foo<!--]]-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `bar` +
- `<!--[[-->bar<!--]]-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('consecutive components with insertion parent', async () => {
- const data = reactive({ foo: 'foo', bar: 'bar' })
- const { container } = await testHydration(
- `<template>
- <div>
- <components.Child1/>
- <components.Child2/>
- </div>
- </template>
- `,
- {
- Child1: `<template><span>{{ data.foo }}</span></template>`,
- Child2: `<template><span>{{ data.bar }}</span></template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div><span>foo</span><span>bar</span></div>`,
- )
- data.foo = 'foo1'
- data.bar = 'bar1'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div><span>foo1</span><span>bar1</span></div>`,
- )
- })
- test('nested consecutive components with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `
- <template><components.Parent/></template>
- `,
- {
- Parent: `<template><div><span/><components.Child/><components.Child/><span/></div></template>`,
- Child: `<template><div>{{ data }}</div></template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>foo</div>` +
- `<!--[[--><div>foo</div><!--]]-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>bar</div>` +
- `<!--[[--><div>bar</div><!--]]-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('nested consecutive components with multi level anchor insertion', async () => {
- const { container, data } = await testHydration(
- `
- <template><div><span></span><components.Parent/><span></span></div></template>
- `,
- {
- Parent: `<template><div><span/><components.Child/><components.Child/><span/></div></template>`,
- Child: `<template><div>{{ data }}</div></template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>` +
- `<span></span>` +
- `<div>foo</div>` +
- `<!--[[--><div>foo</div><!--]]-->` +
- `<span></span>` +
- `</div>` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>` +
- `<span></span>` +
- `<div>bar</div>` +
- `<!--[[--><div>bar</div><!--]]-->` +
- `<span></span>` +
- `</div>` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('mixed component and element with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span/>
- <components.Child/>
- <span/>
- <components.Child/>
- <span/>
- </div>
- </template>
- `,
- {
- Child: `<template>{{ data }}</template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `foo` +
- `<span></span>` +
- `foo` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `bar` +
- `<span></span>` +
- `bar` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('mixed component and text with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span/>
- <components.Child/>
- {{ data }}
- <components.Child/>
- <span/>
- </div>
- </template>
- `,
- {
- Child: `<template>{{ data }}</template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `foo` +
- `<!--[[--> foo <!--]]-->` +
- `foo` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `bar` +
- `<!--[[--> bar <!--]]-->` +
- `bar` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('fragment component with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span/>
- <components.Child/>
- <span/>
- </div>
- </template>
- `,
- {
- Child: `<template><div>{{ data }}</div>-{{ data }}</template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>foo</div>-foo<!--]-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>bar</div>-bar<!--]-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('nested fragment component with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `
- <template><components.Parent/></template>
- `,
- {
- Parent: `<template><div><span/><components.Child/><span/></div></template>`,
- Child: `<template><div>{{ data }}</div>-{{ data }}-</template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>foo</div>-foo-<!--]-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>bar</div>-bar-<!--]-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('nested fragment component with multi level anchor insertion', async () => {
- const { container, data } = await testHydration(
- `
- <template><div><span/><components.Parent/><span/></div></template>
- `,
- {
- Parent: `<template><div><span/><components.Child/><span/></div></template>`,
- Child: `<template><div>{{ data }}</div>-{{ data }}-</template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>` +
- `<span></span>` +
- `<!--[--><div>foo</div>-foo-<!--]-->` +
- `<span></span>` +
- `</div>` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>` +
- `<span></span>` +
- `<!--[--><div>bar</div>-bar-<!--]-->` +
- `<span></span>` +
- `</div>` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('consecutive fragment components with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span/>
- <components.Child/>
- <components.Child/>
- <span/>
- </div>
- </template>
- `,
- {
- Child: `<template><div>{{ data }}</div>-{{ data }}</template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>foo</div>-foo<!--]-->` +
- `<!--[[-->` +
- `<!--[--><div>foo</div>-foo<!--]-->` +
- `<!--]]-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>bar</div>-bar<!--]-->` +
- `<!--[[-->` +
- `<!--[--><div>bar</div>-bar<!--]-->` +
- `<!--]]-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('nested consecutive fragment components with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `
- <template><components.Parent/></template>
- `,
- {
- Parent: `<template><div><span/><components.Child/><components.Child/><span/></div></template>`,
- Child: `<template><div>{{ data }}</div>-{{ data }}-</template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>foo</div>-foo-<!--]-->` +
- `<!--[[-->` +
- `<!--[--><div>foo</div>-foo-<!--]-->` +
- `<!--]]-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>bar</div>-bar-<!--]-->` +
- `<!--[[-->` +
- `<!--[--><div>bar</div>-bar-<!--]-->` +
- `<!--]]-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('nested consecutive fragment components with multi level anchor insertion', async () => {
- const { container, data } = await testHydration(
- `
- <template><div><span></span><components.Parent/><span></span></div></template>
- `,
- {
- Parent: `<template><div><span/><components.Child/><components.Child/><span/></div></template>`,
- Child: `<template><div>{{ data }}</div>-{{ data }}-</template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>` +
- `<span></span>` +
- `<!--[--><div>foo</div>-foo-<!--]-->` +
- `<!--[[-->` +
- `<!--[--><div>foo</div>-foo-<!--]-->` +
- `<!--]]-->` +
- `<span></span>` +
- `</div>` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>` +
- `<span></span>` +
- `<!--[--><div>bar</div>-bar-<!--]-->` +
- `<!--[[-->` +
- `<!--[--><div>bar</div>-bar-<!--]-->` +
- `<!--]]-->` +
- `<span></span>` +
- `</div>` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('nested consecutive fragment components with root level anchor insertion', async () => {
- const { container, data } = await testHydration(
- `
- <template><div><span></span><components.Parent/><span></span></div></template>
- `,
- {
- Parent: `<template><components.Child/><components.Child/></template>`,
- Child: `<template><div>{{ data }}</div>-{{ data }}-</template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[-->` +
- `<!--[--><div>foo</div>-foo-<!--]-->` +
- `<!--[--><div>foo</div>-foo-<!--]-->` +
- `<!--]-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[-->` +
- `<!--[--><div>bar</div>-bar-<!--]-->` +
- `<!--[--><div>bar</div>-bar-<!--]-->` +
- `<!--]-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('mixed fragment component and element with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span/>
- <components.Child/>
- <span/>
- <components.Child/>
- <span/>
- </div>
- </template>
- `,
- {
- Child: `<template><div>{{ data }}</div>-{{ data }}</template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>foo</div>-foo<!--]-->` +
- `<span></span>` +
- `<!--[--><div>foo</div>-foo<!--]-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>bar</div>-bar<!--]-->` +
- `<span></span>` +
- `<!--[--><div>bar</div>-bar<!--]-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('mixed fragment component and text with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span/>
- <components.Child/>
- {{ data }}
- <components.Child/>
- <span/>
- </div>
- </template>
- `,
- {
- Child: `<template><div>{{ data }}</div>-{{ data }}</template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>foo</div>-foo<!--]-->` +
- ` <!--[[--> foo <!--]]--> ` +
- `<!--[--><div>foo</div>-foo<!--]-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>bar</div>-bar<!--]-->` +
- ` <!--[[--> bar <!--]]--> ` +
- `<!--[--><div>bar</div>-bar<!--]-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- })
- describe('dynamic component', () => {
- const anchorLabel = DYNAMIC_COMPONENT_ANCHOR_LABEL
- test('basic dynamic component', async () => {
- const { container, data } = await testHydration(
- `<template>
- <component :is="components[data]"/>
- </template>`,
- {
- foo: `<template><div>foo</div></template>`,
- bar: `<template><div>bar</div></template>`,
- },
- ref('foo'),
- )
- expect(container.innerHTML).toBe(`<div>foo</div><!--${anchorLabel}-->`)
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(`<div>bar</div><!--${anchorLabel}-->`)
- })
- test('dynamic component with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span/>
- <component :is="components[data]"/>
- <span/>
- </div>
- </template>`,
- {
- foo: `<template><div>foo</div></template>`,
- bar: `<template><div>bar</div></template>`,
- },
- ref('foo'),
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>foo</div><!--${anchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>bar</div><!--${anchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('consecutive dynamic components with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span/>
- <component :is="components[data]"/>
- <component :is="components[data]"/>
- <span/>
- </div>
- </template>`,
- {
- foo: `<template><div>foo</div></template>`,
- bar: `<template><div>bar</div></template>`,
- },
- ref('foo'),
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>foo</div><!--${anchorLabel}-->` +
- `<!--[[--><div>foo</div><!--${anchorLabel}--><!--]]-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<div>bar</div><!--${anchorLabel}-->` +
- `<!--[[--><div>bar</div><!--${anchorLabel}--><!--]]-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('dynamic component fallback', async () => {
- const { container, data } = await testHydration(
- `<template>
- <component :is="'button'">
- <span>{{ data }}</span>
- </component>
- </template>`,
- {},
- ref('foo'),
- )
- expect(container.innerHTML).toBe(
- `<button><span>foo</span></button><!--${anchorLabel}-->`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<button><span>bar</span></button><!--${anchorLabel}-->`,
- )
- })
- })
- describe('if', () => {
- const anchorLabel = IF_ANCHOR_LABEL
- test('basic toggle - true -> false', async () => {
- const data = ref(true)
- const { container } = await testHydration(
- `<template>
- <div v-if="data">foo</div>
- </template>`,
- undefined,
- data,
- )
- expect(container.innerHTML).toBe(`<div>foo</div><!--${anchorLabel}-->`)
- data.value = false
- await nextTick()
- expect(container.innerHTML).toBe(`<!--${anchorLabel}-->`)
- })
- test('basic toggle - false -> true', async () => {
- const data = ref(false)
- const { container } = await testHydration(
- `<template>
- <div v-if="data">foo</div>
- </template>`,
- undefined,
- data,
- )
- // v-if="false" is rendered as <!----> in the server-rendered HTML
- // it reused as anchor, so the anchor label is empty
- expect(container.innerHTML).toBe(`<!---->`)
- data.value = true
- await nextTick()
- expect(container.innerHTML).toBe(`<div>foo</div><!---->`)
- })
- test('v-if on insertion parent', async () => {
- const data = ref(true)
- const { container } = await testHydration(
- `<template>
- <div v-if="data">
- <components.Child/>
- </div>
- </template>`,
- { Child: `<template>foo</template>` },
- data,
- )
- expect(container.innerHTML).toBe(`<div>foo</div><!--${anchorLabel}-->`)
- data.value = false
- await nextTick()
- expect(container.innerHTML).toBe(`<!--${anchorLabel}-->`)
- data.value = true
- await nextTick()
- expect(container.innerHTML).toBe(`<div>foo</div><!--${anchorLabel}-->`)
- })
- test('v-if/else-if/else chain - switch branches', async () => {
- const data = ref('a')
- const { container } = await testHydration(
- `<template>
- <div v-if="data === 'a'">foo</div>
- <div v-else-if="data === 'b'">bar</div>
- <div v-else>baz</div>
- </template>`,
- undefined,
- data,
- )
- expect(container.innerHTML).toBe(`<div>foo</div><!--${anchorLabel}-->`)
- data.value = 'b'
- await nextTick()
- expect(container.innerHTML).toBe(`<div>bar</div><!--${anchorLabel}-->`)
- data.value = 'c'
- await nextTick()
- expect(container.innerHTML).toBe(`<div>baz</div><!--${anchorLabel}-->`)
- data.value = 'a'
- await nextTick()
- expect(container.innerHTML).toBe(`<div>foo</div><!--${anchorLabel}-->`)
- })
- test('v-if/else-if/else chain - switch branches (PROD)', async () => {
- try {
- __DEV__ = false
- const data = ref('a')
- const { container } = await testHydration(
- `<template>
- <div v-if="data === 'a'">foo</div>
- <div v-else-if="data === 'b'">bar</div>
- <div v-else>baz</div>
- </template>`,
- undefined,
- data,
- )
- expect(container.innerHTML).toBe(`<div>foo</div><!--${anchorLabel}-->`)
- data.value = 'b'
- await nextTick()
- // In PROD, the anchor of v-else-if (DynamicFragment) is an empty text node,
- // so it won't be rendered
- expect(container.innerHTML).toBe(`<div>bar</div><!--${anchorLabel}-->`)
- data.value = 'c'
- await nextTick()
- // same as above
- expect(container.innerHTML).toBe(`<div>baz</div><!--${anchorLabel}-->`)
- data.value = 'a'
- await nextTick()
- expect(container.innerHTML).toBe(`<div>foo</div><!--${anchorLabel}-->`)
- } finally {
- __DEV__ = true
- }
- })
- test('nested if', async () => {
- const data = reactive({ outer: true, inner: true })
- const { container } = await testHydration(
- `<template>
- <div v-if="data.outer">
- <span>outer</span>
- <div v-if="data.inner">inner</div>
- </div>
- </template>`,
- undefined,
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span>outer</span>` +
- `<div>inner</div><!--${anchorLabel}-->` +
- `</div><!--${anchorLabel}-->`,
- )
- data.inner = false
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span>outer</span>` +
- `<!--${anchorLabel}-->` +
- `</div><!--${anchorLabel}-->`,
- )
- data.outer = false
- await nextTick()
- expect(container.innerHTML).toBe(`<!--${anchorLabel}-->`)
- })
- test('on component', async () => {
- const data = ref(true)
- const { container } = await testHydration(
- `<template>
- <components.Child v-if="data"/>
- </template>`,
- { Child: `<template>foo</template>` },
- data,
- )
- expect(container.innerHTML).toBe(`foo<!--${anchorLabel}-->`)
- data.value = false
- await nextTick()
- expect(container.innerHTML).toBe(`<!--${anchorLabel}-->`)
- })
- test('consecutive if node', async () => {
- const data = ref(true)
- const { container } = await testHydration(
- `<template>
- <components.Child v-if="data"/>
- </template>`,
- { Child: `<template><div v-if="data">foo</div></template>` },
- data,
- )
- expect(container.innerHTML).toBe(`<div>foo</div><!--if--><!--if-->`)
- data.value = false
- await nextTick()
- expect(container.innerHTML).toBe(`<!--if-->`)
- data.value = true
- await nextTick()
- expect(container.innerHTML).toBe(`<div>foo</div><!--if--><!--if-->`)
- })
- test('v-if/else-if/else chain on component - switch branches', async () => {
- const data = ref('a')
- const { container } = await testHydration(
- `<template>
- <components.Child1 v-if="data === 'a'"/>
- <components.Child2 v-else-if="data === 'b'"/>
- <components.Child3 v-else/>
- </template>`,
- {
- Child1: `<template><span>{{data}} child1</span></template>`,
- Child2: `<template><span>{{data}} child2</span></template>`,
- Child3: `<template><span>{{data}} child3</span></template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<span>a child1</span><!--${anchorLabel}-->`,
- )
- data.value = 'b'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<span>b child2</span><!--${anchorLabel}-->`,
- )
- data.value = 'c'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<span>c child3</span><!--${anchorLabel}-->`,
- )
- data.value = 'a'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<span>a child1</span><!--${anchorLabel}-->`,
- )
- })
- test('v-if/else-if/else chain on component - switch branches (PROD)', async () => {
- try {
- __DEV__ = false
- const data = ref('a')
- const { container } = await testHydration(
- `<template>
- <components.Child1 v-if="data === 'a'"/>
- <components.Child2 v-else-if="data === 'b'"/>
- <components.Child3 v-else/>
- </template>`,
- {
- Child1: `<template><span>{{data}} child1</span></template>`,
- Child2: `<template><span>{{data}} child2</span></template>`,
- Child3: `<template><span>{{data}} child3</span></template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<span>a child1</span><!--${anchorLabel}-->`,
- )
- data.value = 'b'
- await nextTick()
- // In PROD, the anchor of v-else-if (DynamicFragment) is an empty text node,
- // so it won't be rendered
- expect(container.innerHTML).toBe(
- `<span>b child2</span><!--${anchorLabel}-->`,
- )
- data.value = 'c'
- await nextTick()
- // same as above
- expect(container.innerHTML).toBe(
- `<span>c child3</span><!--${anchorLabel}-->`,
- )
- data.value = 'a'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<span>a child1</span><!--${anchorLabel}-->`,
- )
- } finally {
- __DEV__ = true
- }
- })
- test('on component with anchor insertion', async () => {
- const data = ref(true)
- const { container } = await testHydration(
- `<template>
- <div>
- <span/>
- <components.Child v-if="data"/>
- <span/>
- </div>
- </template>`,
- { Child: `<template>foo</template>` },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `foo<!--${anchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = false
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--${anchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('consecutive component with insertion parent', async () => {
- const data = reactive({
- show: true,
- foo: 'foo',
- bar: 'bar',
- })
- const { container } = await testHydration(
- `<template>
- <div v-if="data.show">
- <components.Child/>
- <components.Child2/>
- </div>
- </template>`,
- {
- Child: `<template><span>{{data.foo}}</span></template>`,
- Child2: `<template><span>{{data.bar}}</span></template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span>foo</span>` +
- `<span>bar</span>` +
- `</div>` +
- `<!--${anchorLabel}-->`,
- )
- data.show = false
- await nextTick()
- expect(container.innerHTML).toBe(`<!--${anchorLabel}-->`)
- })
- test('consecutive v-if on component with anchor insertion', async () => {
- const data = ref(true)
- const { container } = await testHydration(
- `<template>
- <div>
- <span/>
- <components.Child v-if="data"/>
- <components.Child v-if="data"/>
- <span/>
- </div>
- </template>`,
- { Child: `<template>foo</template>` },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `foo<!--${anchorLabel}-->` +
- `foo<!--${anchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = false
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--${anchorLabel}-->` +
- `<!--${anchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('on fragment component', async () => {
- const data = ref(true)
- const { container } = await testHydration(
- `<template>
- <div>
- <components.Child v-if="data"/>
- </div>
- </template>`,
- {
- Child: `<template><div>{{ data }}</div>-{{ data }}-</template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[--><div>true</div>-true-<!--]-->` +
- `<!--if-->` +
- `</div>`,
- )
- data.value = false
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div><!--[--><!--]--><!--${anchorLabel}--></div>`,
- )
- })
- test('on fragment component with anchor insertion', async () => {
- const data = ref(true)
- const { container } = await testHydration(
- `<template>
- <div>
- <span/>
- <components.Child v-if="data"/>
- <span/>
- </div>
- </template>`,
- {
- Child: `<template><div>{{ data }}</div>-{{ data }}-</template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>true</div>-true-<!--]-->` +
- `<!--if-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = false
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><!--]-->` +
- `<!--${anchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('consecutive v-if on fragment component with anchor insertion', async () => {
- const data = ref(true)
- const { container } = await testHydration(
- `<template>
- <div>
- <span/>
- <components.Child v-if="data"/>
- <components.Child v-if="data"/>
- <span/>
- </div>
- </template>`,
- {
- Child: `<template><div>{{ data }}</div>-{{ data }}-</template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><div>true</div>-true-<!--]--><!--${anchorLabel}-->` +
- `<!--[--><div>true</div>-true-<!--]--><!--${anchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = false
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><!--]--><!--${anchorLabel}-->` +
- `<!--[--><!--]--><!--${anchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('on dynamic component with anchor insertion', async () => {
- const dynamicComponentAnchorLabel = DYNAMIC_COMPONENT_ANCHOR_LABEL
- const data = ref(true)
- const { container } = await testHydration(
- `<template>
- <div>
- <span/>
- <component :is="components.Child" v-if="data"/>
- <span/>
- </div>
- </template>`,
- { Child: `<template>foo</template>` },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `foo<!--${dynamicComponentAnchorLabel}--><!--${anchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value = false
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--${anchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- })
- describe('for', () => {
- const forAnchorLabel = FOR_ANCHOR_LABEL
- const slotAnchorLabel = SLOT_ANCHOR_LABEL
- test('basic v-for', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span v-for="item in data" :key="item">{{ item }}</span>
- </div>
- </template>`,
- undefined,
- ref(['a', 'b', 'c']),
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[-->` +
- `<span>a</span>` +
- `<span>b</span>` +
- `<span>c</span>` +
- `<!--]--><!--${forAnchorLabel}-->` +
- `</div>`,
- )
- data.value.push('d')
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[-->` +
- `<span>a</span>` +
- `<span>b</span>` +
- `<span>c</span>` +
- `<!--]-->` +
- `<span>d</span>` +
- `<!--${forAnchorLabel}-->` +
- `</div>`,
- )
- })
- test('v-for with text node', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span v-for="item in data" :key="item">{{ item }}</span>
- </div>
- </template>`,
- undefined,
- ref(['a', 'b', 'c']),
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[-->` +
- `<span>a</span><span>b</span><span>c</span>` +
- `<!--]--><!--${forAnchorLabel}-->` +
- `</div>`,
- )
- data.value.push('d')
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[-->` +
- `<span>a</span><span>b</span><span>c</span>` +
- `<!--]-->` +
- `<span>d</span>` +
- `<!--${forAnchorLabel}-->` +
- `</div>`,
- )
- })
- test('v-for with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span/>
- <span v-for="item in data" :key="item">{{ item }}</span>
- <span/>
- </div>
- </template>`,
- undefined,
- ref(['a', 'b', 'c']),
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[-->` +
- `<span>a</span>` +
- `<span>b</span>` +
- `<span>c</span>` +
- `<!--]--><!--${forAnchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value.push('d')
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[-->` +
- `<span>a</span>` +
- `<span>b</span>` +
- `<span>c</span>` +
- `<!--]-->` +
- `<span>d</span>` +
- `<!--${forAnchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value.splice(0, 1)
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[-->` +
- `<span>b</span>` +
- `<span>c</span>` +
- `<!--]-->` +
- `<span>d</span>` +
- `<!--${forAnchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('consecutive v-for with anchor insertion', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <span/>
- <span v-for="item in data" :key="item">{{ item }}</span>
- <span v-for="item in data" :key="item">{{ item }}</span>
- <span/>
- </div>
- </template>`,
- undefined,
- ref(['a', 'b', 'c']),
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[-->` +
- `<span>a</span>` +
- `<span>b</span>` +
- `<span>c</span>` +
- `<!--]--><!--${forAnchorLabel}-->` +
- `<!--[-->` +
- `<span>a</span>` +
- `<span>b</span>` +
- `<span>c</span>` +
- `<!--]--><!--${forAnchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value.push('d')
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[-->` +
- `<span>a</span>` +
- `<span>b</span>` +
- `<span>c</span>` +
- `<!--]-->` +
- `<span>d</span>` +
- `<!--${forAnchorLabel}-->` +
- `<!--[-->` +
- `<span>a</span>` +
- `<span>b</span>` +
- `<span>c</span>` +
- `<!--]-->` +
- `<span>d</span>` +
- `<!--${forAnchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- data.value.splice(0, 2)
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[-->` +
- `<span>c</span>` +
- `<!--]-->` +
- `<span>d</span>` +
- `<!--${forAnchorLabel}-->` +
- `<!--[-->` +
- `<span>c</span>` +
- `<!--]-->` +
- `<span>d</span>` +
- `<!--${forAnchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('v-for on component', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <components.Child v-for="item in data" :key="item"/>
- </div>
- </template>`,
- {
- Child: `<template><div>comp</div></template>`,
- },
- ref(['a', 'b', 'c']),
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[-->` +
- `<div>comp</div>` +
- `<div>comp</div>` +
- `<div>comp</div>` +
- `<!--]--><!--${forAnchorLabel}-->` +
- `</div>`,
- )
- data.value.push('d')
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[-->` +
- `<div>comp</div>` +
- `<div>comp</div>` +
- `<div>comp</div>` +
- `<!--]-->` +
- `<div>comp</div>` +
- `<!--${forAnchorLabel}-->` +
- `</div>`,
- )
- })
- test('v-for on component with slots', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <components.Child v-for="item in data" :key="item">
- <span>{{ item }}</span>
- </components.Child>
- </div>
- </template>`,
- {
- Child: `<template><slot/></template>`,
- },
- ref(['a', 'b', 'c']),
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[-->` +
- `<!--[--><span>a</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><span>b</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><span>c</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--]--><!--${forAnchorLabel}-->` +
- `</div>`,
- )
- data.value.push('d')
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[-->` +
- `<!--[--><span>a</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><span>b</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><span>c</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--]-->` +
- `<span>d</span><!--${slotAnchorLabel}-->` +
- `<!--${forAnchorLabel}-->` +
- `</div>`,
- )
- })
- test('on fragment component', async () => {
- const { container, data } = await testHydration(
- `<template>
- <div>
- <components.Child v-for="item in data" :key="item"/>
- </div>
- </template>`,
- {
- Child: `<template><div>foo</div>-bar-</template>`,
- },
- ref(['a', 'b', 'c']),
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[-->` +
- `<!--[--><div>foo</div>-bar-<!--]-->` +
- `<!--[--><div>foo</div>-bar-<!--]-->` +
- `<!--[--><div>foo</div>-bar-<!--]-->` +
- `<!--]--><!--${forAnchorLabel}-->` +
- `</div>`,
- )
- data.value.push('d')
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[-->` +
- `<!--[--><div>foo</div>-bar-<!--]-->` +
- `<!--[--><div>foo</div>-bar-<!--]-->` +
- `<!--[--><div>foo</div>-bar-<!--]-->` +
- `<!--]-->` +
- `<div>foo</div>-bar-` +
- `<!--${forAnchorLabel}-->` +
- `</div>`,
- )
- })
- })
- describe('slots', () => {
- const slotAnchorLabel = SLOT_ANCHOR_LABEL
- const forAnchorLabel = FOR_ANCHOR_LABEL
- test('basic slot', async () => {
- const { data, container } = await testHydration(
- `<template>
- <components.Child>
- <span>{{data}}</span>
- </components.Child>
- </template>`,
- {
- Child: `<template><slot/></template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<!--[--><span>bar</span><!--]--><!--${slotAnchorLabel}-->`,
- )
- })
- test('named slot', async () => {
- const { data, container } = await testHydration(
- `<template>
- <components.Child>
- <template #foo>
- <span>{{data}}</span>
- </template>
- </components.Child>
- </template>`,
- {
- Child: `<template><slot name="foo"/></template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<!--[--><span>bar</span><!--]--><!--${slotAnchorLabel}-->`,
- )
- })
- test('named slot with v-if', async () => {
- const { data, container } = await testHydration(
- `<template>
- <components.Child>
- <template #foo v-if="data">
- <span>{{data}}</span>
- </template>
- </components.Child>
- </template>`,
- {
- Child: `<template><slot name="foo"/></template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->`,
- )
- data.value = false
- await nextTick()
- expect(container.innerHTML).toBe(
- `<!--[--><!--]--><!--${slotAnchorLabel}-->`,
- )
- })
- test('named slot with v-if and v-for', async () => {
- const data = reactive({
- show: true,
- items: ['a', 'b', 'c'],
- })
- const { container } = await testHydration(
- `<template>
- <components.Child>
- <template #foo v-if="data.show">
- <span v-for="item in data.items" :key="item">{{item}}</span>
- </template>
- </components.Child>
- </template>`,
- {
- Child: `<template><slot name="foo"/></template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<!--[-->` +
- `<!--[--><span>a</span><span>b</span><span>c</span><!--]--><!--${forAnchorLabel}-->` +
- `<!--]-->` +
- `<!--${slotAnchorLabel}-->`,
- )
- data.show = false
- await nextTick()
- expect(container.innerHTML).toBe(
- `<!--[--><!--[--><!--]--><!--]--><!--${slotAnchorLabel}-->`,
- )
- })
- test('with anchor insertion', async () => {
- const { data, container } = await testHydration(
- `<template>
- <components.Child>
- <span/>
- <span>{{data}}</span>
- <span/>
- </components.Child>
- </template>`,
- {
- Child: `<template><slot/></template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<!--[-->` +
- `<span></span>` +
- `<span>foo</span>` +
- `<span></span>` +
- `<!--]-->` +
- `<!--${slotAnchorLabel}-->`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<!--[-->` +
- `<span></span>` +
- `<span>bar</span>` +
- `<span></span>` +
- `<!--]-->` +
- `<!--${slotAnchorLabel}-->`,
- )
- })
- test('with multi level anchor insertion', async () => {
- const { data, container } = await testHydration(
- `<template>
- <components.Child>
- <span/>
- <span>{{data}}</span>
- <span/>
- </components.Child>
- </template>`,
- {
- Child: `
- <template>
- <div/>
- <div/>
- <slot/>
- <div/>
- </div>
- </template>`,
- },
- )
- expect(container.innerHTML).toBe(
- `<!--[-->` +
- `<div></div>` +
- `<div></div>` +
- `<!--[-->` +
- `<span></span>` +
- `<span>foo</span>` +
- `<span></span>` +
- `<!--]-->` +
- `<!--${slotAnchorLabel}-->` +
- `<div></div>` +
- `<!--]-->`,
- )
- data.value = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<!--[-->` +
- `<div></div>` +
- `<div></div>` +
- `<!--[-->` +
- `<span></span>` +
- `<span>bar</span>` +
- `<span></span>` +
- `<!--]-->` +
- `<!--${slotAnchorLabel}-->` +
- `<div></div>` +
- `<!--]-->`,
- )
- })
- test('mixed slot and text node', async () => {
- const data = reactive({
- text: 'foo',
- msg: 'hi',
- })
- const { container } = await testHydration(
- `<template>
- <components.Child>
- <span>{{data.text}}</span>
- </components.Child>
- </template>`,
- {
- Child: `<template><div><slot/>{{data.msg}}</div></template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `hi` +
- `</div>`,
- )
- data.msg = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `bar` +
- `</div>`,
- )
- })
- test('mixed root slot and text node', async () => {
- const data = reactive({
- text: 'foo',
- msg: 'hi',
- })
- const { container } = await testHydration(
- `<template>
- <components.Child>
- <span>{{data.text}}</span>
- </components.Child>
- </template>`,
- {
- Child: `<template>{{data.text}}<slot/>{{data.msg}}</template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<!--[-->` +
- `foo` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `hi` +
- `<!--]-->`,
- )
- data.msg = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<!--[-->` +
- `foo` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `bar` +
- `<!--]-->`,
- )
- })
- test('mixed consecutive slot and element', async () => {
- const data = reactive({
- text: 'foo',
- msg: 'hi',
- })
- const { container } = await testHydration(
- `<template>
- <components.Child>
- <template #foo><span>{{data.text}}</span></template>
- <template #bar><span>bar</span></template>
- </components.Child>
- </template>`,
- {
- Child: `<template><div><slot name="foo"/><slot name="bar"/><div>{{data.msg}}</div></div></template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><span>bar</span><!--]--><!--${slotAnchorLabel}-->` +
- `<div>hi</div>` +
- `</div>`,
- )
- data.msg = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><span>bar</span><!--]--><!--${slotAnchorLabel}-->` +
- `<div>bar</div>` +
- `</div>`,
- )
- })
- test('mixed slot and element', async () => {
- const data = reactive({
- text: 'foo',
- msg: 'hi',
- })
- const { container } = await testHydration(
- `<template>
- <components.Child>
- <span>{{data.text}}</span>
- </components.Child>
- </template>`,
- {
- Child: `<template><div><slot/><div>{{data.msg}}</div></div></template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<div>hi</div>` +
- `</div>`,
- )
- data.msg = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<div>bar</div>` +
- `</div>`,
- )
- })
- test('mixed slot and component', async () => {
- const data = reactive({
- msg1: 'foo',
- msg2: 'bar',
- })
- const { container } = await testHydration(
- `<template>
- <components.Child>
- <span>{{data.msg1}}</span>
- </components.Child>
- </template>`,
- {
- Child: `
- <template>
- <div>
- <components.Child2/>
- <slot/>
- <components.Child2/>
- </div>
- </template>`,
- Child2: `
- <template>
- <div>{{data.msg2}}</div>
- </template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<div>bar</div>` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<div>bar</div>` +
- `</div>`,
- )
- data.msg2 = 'hello'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<div>hello</div>` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<div>hello</div>` +
- `</div>`,
- )
- })
- test('mixed slot and fragment component', async () => {
- const data = reactive({
- msg1: 'foo',
- msg2: 'bar',
- })
- const { container } = await testHydration(
- `<template>
- <components.Child>
- <span>{{data.msg1}}</span>
- </components.Child>
- </template>`,
- {
- Child: `
- <template>
- <div>
- <components.Child2/>
- <slot/>
- <components.Child2/>
- </div>
- </template>`,
- Child2: `
- <template>
- <div>{{data.msg1}}</div> {{data.msg2}}
- </template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[--><div>foo</div> bar<!--]-->` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><div>foo</div> bar<!--]-->` +
- `</div>`,
- )
- data.msg1 = 'hello'
- data.msg2 = 'vapor'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[--><div>hello</div> vapor<!--]-->` +
- `<!--[--><span>hello</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><div>hello</div> vapor<!--]-->` +
- `</div>`,
- )
- })
- test('mixed slot and v-if', async () => {
- const data = reactive({
- show: true,
- msg: 'foo',
- })
- const { container } = await testHydration(
- `<template>
- <components.Child>
- <span>{{data.msg}}</span>
- </components.Child>
- </template>`,
- {
- Child: `
- <template>
- <div v-if="data.show">{{data.msg}}</div>
- <slot/>
- <div v-if="data.show">{{data.msg}}</div>
- </template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<!--[-->` +
- `<div>foo</div><!--if-->` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<div>foo</div><!--if-->` +
- `<!--]-->`,
- )
- data.show = false
- await nextTick()
- expect(container.innerHTML).toBe(
- `<!--[-->` +
- `<!--if-->` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--if-->` +
- `<!--]-->`,
- )
- })
- test('mixed slot and v-for', async () => {
- const data = reactive({
- items: ['a', 'b', 'c'],
- msg: 'foo',
- })
- const { container } = await testHydration(
- `<template>
- <components.Child>
- <span>{{data.msg}}</span>
- </components.Child>
- </template>`,
- {
- Child: `
- <template>
- <div v-for="item in data.items" :key="item">{{item}}</div>
- <slot/>
- <div v-for="item in data.items" :key="item">{{item}}</div>
- </template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<!--[-->` +
- `<!--[--><div>a</div><div>b</div><div>c</div><!--]--><!--${forAnchorLabel}-->` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><div>a</div><div>b</div><div>c</div><!--]--><!--${forAnchorLabel}-->` +
- `<!--]-->`,
- )
- data.items.push('d')
- await nextTick()
- expect(container.innerHTML).toBe(
- `<!--[-->` +
- `<!--[--><div>a</div><div>b</div><div>c</div><!--]--><div>d</div><!--${forAnchorLabel}-->` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><div>a</div><div>b</div><div>c</div><!--]--><div>d</div><!--${forAnchorLabel}-->` +
- `<!--]-->`,
- )
- })
- test('consecutive slots', async () => {
- const data = reactive({
- msg1: 'foo',
- msg2: 'bar',
- })
- const { container } = await testHydration(
- `<template>
- <components.Child>
- <span>{{data.msg1}}</span>
- <template #bar>
- <span>{{data.msg2}}</span>
- </template>
- </components.Child>
- </template>`,
- {
- Child: `<template><slot/><slot name="bar"/></template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<!--[-->` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><span>bar</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--]-->`,
- )
- data.msg1 = 'hello'
- data.msg2 = 'vapor'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<!--[-->` +
- `<!--[--><span>hello</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><span>vapor</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--]-->`,
- )
- })
- test('consecutive slots with anchor insertion', async () => {
- const data = reactive({
- msg1: 'foo',
- msg2: 'bar',
- })
- const { container } = await testHydration(
- `<template>
- <components.Child>
- <span>{{data.msg1}}</span>
- <template #bar>
- <span>{{data.msg2}}</span>
- </template>
- </components.Child>
- </template>`,
- {
- Child: `<template>
- <div>
- <span/>
- <slot/>
- <slot name="bar"/>
- <span/>
- </div>
- </template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><span>bar</span><!--]--><!--${slotAnchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- data.msg1 = 'hello'
- data.msg2 = 'vapor'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<span></span>` +
- `<!--[--><span>hello</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><span>vapor</span><!--]--><!--${slotAnchorLabel}-->` +
- `<span></span>` +
- `</div>`,
- )
- })
- test('consecutive slots prepend', async () => {
- const data = reactive({
- msg1: 'foo',
- msg2: 'bar',
- msg3: 'baz',
- })
- const { container } = await testHydration(
- `<template>
- <components.Child>
- <template #foo>
- <span>{{data.msg1}}</span>
- </template>
- <template #bar>
- <span>{{data.msg2}}</span>
- </template>
- </components.Child>
- </template>`,
- {
- Child: `<template>
- <div>
- <slot name="foo"/>
- <slot name="bar"/>
- <div>{{data.msg3}}</div>
- </div>
- </template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><span>bar</span><!--]--><!--${slotAnchorLabel}-->` +
- `<div>baz</div>` +
- `</div>`,
- )
- data.msg1 = 'hello'
- data.msg2 = 'vapor'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<div>` +
- `<!--[--><span>hello</span><!--]--><!--${slotAnchorLabel}-->` +
- `<!--[--><span>vapor</span><!--]--><!--${slotAnchorLabel}-->` +
- `<div>baz</div>` +
- `</div>`,
- )
- })
- test('slot fallback', async () => {
- const data = reactive({
- foo: 'foo',
- })
- const { container } = await testHydration(
- `<template>
- <components.Child>
- </components.Child>
- </template>`,
- {
- Child: `<template><slot><span>{{data.foo}}</span></slot></template>`,
- },
- data,
- )
- expect(container.innerHTML).toBe(
- `<!--[--><span>foo</span><!--]--><!--${slotAnchorLabel}-->`,
- )
- data.foo = 'bar'
- await nextTick()
- expect(container.innerHTML).toBe(
- `<!--[--><span>bar</span><!--]--><!--${slotAnchorLabel}-->`,
- )
- })
- })
- describe.todo('transition', async () => {
- test('transition appear', async () => {})
- test('transition appear with v-if', async () => {})
- test('transition appear with v-show', async () => {})
- test('transition appear w/ event listener', async () => {})
- })
- describe.todo('async component')
- describe.todo('data-allow-mismatch')
- // test('with data-allow-mismatch component when using onServerPrefetch', async () => {
- // const Comp = {
- // template: `
- // <div>Comp2</div>
- // `,
- // }
- // let foo: any
- // const App = {
- // setup() {
- // const flag = ref(true)
- // foo = () => {
- // flag.value = false
- // }
- // onServerPrefetch(() => (flag.value = false))
- // return { flag }
- // },
- // components: {
- // Comp,
- // },
- // template: `
- // <span data-allow-mismatch>
- // <Comp v-if="flag"></Comp>
- // </span>
- // `,
- // }
- // // hydrate
- // const container = document.createElement('div')
- // container.innerHTML = await renderToString(h(App))
- // createSSRApp(App).mount(container)
- // expect(container.innerHTML).toBe(
- // '<span data-allow-mismatch=""><div>Comp2</div></span>',
- // )
- // foo()
- // await nextTick()
- // expect(container.innerHTML).toBe(
- // '<span data-allow-mismatch=""><!--v-if--></span>',
- // )
- // })
- // // compile SSR + client render fn from the same template & hydrate
- // test('full compiler integration', async () => {
- // const mounted: string[] = []
- // const log = vi.fn()
- // const toggle = ref(true)
- // const Child = {
- // data() {
- // return {
- // count: 0,
- // text: 'hello',
- // style: {
- // color: 'red',
- // },
- // }
- // },
- // mounted() {
- // mounted.push('child')
- // },
- // template: `
- // <div>
- // <span class="count" :style="style">{{ count }}</span>
- // <button class="inc" @click="count++">inc</button>
- // <button class="change" @click="style.color = 'green'" >change color</button>
- // <button class="emit" @click="$emit('foo')">emit</button>
- // <span class="text">{{ text }}</span>
- // <input v-model="text">
- // </div>
- // `,
- // }
- // const App = {
- // setup() {
- // return { toggle }
- // },
- // mounted() {
- // mounted.push('parent')
- // },
- // template: `
- // <div>
- // <span>hello</span>
- // <template v-if="toggle">
- // <Child @foo="log('child')"/>
- // <template v-if="true">
- // <button class="parent-click" @click="log('click')">click me</button>
- // </template>
- // </template>
- // <span>hello</span>
- // </div>`,
- // components: {
- // Child,
- // },
- // methods: {
- // log,
- // },
- // }
- // const container = document.createElement('div')
- // // server render
- // container.innerHTML = await renderToString(h(App))
- // // hydrate
- // createSSRApp(App).mount(container)
- // // assert interactions
- // // 1. parent button click
- // triggerEvent('click', container.querySelector('.parent-click')!)
- // expect(log).toHaveBeenCalledWith('click')
- // // 2. child inc click + text interpolation
- // const count = container.querySelector('.count') as HTMLElement
- // expect(count.textContent).toBe(`0`)
- // triggerEvent('click', container.querySelector('.inc')!)
- // await nextTick()
- // expect(count.textContent).toBe(`1`)
- // // 3. child color click + style binding
- // expect(count.style.color).toBe('red')
- // triggerEvent('click', container.querySelector('.change')!)
- // await nextTick()
- // expect(count.style.color).toBe('green')
- // // 4. child event emit
- // triggerEvent('click', container.querySelector('.emit')!)
- // expect(log).toHaveBeenCalledWith('child')
- // // 5. child v-model
- // const text = container.querySelector('.text')!
- // const input = container.querySelector('input')!
- // expect(text.textContent).toBe('hello')
- // input.value = 'bye'
- // triggerEvent('input', input)
- // await nextTick()
- // expect(text.textContent).toBe('bye')
- // })
- // test('handle click error in ssr mode', async () => {
- // const App = {
- // setup() {
- // const throwError = () => {
- // throw new Error('Sentry Error')
- // }
- // return { throwError }
- // },
- // template: `
- // <div>
- // <button class="parent-click" @click="throwError">click me</button>
- // </div>`,
- // }
- // const container = document.createElement('div')
- // // server render
- // container.innerHTML = await renderToString(h(App))
- // // hydrate
- // const app = createSSRApp(App)
- // const handler = (app.config.errorHandler = vi.fn())
- // app.mount(container)
- // // assert interactions
- // // parent button click
- // triggerEvent('click', container.querySelector('.parent-click')!)
- // expect(handler).toHaveBeenCalled()
- // })
- // test('handle blur error in ssr mode', async () => {
- // const App = {
- // setup() {
- // const throwError = () => {
- // throw new Error('Sentry Error')
- // }
- // return { throwError }
- // },
- // template: `
- // <div>
- // <input class="parent-click" @blur="throwError"/>
- // </div>`,
- // }
- // const container = document.createElement('div')
- // // server render
- // container.innerHTML = await renderToString(h(App))
- // // hydrate
- // const app = createSSRApp(App)
- // const handler = (app.config.errorHandler = vi.fn())
- // app.mount(container)
- // // assert interactions
- // // parent blur event
- // triggerEvent('blur', container.querySelector('.parent-click')!)
- // expect(handler).toHaveBeenCalled()
- // })
- // test('async component', async () => {
- // const spy = vi.fn()
- // const Comp = () =>
- // h(
- // 'button',
- // {
- // onClick: spy,
- // },
- // 'hello!',
- // )
- // let serverResolve: any
- // let AsyncComp = defineAsyncComponent(
- // () =>
- // new Promise(r => {
- // serverResolve = r
- // }),
- // )
- // const App = {
- // render() {
- // return ['hello', h(AsyncComp), 'world']
- // },
- // }
- // // server render
- // const htmlPromise = renderToString(h(App))
- // serverResolve(Comp)
- // const html = await htmlPromise
- // expect(html).toMatchInlineSnapshot(
- // `"<!--[-->hello<button>hello!</button>world<!--]-->"`,
- // )
- // // hydration
- // let clientResolve: any
- // AsyncComp = defineAsyncComponent(
- // () =>
- // new Promise(r => {
- // clientResolve = r
- // }),
- // )
- // const container = document.createElement('div')
- // container.innerHTML = html
- // createSSRApp(App).mount(container)
- // // hydration not complete yet
- // triggerEvent('click', container.querySelector('button')!)
- // expect(spy).not.toHaveBeenCalled()
- // // resolve
- // clientResolve(Comp)
- // await new Promise(r => setTimeout(r))
- // // should be hydrated now
- // triggerEvent('click', container.querySelector('button')!)
- // expect(spy).toHaveBeenCalled()
- // })
- // test('update async wrapper before resolve', async () => {
- // const Comp = {
- // render() {
- // return h('h1', 'Async component')
- // },
- // }
- // let serverResolve: any
- // let AsyncComp = defineAsyncComponent(
- // () =>
- // new Promise(r => {
- // serverResolve = r
- // }),
- // )
- // const toggle = ref(true)
- // const App = {
- // setup() {
- // onMounted(() => {
- // // change state, this makes updateComponent(AsyncComp) execute before
- // // the async component is resolved
- // toggle.value = false
- // })
- // return () => {
- // return [toggle.value ? 'hello' : 'world', h(AsyncComp)]
- // }
- // },
- // }
- // // server render
- // const htmlPromise = renderToString(h(App))
- // serverResolve(Comp)
- // const html = await htmlPromise
- // expect(html).toMatchInlineSnapshot(
- // `"<!--[-->hello<h1>Async component</h1><!--]-->"`,
- // )
- // // hydration
- // let clientResolve: any
- // AsyncComp = defineAsyncComponent(
- // () =>
- // new Promise(r => {
- // clientResolve = r
- // }),
- // )
- // const container = document.createElement('div')
- // container.innerHTML = html
- // createSSRApp(App).mount(container)
- // // resolve
- // clientResolve(Comp)
- // await new Promise(r => setTimeout(r))
- // // should be hydrated now
- // expect(`Hydration node mismatch`).not.toHaveBeenWarned()
- // expect(container.innerHTML).toMatchInlineSnapshot(
- // `"<!--[-->world<h1>Async component</h1><!--]-->"`,
- // )
- // })
- // test('hydrate safely when property used by async setup changed before render', async () => {
- // const toggle = ref(true)
- // const AsyncComp = {
- // async setup() {
- // await new Promise<void>(r => setTimeout(r, 10))
- // return () => h('h1', 'Async component')
- // },
- // }
- // const AsyncWrapper = {
- // render() {
- // return h(AsyncComp)
- // },
- // }
- // const SiblingComp = {
- // setup() {
- // toggle.value = false
- // return () => h('span')
- // },
- // }
- // const App = {
- // setup() {
- // return () =>
- // h(
- // Suspense,
- // {},
- // {
- // default: () => [
- // h('main', {}, [
- // h(AsyncWrapper, {
- // prop: toggle.value ? 'hello' : 'world',
- // }),
- // h(SiblingComp),
- // ]),
- // ],
- // },
- // )
- // },
- // }
- // // server render
- // const html = await renderToString(h(App))
- // expect(html).toMatchInlineSnapshot(
- // `"<main><h1 prop="hello">Async component</h1><span></span></main>"`,
- // )
- // expect(toggle.value).toBe(false)
- // // hydration
- // // reset the value
- // toggle.value = true
- // expect(toggle.value).toBe(true)
- // const container = document.createElement('div')
- // container.innerHTML = html
- // createSSRApp(App).mount(container)
- // await new Promise(r => setTimeout(r, 10))
- // expect(toggle.value).toBe(false)
- // // should be hydrated now
- // expect(container.innerHTML).toMatchInlineSnapshot(
- // `"<main><h1 prop="world">Async component</h1><span></span></main>"`,
- // )
- // })
- // test('hydrate safely when property used by deep nested async setup changed before render', async () => {
- // const toggle = ref(true)
- // const AsyncComp = {
- // async setup() {
- // await new Promise<void>(r => setTimeout(r, 10))
- // return () => h('h1', 'Async component')
- // },
- // }
- // const AsyncWrapper = { render: () => h(AsyncComp) }
- // const AsyncWrapperWrapper = { render: () => h(AsyncWrapper) }
- // const SiblingComp = {
- // setup() {
- // toggle.value = false
- // return () => h('span')
- // },
- // }
- // const App = {
- // setup() {
- // return () =>
- // h(
- // Suspense,
- // {},
- // {
- // default: () => [
- // h('main', {}, [
- // h(AsyncWrapperWrapper, {
- // prop: toggle.value ? 'hello' : 'world',
- // }),
- // h(SiblingComp),
- // ]),
- // ],
- // },
- // )
- // },
- // }
- // // server render
- // const html = await renderToString(h(App))
- // expect(html).toMatchInlineSnapshot(
- // `"<main><h1 prop="hello">Async component</h1><span></span></main>"`,
- // )
- // expect(toggle.value).toBe(false)
- // // hydration
- // // reset the value
- // toggle.value = true
- // expect(toggle.value).toBe(true)
- // const container = document.createElement('div')
- // container.innerHTML = html
- // createSSRApp(App).mount(container)
- // await new Promise(r => setTimeout(r, 10))
- // expect(toggle.value).toBe(false)
- // // should be hydrated now
- // expect(container.innerHTML).toMatchInlineSnapshot(
- // `"<main><h1 prop="world">Async component</h1><span></span></main>"`,
- // )
- // })
- // // #3787
- // test('unmount async wrapper before load', async () => {
- // let resolve: any
- // const AsyncComp = defineAsyncComponent(
- // () =>
- // new Promise(r => {
- // resolve = r
- // }),
- // )
- // const show = ref(true)
- // const root = document.createElement('div')
- // root.innerHTML = '<div><div>async</div></div>'
- // createSSRApp({
- // render() {
- // return h('div', [show.value ? h(AsyncComp) : h('div', 'hi')])
- // },
- // }).mount(root)
- // show.value = false
- // await nextTick()
- // expect(root.innerHTML).toBe('<div><div>hi</div></div>')
- // resolve({})
- // })
- // //#12362
- // test('nested async wrapper', async () => {
- // const Toggle = defineAsyncComponent(
- // () =>
- // new Promise(r => {
- // r(
- // defineComponent({
- // setup(_, { slots }) {
- // const show = ref(false)
- // onMounted(() => {
- // nextTick(() => {
- // show.value = true
- // })
- // })
- // return () =>
- // withDirectives(
- // h('div', null, [renderSlot(slots, 'default')]),
- // [[vShow, show.value]],
- // )
- // },
- // }) as any,
- // )
- // }),
- // )
- // const Wrapper = defineAsyncComponent(() => {
- // return new Promise(r => {
- // r(
- // defineComponent({
- // render(this: any) {
- // return renderSlot(this.$slots, 'default')
- // },
- // }) as any,
- // )
- // })
- // })
- // const count = ref(0)
- // const fn = vi.fn()
- // const Child = {
- // setup() {
- // onMounted(() => {
- // fn()
- // count.value++
- // })
- // return () => h('div', count.value)
- // },
- // }
- // const App = {
- // render() {
- // return h(Toggle, null, {
- // default: () =>
- // h(Wrapper, null, {
- // default: () =>
- // h(Wrapper, null, {
- // default: () => h(Child),
- // }),
- // }),
- // })
- // },
- // }
- // const root = document.createElement('div')
- // root.innerHTML = await renderToString(h(App))
- // expect(root.innerHTML).toMatchInlineSnapshot(
- // `"<div style="display:none;"><!--[--><!--[--><!--[--><div>0</div><!--]--><!--]--><!--]--></div>"`,
- // )
- // createSSRApp(App).mount(root)
- // await nextTick()
- // await nextTick()
- // expect(root.innerHTML).toMatchInlineSnapshot(
- // `"<div style=""><!--[--><!--[--><!--[--><div>1</div><!--]--><!--]--><!--]--></div>"`,
- // )
- // expect(fn).toBeCalledTimes(1)
- // })
- // test('unmount async wrapper before load (fragment)', async () => {
- // let resolve: any
- // const AsyncComp = defineAsyncComponent(
- // () =>
- // new Promise(r => {
- // resolve = r
- // }),
- // )
- // const show = ref(true)
- // const root = document.createElement('div')
- // root.innerHTML = '<div><!--[-->async<!--]--></div>'
- // createSSRApp({
- // render() {
- // return h('div', [show.value ? h(AsyncComp) : h('div', 'hi')])
- // },
- // }).mount(root)
- // show.value = false
- // await nextTick()
- // expect(root.innerHTML).toBe('<div><div>hi</div></div>')
- // resolve({})
- // })
- // test('elements with camel-case in svg ', () => {
- // const { vnode, container } = mountWithHydration(
- // '<animateTransform></animateTransform>',
- // () => h('animateTransform'),
- // )
- // expect(vnode.el).toBe(container.firstChild)
- // expect(`Hydration node mismatch`).not.toHaveBeenWarned()
- // })
- // test('SVG as a mount container', () => {
- // const svgContainer = document.createElement('svg')
- // svgContainer.innerHTML = '<g></g>'
- // const app = createSSRApp({
- // render: () => h('g'),
- // })
- // expect(
- // (
- // app.mount(svgContainer).$.subTree as VNode<Node, Element> & {
- // el: Element
- // }
- // ).el instanceof SVGElement,
- // )
- // })
- // test('force hydrate prop with `.prop` modifier', () => {
- // const { container } = mountWithHydration('<input type="checkbox">', () =>
- // h('input', {
- // type: 'checkbox',
- // '.indeterminate': true,
- // }),
- // )
- // expect((container.firstChild! as any).indeterminate).toBe(true)
- // })
- // test('force hydrate input v-model with non-string value bindings', () => {
- // const { container } = mountWithHydration(
- // '<input type="checkbox" value="true">',
- // () =>
- // withDirectives(
- // createVNode(
- // 'input',
- // { type: 'checkbox', 'true-value': true },
- // null,
- // PatchFlags.PROPS,
- // ['true-value'],
- // ),
- // [[vModelCheckbox, true]],
- // ),
- // )
- // expect((container.firstChild as any)._trueValue).toBe(true)
- // })
- // test('force hydrate checkbox with indeterminate', () => {
- // const { container } = mountWithHydration(
- // '<input type="checkbox" indeterminate>',
- // () =>
- // createVNode(
- // 'input',
- // { type: 'checkbox', indeterminate: '' },
- // null,
- // PatchFlags.CACHED,
- // ),
- // )
- // expect((container.firstChild as any).indeterminate).toBe(true)
- // })
- // test('force hydrate select option with non-string value bindings', () => {
- // const { container } = mountWithHydration(
- // '<select><option value="true">ok</option></select>',
- // () =>
- // h('select', [
- // // hoisted because bound value is a constant...
- // createVNode('option', { value: true }, null, -1 /* HOISTED */),
- // ]),
- // )
- // expect((container.firstChild!.firstChild as any)._value).toBe(true)
- // })
- // // #7203
- // test('force hydrate custom element with dynamic props', () => {
- // class MyElement extends HTMLElement {
- // foo = ''
- // constructor() {
- // super()
- // }
- // }
- // customElements.define('my-element-7203', MyElement)
- // const msg = ref('bar')
- // const container = document.createElement('div')
- // container.innerHTML = '<my-element-7203></my-element-7203>'
- // const app = createSSRApp({
- // render: () => h('my-element-7203', { foo: msg.value }),
- // })
- // app.mount(container)
- // expect((container.firstChild as any).foo).toBe(msg.value)
- // })
- // // #5728
- // test('empty text node in slot', () => {
- // const Comp = {
- // render(this: any) {
- // return renderSlot(this.$slots, 'default', {}, () => [
- // createTextVNode(''),
- // ])
- // },
- // }
- // const { container, vnode } = mountWithHydration('<!--[--><!--]-->', () =>
- // h(Comp),
- // )
- // expect(container.childNodes.length).toBe(3)
- // const text = container.childNodes[1]
- // expect(text.nodeType).toBe(3)
- // expect(vnode.el).toBe(container.childNodes[0])
- // // component => slot fragment => text node
- // expect((vnode as any).component?.subTree.children[0].el).toBe(text)
- // })
- // // #7215
- // test('empty text node', () => {
- // const Comp = {
- // render(this: any) {
- // return h('p', [''])
- // },
- // }
- // const { container } = mountWithHydration('<p></p>', () => h(Comp))
- // expect(container.childNodes.length).toBe(1)
- // const p = container.childNodes[0]
- // expect(p.childNodes.length).toBe(1)
- // const text = p.childNodes[0]
- // expect(text.nodeType).toBe(3)
- // })
- // // #11372
- // test('object style value tracking in prod', async () => {
- // __DEV__ = false
- // try {
- // const style = reactive({ color: 'red' })
- // const Comp = {
- // render(this: any) {
- // return (
- // openBlock(),
- // createElementBlock(
- // 'div',
- // {
- // style: normalizeStyle(style),
- // },
- // null,
- // 4 /* STYLE */,
- // )
- // )
- // },
- // }
- // const { container } = mountWithHydration(
- // `<div style="color: red;"></div>`,
- // () => h(Comp),
- // )
- // style.color = 'green'
- // await nextTick()
- // expect(container.innerHTML).toBe(`<div style="color: green;"></div>`)
- // } finally {
- // __DEV__ = true
- // }
- // })
- // test('app.unmount()', async () => {
- // const container = document.createElement('DIV')
- // container.innerHTML = '<button></button>'
- // const App = defineComponent({
- // setup(_, { expose }) {
- // const count = ref(0)
- // expose({ count })
- // return () =>
- // h('button', {
- // onClick: () => count.value++,
- // })
- // },
- // })
- // const app = createSSRApp(App)
- // const vm = app.mount(container)
- // await nextTick()
- // expect((container as any)._vnode).toBeDefined()
- // // @ts-expect-error - expose()'d properties are not available on vm type
- // expect(vm.count).toBe(0)
- // app.unmount()
- // expect((container as any)._vnode).toBe(null)
- // })
- // // #6637
- // test('stringified root fragment', () => {
- // mountWithHydration(`<!--[--><div></div><!--]-->`, () =>
- // createStaticVNode(`<div></div>`, 1),
- // )
- // expect(`mismatch`).not.toHaveBeenWarned()
- // })
- // test('transition appear', () => {
- // const { vnode, container } = mountWithHydration(
- // `<template><div>foo</div></template>`,
- // () =>
- // h(
- // Transition,
- // { appear: true },
- // {
- // default: () => h('div', 'foo'),
- // },
- // ),
- // )
- // expect(container.firstChild).toMatchInlineSnapshot(`
- // <div
- // class="v-enter-from v-enter-active"
- // >
- // foo
- // </div>
- // `)
- // expect(vnode.el).toBe(container.firstChild)
- // expect(`mismatch`).not.toHaveBeenWarned()
- // })
- // test('transition appear with v-if', () => {
- // const show = false
- // const { vnode, container } = mountWithHydration(
- // `<template><!----></template>`,
- // () =>
- // h(
- // Transition,
- // { appear: true },
- // {
- // default: () => (show ? h('div', 'foo') : createCommentVNode('')),
- // },
- // ),
- // )
- // expect(container.firstChild).toMatchInlineSnapshot('<!---->')
- // expect(vnode.el).toBe(container.firstChild)
- // expect(`mismatch`).not.toHaveBeenWarned()
- // })
- // test('transition appear with v-show', () => {
- // const show = false
- // const { vnode, container } = mountWithHydration(
- // `<template><div style="display: none;">foo</div></template>`,
- // () =>
- // h(
- // Transition,
- // { appear: true },
- // {
- // default: () =>
- // withDirectives(createVNode('div', null, 'foo'), [[vShow, show]]),
- // },
- // ),
- // )
- // expect(container.firstChild).toMatchInlineSnapshot(`
- // <div
- // class="v-enter-from v-enter-active"
- // style="display: none;"
- // >
- // foo
- // </div>
- // `)
- // expect((container.firstChild as any)[vShowOriginalDisplay]).toBe('')
- // expect(vnode.el).toBe(container.firstChild)
- // expect(`mismatch`).not.toHaveBeenWarned()
- // })
- // test('transition appear w/ event listener', async () => {
- // const container = document.createElement('div')
- // container.innerHTML = `<template><button>0</button></template>`
- // createSSRApp({
- // data() {
- // return {
- // count: 0,
- // }
- // },
- // template: `
- // <Transition appear>
- // <button @click="count++">{{count}}</button>
- // </Transition>
- // `,
- // }).mount(container)
- // expect(container.firstChild).toMatchInlineSnapshot(`
- // <button
- // class="v-enter-from v-enter-active"
- // >
- // 0
- // </button>
- // `)
- // triggerEvent('click', container.querySelector('button')!)
- // await nextTick()
- // expect(container.firstChild).toMatchInlineSnapshot(`
- // <button
- // class="v-enter-from v-enter-active"
- // >
- // 1
- // </button>
- // `)
- // })
- // test('Suspense + transition appear', async () => {
- // const { vnode, container } = mountWithHydration(
- // `<template><div>foo</div></template>`,
- // () =>
- // h(Suspense, {}, () =>
- // h(
- // Transition,
- // { appear: true },
- // {
- // default: () => h('div', 'foo'),
- // },
- // ),
- // ),
- // )
- // expect(vnode.el).toBe(container.firstChild)
- // // wait for hydration to finish
- // await new Promise(r => setTimeout(r))
- // expect(container.firstChild).toMatchInlineSnapshot(`
- // <div
- // class="v-enter-from v-enter-active"
- // >
- // foo
- // </div>
- // `)
- // await nextTick()
- // expect(vnode.el).toBe(container.firstChild)
- // })
- // // #10607
- // test('update component stable slot (prod + optimized mode)', async () => {
- // __DEV__ = false
- // try {
- // const container = document.createElement('div')
- // container.innerHTML = `<template><div show="false"><!--[--><div><div><!----></div></div><div>0</div><!--]--></div></template>`
- // const Comp = {
- // render(this: any) {
- // return (
- // openBlock(),
- // createElementBlock('div', null, [
- // renderSlot(this.$slots, 'default'),
- // ])
- // )
- // },
- // }
- // const show = ref(false)
- // const clicked = ref(false)
- // const Wrapper = {
- // setup() {
- // const items = ref<number[]>([])
- // onMounted(() => {
- // items.value = [1]
- // })
- // return () => {
- // return (
- // openBlock(),
- // createBlock(Comp, null, {
- // default: withCtx(() => [
- // createElementVNode('div', null, [
- // createElementVNode('div', null, [
- // clicked.value
- // ? (openBlock(),
- // createElementBlock('div', { key: 0 }, 'foo'))
- // : createCommentVNode('v-if', true),
- // ]),
- // ]),
- // createElementVNode(
- // 'div',
- // null,
- // items.value.length,
- // 1 /* TEXT */,
- // ),
- // ]),
- // _: 1 /* STABLE */,
- // })
- // )
- // }
- // },
- // }
- // createSSRApp({
- // components: { Wrapper },
- // data() {
- // return { show }
- // },
- // template: `<Wrapper :show="show"/>`,
- // }).mount(container)
- // await nextTick()
- // expect(container.innerHTML).toBe(
- // `<div show="false"><!--[--><div><div><!----></div></div><div>1</div><!--]--></div>`,
- // )
- // show.value = true
- // await nextTick()
- // expect(async () => {
- // clicked.value = true
- // await nextTick()
- // }).not.toThrow("Cannot read properties of null (reading 'insertBefore')")
- // await nextTick()
- // expect(container.innerHTML).toBe(
- // `<div show="true"><!--[--><div><div><div>foo</div></div></div><div>1</div><!--]--></div>`,
- // )
- // } catch (e) {
- // throw e
- // } finally {
- // __DEV__ = true
- // }
- // })
- // describe('mismatch handling', () => {
- // test('text node', () => {
- // const { container } = mountWithHydration(`foo`, () => 'bar')
- // expect(container.textContent).toBe('bar')
- // expect(`Hydration text mismatch`).toHaveBeenWarned()
- // })
- // test('element text content', () => {
- // const { container } = mountWithHydration(`<div>foo</div>`, () =>
- // h('div', 'bar'),
- // )
- // expect(container.innerHTML).toBe('<div>bar</div>')
- // expect(`Hydration text content mismatch`).toHaveBeenWarned()
- // })
- // test('not enough children', () => {
- // const { container } = mountWithHydration(`<div></div>`, () =>
- // h('div', [h('span', 'foo'), h('span', 'bar')]),
- // )
- // expect(container.innerHTML).toBe(
- // '<div><span>foo</span><span>bar</span></div>',
- // )
- // expect(`Hydration children mismatch`).toHaveBeenWarned()
- // })
- // test('too many children', () => {
- // const { container } = mountWithHydration(
- // `<div><span>foo</span><span>bar</span></div>`,
- // () => h('div', [h('span', 'foo')]),
- // )
- // expect(container.innerHTML).toBe('<div><span>foo</span></div>')
- // expect(`Hydration children mismatch`).toHaveBeenWarned()
- // })
- // test('complete mismatch', () => {
- // const { container } = mountWithHydration(
- // `<div><span>foo</span><span>bar</span></div>`,
- // () => h('div', [h('div', 'foo'), h('p', 'bar')]),
- // )
- // expect(container.innerHTML).toBe('<div><div>foo</div><p>bar</p></div>')
- // expect(`Hydration node mismatch`).toHaveBeenWarnedTimes(2)
- // })
- // test('fragment mismatch removal', () => {
- // const { container } = mountWithHydration(
- // `<div><!--[--><div>foo</div><div>bar</div><!--]--></div>`,
- // () => h('div', [h('span', 'replaced')]),
- // )
- // expect(container.innerHTML).toBe('<div><span>replaced</span></div>')
- // expect(`Hydration node mismatch`).toHaveBeenWarned()
- // })
- // test('fragment not enough children', () => {
- // const { container } = mountWithHydration(
- // `<div><!--[--><div>foo</div><!--]--><div>baz</div></div>`,
- // () => h('div', [[h('div', 'foo'), h('div', 'bar')], h('div', 'baz')]),
- // )
- // expect(container.innerHTML).toBe(
- // '<div><!--[--><div>foo</div><div>bar</div><!--]--><div>baz</div></div>',
- // )
- // expect(`Hydration node mismatch`).toHaveBeenWarned()
- // })
- // test('fragment too many children', () => {
- // const { container } = mountWithHydration(
- // `<div><!--[--><div>foo</div><div>bar</div><!--]--><div>baz</div></div>`,
- // () => h('div', [[h('div', 'foo')], h('div', 'baz')]),
- // )
- // expect(container.innerHTML).toBe(
- // '<div><!--[--><div>foo</div><!--]--><div>baz</div></div>',
- // )
- // // fragment ends early and attempts to hydrate the extra <div>bar</div>
- // // as 2nd fragment child.
- // expect(`Hydration text content mismatch`).toHaveBeenWarned()
- // // excessive children removal
- // expect(`Hydration children mismatch`).toHaveBeenWarned()
- // })
- // test('Teleport target has empty children', () => {
- // const teleportContainer = document.createElement('div')
- // teleportContainer.id = 'teleport'
- // document.body.appendChild(teleportContainer)
- // mountWithHydration('<!--teleport start--><!--teleport end-->', () =>
- // h(Teleport, { to: '#teleport' }, [h('span', 'value')]),
- // )
- // expect(teleportContainer.innerHTML).toBe(`<span>value</span>`)
- // expect(`Hydration children mismatch`).toHaveBeenWarned()
- // })
- // test('comment mismatch (element)', () => {
- // const { container } = mountWithHydration(`<div><span></span></div>`, () =>
- // h('div', [createCommentVNode('hi')]),
- // )
- // expect(container.innerHTML).toBe('<div><!--hi--></div>')
- // expect(`Hydration node mismatch`).toHaveBeenWarned()
- // })
- // test('comment mismatch (text)', () => {
- // const { container } = mountWithHydration(`<div>foobar</div>`, () =>
- // h('div', [createCommentVNode('hi')]),
- // )
- // expect(container.innerHTML).toBe('<div><!--hi--></div>')
- // expect(`Hydration node mismatch`).toHaveBeenWarned()
- // })
- // test('class mismatch', () => {
- // mountWithHydration(`<div class="foo bar"></div>`, () =>
- // h('div', { class: ['foo', 'bar'] }),
- // )
- // mountWithHydration(`<div class="foo bar"></div>`, () =>
- // h('div', { class: { foo: true, bar: true } }),
- // )
- // mountWithHydration(`<div class="foo bar"></div>`, () =>
- // h('div', { class: 'foo bar' }),
- // )
- // // SVG classes
- // mountWithHydration(`<svg class="foo bar"></svg>`, () =>
- // h('svg', { class: 'foo bar' }),
- // )
- // // class with different order
- // mountWithHydration(`<div class="foo bar"></div>`, () =>
- // h('div', { class: 'bar foo' }),
- // )
- // expect(`Hydration class mismatch`).not.toHaveBeenWarned()
- // mountWithHydration(`<div class="foo bar"></div>`, () =>
- // h('div', { class: 'foo' }),
- // )
- // expect(`Hydration class mismatch`).toHaveBeenWarned()
- // })
- // test('style mismatch', () => {
- // mountWithHydration(`<div style="color:red;"></div>`, () =>
- // h('div', { style: { color: 'red' } }),
- // )
- // mountWithHydration(`<div style="color:red;"></div>`, () =>
- // h('div', { style: `color:red;` }),
- // )
- // mountWithHydration(
- // `<div style="color:red; font-size: 12px;"></div>`,
- // () => h('div', { style: `font-size: 12px; color:red;` }),
- // )
- // mountWithHydration(`<div style="color:red;display:none;"></div>`, () =>
- // withDirectives(createVNode('div', { style: 'color: red' }, ''), [
- // [vShow, false],
- // ]),
- // )
- // expect(`Hydration style mismatch`).not.toHaveBeenWarned()
- // mountWithHydration(`<div style="color:red;"></div>`, () =>
- // h('div', { style: { color: 'green' } }),
- // )
- // expect(`Hydration style mismatch`).toHaveBeenWarnedTimes(1)
- // })
- // test('style mismatch when no style attribute is present', () => {
- // mountWithHydration(`<div></div>`, () =>
- // h('div', { style: { color: 'red' } }),
- // )
- // expect(`Hydration style mismatch`).toHaveBeenWarnedTimes(1)
- // })
- // test('style mismatch w/ v-show', () => {
- // mountWithHydration(`<div style="color:red;display:none"></div>`, () =>
- // withDirectives(createVNode('div', { style: 'color: red' }, ''), [
- // [vShow, false],
- // ]),
- // )
- // expect(`Hydration style mismatch`).not.toHaveBeenWarned()
- // mountWithHydration(`<div style="color:red;"></div>`, () =>
- // withDirectives(createVNode('div', { style: 'color: red' }, ''), [
- // [vShow, false],
- // ]),
- // )
- // expect(`Hydration style mismatch`).toHaveBeenWarnedTimes(1)
- // })
- // test('attr mismatch', () => {
- // mountWithHydration(`<div id="foo"></div>`, () => h('div', { id: 'foo' }))
- // mountWithHydration(`<div spellcheck></div>`, () =>
- // h('div', { spellcheck: '' }),
- // )
- // mountWithHydration(`<div></div>`, () => h('div', { id: undefined }))
- // // boolean
- // mountWithHydration(`<select multiple></div>`, () =>
- // h('select', { multiple: true }),
- // )
- // mountWithHydration(`<select multiple></div>`, () =>
- // h('select', { multiple: 'multiple' }),
- // )
- // expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
- // mountWithHydration(`<div></div>`, () => h('div', { id: 'foo' }))
- // expect(`Hydration attribute mismatch`).toHaveBeenWarnedTimes(1)
- // mountWithHydration(`<div id="bar"></div>`, () => h('div', { id: 'foo' }))
- // expect(`Hydration attribute mismatch`).toHaveBeenWarnedTimes(2)
- // })
- // test('attr special case: textarea value', () => {
- // mountWithHydration(`<textarea>foo</textarea>`, () =>
- // h('textarea', { value: 'foo' }),
- // )
- // mountWithHydration(`<textarea></textarea>`, () =>
- // h('textarea', { value: '' }),
- // )
- // expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
- // mountWithHydration(`<textarea>foo</textarea>`, () =>
- // h('textarea', { value: 'bar' }),
- // )
- // expect(`Hydration attribute mismatch`).toHaveBeenWarned()
- // })
- // // #11873
- // test('<textarea> with newlines at the beginning', async () => {
- // const render = () => h('textarea', null, '\nhello')
- // const html = await renderToString(createSSRApp({ render }))
- // mountWithHydration(html, render)
- // expect(`Hydration text content mismatch`).not.toHaveBeenWarned()
- // })
- // test('<pre> with newlines at the beginning', async () => {
- // const render = () => h('pre', null, '\n')
- // const html = await renderToString(createSSRApp({ render }))
- // mountWithHydration(html, render)
- // expect(`Hydration text content mismatch`).not.toHaveBeenWarned()
- // })
- // test('boolean attr handling', () => {
- // mountWithHydration(`<input />`, () => h('input', { readonly: false }))
- // expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
- // mountWithHydration(`<input readonly />`, () =>
- // h('input', { readonly: true }),
- // )
- // expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
- // mountWithHydration(`<input readonly="readonly" />`, () =>
- // h('input', { readonly: true }),
- // )
- // expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
- // })
- // test('client value is null or undefined', () => {
- // mountWithHydration(`<div></div>`, () =>
- // h('div', { draggable: undefined }),
- // )
- // expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
- // mountWithHydration(`<input />`, () => h('input', { type: null }))
- // expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
- // })
- // test('should not warn against object values', () => {
- // mountWithHydration(`<input />`, () => h('input', { from: {} }))
- // expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
- // })
- // test('should not warn on falsy bindings of non-property keys', () => {
- // mountWithHydration(`<button />`, () => h('button', { href: undefined }))
- // expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
- // })
- // test('should not warn on non-renderable option values', () => {
- // mountWithHydration(`<select><option>hello</option></select>`, () =>
- // h('select', [h('option', { value: ['foo'] }, 'hello')]),
- // )
- // expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
- // })
- // test('should not warn css v-bind', () => {
- // const container = document.createElement('div')
- // container.innerHTML = `<div style="--foo:red;color:var(--foo);" />`
- // const app = createSSRApp({
- // setup() {
- // useCssVars(() => ({
- // foo: 'red',
- // }))
- // return () => h('div', { style: { color: 'var(--foo)' } })
- // },
- // })
- // app.mount(container)
- // expect(`Hydration style mismatch`).not.toHaveBeenWarned()
- // })
- // // #10317 - test case from #10325
- // test('css vars should only be added to expected on component root dom', () => {
- // const container = document.createElement('div')
- // container.innerHTML = `<div style="--foo:red;"><div style="color:var(--foo);" /></div>`
- // const app = createSSRApp({
- // setup() {
- // useCssVars(() => ({
- // foo: 'red',
- // }))
- // return () =>
- // h('div', null, [h('div', { style: { color: 'var(--foo)' } })])
- // },
- // })
- // app.mount(container)
- // expect(`Hydration style mismatch`).not.toHaveBeenWarned()
- // })
- // // #11188
- // test('css vars support fallthrough', () => {
- // const container = document.createElement('div')
- // container.innerHTML = `<div style="padding: 4px;--foo:red;"></div>`
- // const app = createSSRApp({
- // setup() {
- // useCssVars(() => ({
- // foo: 'red',
- // }))
- // return () => h(Child)
- // },
- // })
- // const Child = {
- // setup() {
- // return () => h('div', { style: 'padding: 4px' })
- // },
- // }
- // app.mount(container)
- // expect(`Hydration style mismatch`).not.toHaveBeenWarned()
- // })
- // // #11189
- // test('should not warn for directives that mutate DOM in created', () => {
- // const container = document.createElement('div')
- // container.innerHTML = `<div class="test red"></div>`
- // const vColor: ObjectDirective = {
- // created(el, binding) {
- // el.classList.add(binding.value)
- // },
- // }
- // const app = createSSRApp({
- // setup() {
- // return () =>
- // withDirectives(h('div', { class: 'test' }), [[vColor, 'red']])
- // },
- // })
- // app.mount(container)
- // expect(`Hydration style mismatch`).not.toHaveBeenWarned()
- // })
- // test('escape css var name', () => {
- // const container = document.createElement('div')
- // container.innerHTML = `<div style="padding: 4px;--foo\\.bar:red;"></div>`
- // const app = createSSRApp({
- // setup() {
- // useCssVars(() => ({
- // 'foo.bar': 'red',
- // }))
- // return () => h(Child)
- // },
- // })
- // const Child = {
- // setup() {
- // return () => h('div', { style: 'padding: 4px' })
- // },
- // }
- // app.mount(container)
- // expect(`Hydration style mismatch`).not.toHaveBeenWarned()
- // })
- // })
- // describe('data-allow-mismatch', () => {
- // test('element text content', () => {
- // const { container } = mountWithHydration(
- // `<div data-allow-mismatch="text">foo</div>`,
- // () => h('div', 'bar'),
- // )
- // expect(container.innerHTML).toBe(
- // '<div data-allow-mismatch="text">bar</div>',
- // )
- // expect(`Hydration text content mismatch`).not.toHaveBeenWarned()
- // })
- // test('not enough children', () => {
- // const { container } = mountWithHydration(
- // `<div data-allow-mismatch="children"></div>`,
- // () => h('div', [h('span', 'foo'), h('span', 'bar')]),
- // )
- // expect(container.innerHTML).toBe(
- // '<div data-allow-mismatch="children"><span>foo</span><span>bar</span></div>',
- // )
- // expect(`Hydration children mismatch`).not.toHaveBeenWarned()
- // })
- // test('too many children', () => {
- // const { container } = mountWithHydration(
- // `<div data-allow-mismatch="children"><span>foo</span><span>bar</span></div>`,
- // () => h('div', [h('span', 'foo')]),
- // )
- // expect(container.innerHTML).toBe(
- // '<div data-allow-mismatch="children"><span>foo</span></div>',
- // )
- // expect(`Hydration children mismatch`).not.toHaveBeenWarned()
- // })
- // test('complete mismatch', () => {
- // const { container } = mountWithHydration(
- // `<div data-allow-mismatch="children"><span>foo</span><span>bar</span></div>`,
- // () => h('div', [h('div', 'foo'), h('p', 'bar')]),
- // )
- // expect(container.innerHTML).toBe(
- // '<div data-allow-mismatch="children"><div>foo</div><p>bar</p></div>',
- // )
- // expect(`Hydration node mismatch`).not.toHaveBeenWarned()
- // })
- // test('fragment mismatch removal', () => {
- // const { container } = mountWithHydration(
- // `<div data-allow-mismatch="children"><!--[--><div>foo</div><div>bar</div><!--]--></div>`,
- // () => h('div', [h('span', 'replaced')]),
- // )
- // expect(container.innerHTML).toBe(
- // '<div data-allow-mismatch="children"><span>replaced</span></div>',
- // )
- // expect(`Hydration node mismatch`).not.toHaveBeenWarned()
- // })
- // test('fragment not enough children', () => {
- // const { container } = mountWithHydration(
- // `<div data-allow-mismatch="children"><!--[--><div>foo</div><!--]--><div>baz</div></div>`,
- // () => h('div', [[h('div', 'foo'), h('div', 'bar')], h('div', 'baz')]),
- // )
- // expect(container.innerHTML).toBe(
- // '<div data-allow-mismatch="children"><!--[--><div>foo</div><div>bar</div><!--]--><div>baz</div></div>',
- // )
- // expect(`Hydration node mismatch`).not.toHaveBeenWarned()
- // })
- // test('fragment too many children', () => {
- // const { container } = mountWithHydration(
- // `<div data-allow-mismatch="children"><!--[--><div>foo</div><div>bar</div><!--]--><div>baz</div></div>`,
- // () => h('div', [[h('div', 'foo')], h('div', 'baz')]),
- // )
- // expect(container.innerHTML).toBe(
- // '<div data-allow-mismatch="children"><!--[--><div>foo</div><!--]--><div>baz</div></div>',
- // )
- // // fragment ends early and attempts to hydrate the extra <div>bar</div>
- // // as 2nd fragment child.
- // expect(`Hydration text content mismatch`).not.toHaveBeenWarned()
- // // excessive children removal
- // expect(`Hydration children mismatch`).not.toHaveBeenWarned()
- // })
- // test('comment mismatch (element)', () => {
- // const { container } = mountWithHydration(
- // `<div data-allow-mismatch="children"><span></span></div>`,
- // () => h('div', [createCommentVNode('hi')]),
- // )
- // expect(container.innerHTML).toBe(
- // '<div data-allow-mismatch="children"><!--hi--></div>',
- // )
- // expect(`Hydration node mismatch`).not.toHaveBeenWarned()
- // })
- // test('comment mismatch (text)', () => {
- // const { container } = mountWithHydration(
- // `<div data-allow-mismatch="children">foobar</div>`,
- // () => h('div', [createCommentVNode('hi')]),
- // )
- // expect(container.innerHTML).toBe(
- // '<div data-allow-mismatch="children"><!--hi--></div>',
- // )
- // expect(`Hydration node mismatch`).not.toHaveBeenWarned()
- // })
- // test('class mismatch', () => {
- // mountWithHydration(
- // `<div class="foo bar" data-allow-mismatch="class"></div>`,
- // () => h('div', { class: 'foo' }),
- // )
- // expect(`Hydration class mismatch`).not.toHaveBeenWarned()
- // })
- // test('style mismatch', () => {
- // mountWithHydration(
- // `<div style="color:red;" data-allow-mismatch="style"></div>`,
- // () => h('div', { style: { color: 'green' } }),
- // )
- // expect(`Hydration style mismatch`).not.toHaveBeenWarned()
- // })
- // test('attr mismatch', () => {
- // mountWithHydration(`<div data-allow-mismatch="attribute"></div>`, () =>
- // h('div', { id: 'foo' }),
- // )
- // mountWithHydration(
- // `<div id="bar" data-allow-mismatch="attribute"></div>`,
- // () => h('div', { id: 'foo' }),
- // )
- // expect(`Hydration attribute mismatch`).not.toHaveBeenWarned()
- // })
- // })
- test.todo('Teleport')
- test.todo('Suspense')
- })
- describe('VDOM hydration interop', () => {
- test('basic vapor component', async () => {
- const data = ref(true)
- const { container } = await testHydrationInterop(
- `<script setup>const data = _data; const components = _components;</script>
- <template>
- <components.VaporChild/>
- </template>`,
- {
- VaporChild: {
- code: `<template>{{ data }}</template>`,
- vapor: true,
- },
- },
- data,
- )
- expect(container.innerHTML).toMatchInlineSnapshot(`"true"`)
- data.value = false
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(`"false"`)
- })
- test('nested components (VDOM -> Vapor -> VDOM)', async () => {
- const data = ref(true)
- const { container } = await testHydrationInterop(
- `<script setup>const data = _data; const components = _components;</script>
- <template>
- <components.VaporChild/>
- </template>`,
- {
- VaporChild: {
- code: `<template><components.VdomChild/></template>`,
- vapor: true,
- },
- VdomChild: {
- code: `<script setup>const data = _data;</script>
- <template>{{ data }}</template>`,
- vapor: false,
- },
- },
- data,
- )
- expect(container.innerHTML).toMatchInlineSnapshot(`"true"`)
- data.value = false
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(`"false"`)
- })
- test('nested components (VDOM -> Vapor -> VDOM (with slot fallback))', async () => {
- const data = ref(true)
- const { container } = await testHydrationInterop(
- `<script setup>const data = _data; const components = _components;</script>
- <template>
- <components.VaporChild/>
- </template>`,
- {
- VaporChild: {
- code: `<template><components.VdomChild/></template>`,
- vapor: true,
- },
- VdomChild: {
- code: `<script setup>const data = _data;</script>
- <template><slot><span>{{data}}</span></slot></template>`,
- vapor: false,
- },
- },
- data,
- )
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<!--[--><span>true</span><!--]--><!--slot-->"`,
- )
- data.value = false
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<!--[--><span>false</span><!--]--><!--slot-->"`,
- )
- })
- test('nested components (VDOM -> Vapor(with slot fallback) -> VDOM)', async () => {
- const data = ref(true)
- const { container } = await testHydrationInterop(
- `<script setup>const data = _data; const components = _components;</script>
- <template>
- <components.VaporChild/>
- </template>`,
- {
- VaporChild: {
- code: `<template>
- <components.VdomChild>
- <template #default>
- <span>{{data}} vapor fallback</span>
- </template>
- </components.VdomChild>
- </template>`,
- vapor: true,
- },
- VdomChild: {
- code: `<script setup>const data = _data;</script>
- <template><slot><span>vdom fallback</span></slot></template>`,
- vapor: false,
- },
- },
- data,
- )
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<!--[--><span>true vapor fallback</span><!--]--><!--slot-->"`,
- )
- data.value = false
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<!--[--><span>false vapor fallback</span><!--]--><!--slot-->"`,
- )
- })
- test('vapor slot render vdom component', async () => {
- const data = ref(true)
- const { container } = await testHydrationInterop(
- `<script setup>const data = _data; const components = _components;</script>
- <template>
- <components.VaporChild>
- <components.VdomChild/>
- </components.VaporChild>
- </template>`,
- {
- VaporChild: {
- code: `<template><div><slot/></div></template>`,
- vapor: true,
- },
- VdomChild: {
- code: `<script setup>const data = _data;</script>
- <template>{{ data }}</template>`,
- vapor: false,
- },
- },
- data,
- )
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div><!--[-->true<!--]--><!--slot--></div>"`,
- )
- data.value = false
- await nextTick()
- expect(container.innerHTML).toMatchInlineSnapshot(
- `"<div><!--[-->false<!--]--><!--slot--></div>"`,
- )
- })
- })
|