Repository: blitz-js/superjson (ts)

Issue:
Error "Ambiguous class, provide a unique identifier" with next.js 10.0.6
We are having an issue with next.js 10.0.6 in Blitz where we get the `"Ambiguous class, provide a unique identifier"` error even though [all classes have unique ids](https://github.com/blitz-js/blitz/blob/canary/packages/core/src/errors.ts). 

👉  https://github.com/blitz-js/blitz/pull/1828/checks?check_run_id=1795588783#step:9:104

**Possible fix:** 

Disable this check, https://github.com/blitz-js/superjson/blob/main/src/registry.ts#L17, if you are explicitly providing an identifier.

Pull request description:
Only check for ambiguous classes in development
Closes #106, #105 

Patch:
diff --git a/src/registry.ts b/src/registry.ts
index 07ea5af..4e867d2 100644
--- a/src/registry.ts
+++ b/src/registry.ts
@@ -14,8 +14,13 @@ export class Registry<T> {
       identifier = this.generateIdentifier(value);
     }
 
-    if (this.kv.getByKey(identifier)) {
-      throw new Error('Ambiguous class, provide a unique identifier.');
+    if (process.env.NODE_ENV !== 'production') {
+      const alreadyRegistered = this.kv.getByKey(identifier);
+      if (alreadyRegistered && alreadyRegistered !== value) {
+        console.warn(
+          `Ambiguous class "${identifier}", provide a unique identifier.`
+        );
+      }
     }
 
     this.kv.set(identifier, value);


Test patch:
diff --git a/src/registry.test.ts b/src/registry.test.ts
index 943a633..2124810 100644
--- a/src/registry.test.ts
+++ b/src/registry.test.ts
@@ -16,8 +16,11 @@ test('class registry', () => {
 
   expect(() => registry.register(Car)).not.toThrow();
 
-  expect(() => registry.register(class Car {})).toThrow(
-    'Ambiguous class, provide a unique identifier.'
+  const warnSpy = jest.spyOn(console, 'warn');
+
+  registry.register(class Car {});
+  expect(warnSpy).toHaveBeenCalledWith(
+    'Ambiguous class "Car", provide a unique identifier.'
   );
 
   registry.register(class Car {}, 'car2');