]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf(ssr): improve isComment check (#6078)
authorHitesh Khandelwal <hkk12369@gmail.com>
Mon, 13 Jun 2022 03:06:15 +0000 (08:36 +0530)
committerGitHub <noreply@github.com>
Mon, 13 Jun 2022 03:06:15 +0000 (23:06 -0400)
packages/server-renderer/src/helpers/ssrRenderSlot.ts

index fbe7266b2a1050d6f9654ac960eab7905cad6b6f..ea1e7e941064e432cac5dde977b6750bfb7468a3 100644 (file)
@@ -87,11 +87,11 @@ export function ssrRenderSlotInner(
   }
 }
 
+const commentTestRE = /^<!--.*-->$/s
 const commentRE = /<!--[^]*?-->/gm
 function isComment(item: SSRBufferItem) {
-  return (
-    typeof item === 'string' &&
-    commentRE.test(item) &&
-    !item.replace(commentRE, '').trim()
-  )
+  if (typeof item !== 'string' || !commentTestRE.test(item)) return false
+  // if item is '<!---->' or '<!--[-->' or '<!--]-->', return true directly
+  if (item.length <= 8) return true
+  return !item.replace(commentRE, '').trim()
 }