@@ -2653,7 +2653,7 @@ function validateProp(key, propOptions, propsData, vm) {
2653
2653
var absent = ! hasOwn ( propsData , key ) ;
2654
2654
var value = propsData [ key ] ;
2655
2655
// handle boolean props
2656
- if ( prop . type === Boolean ) {
2656
+ if ( getType ( prop . type ) === ' Boolean' ) {
2657
2657
if ( absent && ! hasOwn ( prop , 'default' ) ) {
2658
2658
value = false ;
2659
2659
} else if ( value === '' || value === hyphenate ( key ) ) {
@@ -2734,27 +2734,20 @@ function assertProp(prop, name, value, vm, absent) {
2734
2734
*/
2735
2735
function assertType ( value , type ) {
2736
2736
var valid = void 0 ;
2737
- var expectedType = void 0 ;
2738
- if ( type === String ) {
2739
- expectedType = 'string' ;
2740
- valid = typeof value === expectedType ;
2741
- } else if ( type === Number ) {
2742
- expectedType = 'number' ;
2743
- valid = typeof value === expectedType ;
2744
- } else if ( type === Boolean ) {
2745
- expectedType = 'boolean' ;
2746
- valid = typeof value === expectedType ;
2747
- } else if ( type === Function ) {
2748
- expectedType = 'function' ;
2749
- valid = typeof value === expectedType ;
2750
- } else if ( type === Object ) {
2751
- expectedType = 'Object' ;
2737
+ var expectedType = getType ( type ) ;
2738
+ if ( expectedType === 'String' ) {
2739
+ valid = typeof value === ( expectedType = 'string' ) ;
2740
+ } else if ( expectedType === 'Number' ) {
2741
+ valid = typeof value === ( expectedType = 'number' ) ;
2742
+ } else if ( expectedType === 'Boolean' ) {
2743
+ valid = typeof value === ( expectedType = 'boolean' ) ;
2744
+ } else if ( expectedType === 'Function' ) {
2745
+ valid = typeof value === ( expectedType = 'function' ) ;
2746
+ } else if ( expectedType === 'Object' ) {
2752
2747
valid = isPlainObject ( value ) ;
2753
- } else if ( type === Array ) {
2754
- expectedType = 'Array' ;
2748
+ } else if ( expectedType === 'Array' ) {
2755
2749
valid = Array . isArray ( value ) ;
2756
2750
} else {
2757
- expectedType = type . name || type . toString ( ) ;
2758
2751
valid = value instanceof type ;
2759
2752
}
2760
2753
return {
@@ -2763,6 +2756,16 @@ function assertType(value, type) {
2763
2756
} ;
2764
2757
}
2765
2758
2759
+ /**
2760
+ * Use function string name to check built-in types,
2761
+ * because a simple equality check will fail when running
2762
+ * across different vms / iframes.
2763
+ */
2764
+ function getType ( fn ) {
2765
+ var match = fn && fn . toString ( ) . match ( / ^ \s * f u n c t i o n ( \w + ) / ) ;
2766
+ return match && match [ 1 ] ;
2767
+ }
2768
+
2766
2769
// attributes that should be using props for binding
2767
2770
var mustUseProp = makeMap ( 'value,selected,checked,muted' ) ;
2768
2771
@@ -4484,6 +4487,14 @@ function makeFunction(code) {
4484
4487
}
4485
4488
}
4486
4489
4490
+ var warned = Object . create ( null ) ;
4491
+ var warnOnce = function warnOnce ( msg ) {
4492
+ if ( ! warned [ msg ] ) {
4493
+ warned [ msg ] = true ;
4494
+ console . warn ( '\n\u001b[31m' + msg + '\u001b[39m\n' ) ;
4495
+ }
4496
+ } ;
4497
+
4487
4498
var normalizeAsync = function normalizeAsync ( cache , method ) {
4488
4499
var fn = cache [ method ] ;
4489
4500
if ( ! fn ) {
@@ -4531,9 +4542,10 @@ function createRenderFunction(modules, directives, isUnaryTag, cache) {
4531
4542
// check cache hit
4532
4543
var Ctor = node . componentOptions . Ctor ;
4533
4544
var getKey = Ctor . options . serverCacheKey ;
4534
- if ( getKey && cache ) {
4545
+ var name = Ctor . options . name ;
4546
+ if ( getKey && cache && name ) {
4535
4547
( function ( ) {
4536
- var key = Ctor . cid + '::' + getKey ( node . componentOptions . propsData ) ;
4548
+ var key = name + '::' + getKey ( node . componentOptions . propsData ) ;
4537
4549
if ( has ) {
4538
4550
has ( key , function ( hit ) {
4539
4551
if ( hit ) {
@@ -4555,8 +4567,11 @@ function createRenderFunction(modules, directives, isUnaryTag, cache) {
4555
4567
}
4556
4568
} ) ( ) ;
4557
4569
} else {
4558
- if ( getKey ) {
4559
- console . error ( '[vue-server-renderer] Component ' + ( Ctor . options . name || '(anonymous)' ) + ' implemented serverCacheKey, ' + 'but no cache was provided to the renderer.' ) ;
4570
+ if ( getKey && ! cache ) {
4571
+ warnOnce ( '[vue-server-renderer] Component ' + ( Ctor . options . name || '(anonymous)' ) + ' implemented serverCacheKey, ' + 'but no cache was provided to the renderer.' ) ;
4572
+ }
4573
+ if ( getKey && ! name ) {
4574
+ warnOnce ( '[vue-server-renderer] Components that implement "serverCacheKey" ' + 'must also define a unique "name" option.' ) ;
4560
4575
}
4561
4576
renderComponent ( node , write , next , isRoot ) ;
4562
4577
}
@@ -4678,6 +4693,7 @@ function createRenderFunction(modules, directives, isUnaryTag, cache) {
4678
4693
}
4679
4694
4680
4695
return function render ( component , write , done ) {
4696
+ warned = Object . create ( null ) ;
4681
4697
activeInstance = component ;
4682
4698
normalizeRender ( component ) ;
4683
4699
renderNode ( component . _render ( ) , write , done , true ) ;
0 commit comments