function replacePrototypesWithProxies(instance) {
  let previous = instance;
  let proto = Object.getPrototypeOf(instance);

  while (proto && proto.constructor !== HTMLElement) {
    const key = keysForClasses.get(proto.constructor);
    if (key) {
      // this is a prototype that might be hot-replaced later
      const getCurrentProto = () => proxiesForKeys.get(key).currentClass.prototype;
      Object.setPrototypeOf(previous, createProxy(proto, getCurrentProto));
    }

    previous = proto;
    proto = Object.getPrototypeOf(proto);
  }
}
Replaces all prototypes in the inheritance chain with a proxy
that references the latest implementation