const REHYDRATED = '__REHYDRATED__' ; let patched = false ; let oldAppendChild = null ; let oldInsertBefore = null ; function patchedAppendChild < T extends Node > ( child ) { if ( child [ REHYDRATED ] ) { return child ; } return oldAppendChild . call ( this , child ) ; } ; function patchedInsertBefore < T extends Node > ( child , reference ) { if ( child [ REHYDRATED ] ) { return child ; } return oldInsertBefore . call ( this , child , reference ) ; } ; /**
 * Patch appendChild and insertBefore to ignore rehydrated nodes.
 */ export function patchAppendChildAndInsertBefore ( ) { if ( patched ) { return ; } oldAppendChild = Element . prototype . appendChild ; Element . prototype . appendChild = patchedAppendChild ; oldInsertBefore = Node . prototype . insertBefore ; Node . prototype . insertBefore = patchedInsertBefore ; patched = true ; } /**
 * Unpatch appendChild and insertBefore
 */ export function unpatchAppendChildAndInsertBefore ( ) { if ( ! patched ) { return ; } Element . prototype . appendChild = oldAppendChild ; oldAppendChild = null ; oldInsertBefore = null ; patched = false ; }