File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -65,10 +65,14 @@ export function observable (obj) {
65
65
)
66
66
}
67
67
68
+ function isDomNode ( obj ) {
69
+ return typeof Node === 'function' && obj instanceof Node
70
+ }
71
+
68
72
function instrumentObservable ( obj ) {
69
73
const instrument = instrumentations . get ( Object . getPrototypeOf ( obj ) )
70
74
// these objects break, when they are wrapped with proxies
71
- if ( instrument === false ) {
75
+ if ( instrument === false || isDomNode ( obj ) ) {
72
76
return obj
73
77
}
74
78
// these objects can be wrapped by Proxies, but require special instrumentation beforehand
Original file line number Diff line number Diff line change @@ -328,4 +328,16 @@ describe('observe', () => {
328
328
await nextTick ( )
329
329
expect ( dummy ) . to . equal ( 'p2p1p3' )
330
330
} )
331
+
332
+ it ( 'should not error when a DOM element is added' , async ( ) => {
333
+ let dummy = null
334
+ const observed = observable ( { obj : null } )
335
+ observe ( ( ) => ( dummy = observed . obj && observed . obj . nodeType ) )
336
+
337
+ await nextTick ( )
338
+ expect ( dummy ) . to . equal ( null )
339
+ observed . obj = document
340
+ await nextTick ( )
341
+ expect ( dummy ) . to . equal ( 9 )
342
+ } )
331
343
} )
You can’t perform that action at this time.
0 commit comments