fix(runtime-dom): should patch svg innerHtml (#956)
This commit is contained in:
		
							parent
							
								
									33ccfc0a8b
								
							
						
					
					
						commit
						27b5c71944
					
				| @ -45,6 +45,22 @@ describe('runtime-dom: props patching', () => { | |||||||
|     expect(fn).toHaveBeenCalled() |     expect(fn).toHaveBeenCalled() | ||||||
|   }) |   }) | ||||||
| 
 | 
 | ||||||
|  |   // #954
 | ||||||
|  |   test('(svg) innerHTML unmount prev children', () => { | ||||||
|  |     const fn = jest.fn() | ||||||
|  |     const comp = { | ||||||
|  |       render: () => 'foo', | ||||||
|  |       unmounted: fn | ||||||
|  |     } | ||||||
|  |     const root = document.createElement('div') | ||||||
|  |     render(h('div', null, [h(comp)]), root) | ||||||
|  |     expect(root.innerHTML).toBe(`<div>foo</div>`) | ||||||
|  | 
 | ||||||
|  |     render(h('svg', { innerHTML: '<g></g>' }), root) | ||||||
|  |     expect(root.innerHTML).toBe(`<svg><g></g></svg>`) | ||||||
|  |     expect(fn).toHaveBeenCalled() | ||||||
|  |   }) | ||||||
|  | 
 | ||||||
|   test('textContent unmount prev children', () => { |   test('textContent unmount prev children', () => { | ||||||
|     const fn = jest.fn() |     const fn = jest.fn() | ||||||
|     const comp = { |     const comp = { | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ import { patchStyle } from './modules/style' | |||||||
| import { patchAttr } from './modules/attrs' | import { patchAttr } from './modules/attrs' | ||||||
| import { patchDOMProp } from './modules/props' | import { patchDOMProp } from './modules/props' | ||||||
| import { patchEvent } from './modules/events' | import { patchEvent } from './modules/events' | ||||||
| import { isOn, isString } from '@vue/shared' | import { isOn, isString, isFunction } from '@vue/shared' | ||||||
| import { RendererOptions } from '@vue/runtime-core' | import { RendererOptions } from '@vue/runtime-core' | ||||||
| 
 | 
 | ||||||
| const nativeOnRE = /^on[a-z]/ | const nativeOnRE = /^on[a-z]/ | ||||||
| @ -34,10 +34,16 @@ export const patchProp: RendererOptions<Node, Element>['patchProp'] = ( | |||||||
|           patchEvent(el, key, prevValue, nextValue, parentComponent) |           patchEvent(el, key, prevValue, nextValue, parentComponent) | ||||||
|         } |         } | ||||||
|       } else if ( |       } else if ( | ||||||
|         !isSVG && |         isSVG | ||||||
|         key in el && |           ? // most keys must be set as attribute on svg elements to work
 | ||||||
|         // onclick="foo" needs to be set as an attribute to work
 |             // ...except innerHTML
 | ||||||
|         !(nativeOnRE.test(key) && isString(nextValue)) |             key === 'innerHTML' || | ||||||
|  |             // or native onclick with function values
 | ||||||
|  |             (key in el && nativeOnRE.test(key) && isFunction(nextValue)) | ||||||
|  |           : // for normal html elements, set as a property if it exists
 | ||||||
|  |             key in el && | ||||||
|  |             // except native onclick with string values
 | ||||||
|  |             !(nativeOnRE.test(key) && isString(nextValue)) | ||||||
|       ) { |       ) { | ||||||
|         patchDOMProp( |         patchDOMProp( | ||||||
|           el, |           el, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user