mirror of https://github.com/vuejs/vue.git
				
				
				
			* don't throw error when node gets relocated * perf: Simplify if check in vdom/patch
This commit is contained in:
		
							parent
							
								
									9311876c7c
								
							
						
					
					
						commit
						255b627f39
					
				|  | @ -234,7 +234,9 @@ export function createPatchFunction (backend) { | ||||||
|   function insert (parent, elm, ref) { |   function insert (parent, elm, ref) { | ||||||
|     if (isDef(parent)) { |     if (isDef(parent)) { | ||||||
|       if (isDef(ref)) { |       if (isDef(ref)) { | ||||||
|  |         if (ref.parentNode === parent) { | ||||||
|           nodeOps.insertBefore(parent, elm, ref) |           nodeOps.insertBefore(parent, elm, ref) | ||||||
|  |         } | ||||||
|       } else { |       } else { | ||||||
|         nodeOps.appendChild(parent, elm) |         nodeOps.appendChild(parent, elm) | ||||||
|       } |       } | ||||||
|  |  | ||||||
|  | @ -366,4 +366,46 @@ describe('Component', () => { | ||||||
|       Vue.config.errorHandler = null |       Vue.config.errorHandler = null | ||||||
|     }).then(done) |     }).then(done) | ||||||
|   }) |   }) | ||||||
|  | 
 | ||||||
|  |   it('relocates node without error', done => { | ||||||
|  |     const el = document.createElement('div') | ||||||
|  |     document.body.appendChild(el) | ||||||
|  |     const target = document.createElement('div') | ||||||
|  |     document.body.appendChild(target) | ||||||
|  | 
 | ||||||
|  |     const Test = { | ||||||
|  |       render (h) { | ||||||
|  |         return h('div', { class: 'test' }, this.$slots.default) | ||||||
|  |       }, | ||||||
|  |       mounted () { | ||||||
|  |         target.appendChild(this.$el) | ||||||
|  |       }, | ||||||
|  |       beforeDestroy () { | ||||||
|  |         const parent = this.$el.parentNode | ||||||
|  |         if (parent) { | ||||||
|  |           parent.removeChild(this.$el) | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     const vm = new Vue({ | ||||||
|  |       data () { | ||||||
|  |         return { | ||||||
|  |           view: true | ||||||
|  |         } | ||||||
|  |       }, | ||||||
|  |       template: `<div><test v-if="view">Test</test></div>`, | ||||||
|  |       components: { | ||||||
|  |         test: Test | ||||||
|  |       } | ||||||
|  |     }).$mount(el) | ||||||
|  | 
 | ||||||
|  |     expect(el.outerHTML).toBe('<div></div>') | ||||||
|  |     expect(target.outerHTML).toBe('<div><div class="test">Test</div></div>') | ||||||
|  |     vm.view = false | ||||||
|  |     waitForUpdate(() => { | ||||||
|  |       expect(el.outerHTML).toBe('<div></div>') | ||||||
|  |       expect(target.outerHTML).toBe('<div></div>') | ||||||
|  |       vm.$destroy() | ||||||
|  |     }).then(done) | ||||||
|  |   }) | ||||||
| }) | }) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue