From 6dae253bc12b438d71b12bb78365991284f536fa Mon Sep 17 00:00:00 2001 From: eight Date: Mon, 21 Nov 2022 18:44:46 +0800 Subject: [PATCH] Fix: allow numbers in tag name (#261) --- .../__tests__/partialHydration.spec.ts | 12 ++++++++++++ src/partialHydration/partialHydration.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/partialHydration/__tests__/partialHydration.spec.ts b/src/partialHydration/__tests__/partialHydration.spec.ts index 7972e3dc..4cc6087a 100644 --- a/src/partialHydration/__tests__/partialHydration.spec.ts +++ b/src/partialHydration/__tests__/partialHydration.spec.ts @@ -13,6 +13,18 @@ describe('#partialHydration', () => { ); }); + it('allow numbers in the tag name', async () => { + expect( + ( + await partialHydration.markup({ + content: '', + }) + ).code, + ).toMatchInlineSnapshot( + `""`, + ); + }); + it('explicit lazy', async () => { expect( ( diff --git a/src/partialHydration/partialHydration.ts b/src/partialHydration/partialHydration.ts index 45c821fe..741498b1 100644 --- a/src/partialHydration/partialHydration.ts +++ b/src/partialHydration/partialHydration.ts @@ -18,7 +18,7 @@ const createReplacementString = ({ input, name, props }) => { export const preprocessSvelteContent = (content) => { // Note: this regex only supports self closing components. // Slots aren't supported for client hydration either. - const hydrateableComponentPattern = /<([a-zA-Z]+)[^>]+hydrate-client={([^]*?})}[^/>]*\/>/gim; + const hydrateableComponentPattern = /<([a-zA-Z\d]+)\b[^>]+\bhydrate-client={([^]*?})}[^/>]*\/>/gim; const matches = [...content.matchAll(hydrateableComponentPattern)]; const output = matches.reduce((out, match) => {