function register(importMeta, name, clazz) {
  const key = `${new URL(importMeta.url).pathname}:${name}`;
  const existing = proxiesForKeys.get(key);
  if (!existing) {
    // this class was not yet registered,

    // create a proxy that will forward to the latest implementation
    const proxy = createProxy(clazz, () => proxiesForKeys.get(key).currentClass);
    // inject a HMR class into the inheritance chain
    injectInheritsHmrClass(clazz);
    // keep track of all connected elements for this class
    const connectedElements = trackConnectedElements(clazz);

    proxiesForKeys.set(key, {
      originalProxy: proxy,
      currentProxy: proxy,
      originalClass: clazz,
      currentClass: clazz,
      connectedElements,
    });
    keysForClasses.set(clazz, key);
    return proxy;
  }
  // class was already registered before

  // register new class, all calls will be proxied to this class
  const previousProxy = existing.currentProxy;
  const currentProxy = createProxy(clazz, () => proxiesForKeys.get(key).currentClass);
  existing.currentClass = clazz;
  existing.currentProxy = currentProxy;

  Promise.resolve().then(() => {
    // call optional HMR on the class if they exist, after next microtask to ensure
    // module bodies have executed fully
    if (clazz.hotReplacedCallback) {
      try {
        clazz.hotReplacedCallback();
      } catch (error) {
        console.error(error);
      }
    }

    for (const element of existing.connectedElements) {
      if (element.constructor === previousProxy) {
        // we need to update the constructor of the element to match to newly created proxy
        // but we should only do this for elements that was directly created with this class
        // and not for elements that extend this
        element.constructor = currentProxy;
      }

      if (element.hotReplacedCallback) {
        try {
          element.hotReplacedCallback();
        } catch (error) {
          console.error(error);
        }
      }
    }
  });

  // the original proxy already forwards to the new class but we're return a new proxy
  // because access to `prototype` must return the original value and we need to be able to
  // manipulate the prototype on the new class
  return currentProxy;
}
Registers a web component class. Triggers a hot replacement if the
class was already registered before.