Browse Source

fix(ssr): fix cachedEscape memory issue

close #6332
Evan You 8 years ago
parent
commit
02f8b80676

+ 2 - 2
src/platforms/web/server/modules/attrs.js

@@ -1,6 +1,6 @@
 /* @flow */
 
-import { cachedEscape } from '../util'
+import { escape } from '../util'
 
 import {
   isDef,
@@ -50,7 +50,7 @@ export function renderAttr (key: string, value: string): string {
   } else if (isEnumeratedAttr(key)) {
     return ` ${key}="${isFalsyAttrValue(value) || value === 'false' ? 'false' : 'true'}"`
   } else if (!isFalsyAttrValue(value)) {
-    return ` ${key}="${cachedEscape(String(value))}"`
+    return ` ${key}="${escape(String(value))}"`
   }
   return ''
 }

+ 2 - 2
src/platforms/web/server/modules/class.js

@@ -1,11 +1,11 @@
 /* @flow */
 
-import { cachedEscape } from '../util'
+import { escape } from '../util'
 import { genClassForVnode } from 'web/util/index'
 
 export default function renderClass (node: VNodeWithData): ?string {
   const classList = genClassForVnode(node)
   if (classList !== '') {
-    return ` class="${cachedEscape(classList)}"`
+    return ` class="${escape(classList)}"`
   }
 }

+ 2 - 2
src/platforms/web/server/modules/style.js

@@ -1,6 +1,6 @@
 /* @flow */
 
-import { cachedEscape } from '../util'
+import { escape } from '../util'
 import { hyphenate } from 'shared/util'
 import { getStyle } from 'web/util/style'
 
@@ -23,6 +23,6 @@ export function genStyle (style: Object): string {
 export default function renderStyle (vnode: VNodeWithData): ?string {
   const styleText = genStyle(getStyle(vnode, false))
   if (styleText !== '') {
-    return ` style=${JSON.stringify(cachedEscape(styleText))}`
+    return ` style=${JSON.stringify(escape(styleText))}`
   }
 }

+ 1 - 3
src/platforms/web/server/util.js

@@ -1,6 +1,6 @@
 /* @flow */
 
-import { makeMap, cached } from 'shared/util'
+import { makeMap } from 'shared/util'
 
 const isAttr = makeMap(
   'accept,accept-charset,accesskey,action,align,alt,async,autocomplete,' +
@@ -46,8 +46,6 @@ export function escape (s: string) {
   return s.replace(/[<>"&]/g, escapeChar)
 }
 
-export const cachedEscape = cached(escape)
-
 function escapeChar (a) {
   return ESC[a] || a
 }

+ 3 - 3
src/server/optimizing-compiler/runtime-helpers.js

@@ -1,6 +1,6 @@
 /* @flow */
 
-import { escape, cachedEscape } from 'web/server/util'
+import { escape } from 'web/server/util'
 import { isObject, extend } from 'shared/util'
 import { renderAttr } from 'web/server/modules/attrs'
 import { renderClass } from 'web/util/class'
@@ -123,7 +123,7 @@ function renderSSRClass (
   dynamic: any
 ): string {
   const res = renderClass(staticClass, dynamic)
-  return res === '' ? res : ` class="${cachedEscape(res)}"`
+  return res === '' ? res : ` class="${escape(res)}"`
 }
 
 function renderSSRStyle (
@@ -136,5 +136,5 @@ function renderSSRStyle (
   if (dynamic) extend(style, normalizeStyleBinding(dynamic))
   if (extra) extend(style, extra)
   const res = genStyle(style)
-  return res === '' ? res : ` style=${JSON.stringify(cachedEscape(res))}`
+  return res === '' ? res : ` style=${JSON.stringify(escape(res))}`
 }