Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous class : provide a unique identifier #208

Closed
LaCocoRoco opened this issue Nov 25, 2022 · 5 comments · Fixed by #211
Closed

Ambiguous class : provide a unique identifier #208

LaCocoRoco opened this issue Nov 25, 2022 · 5 comments · Fixed by #211

Comments

@LaCocoRoco
Copy link

Issues Reference: #105 #106 #107 #116 #118
Code Reference: superjson/blob/main/src/registry

This warning only happens in none production environment.
In my use case by using next-superjson-plugin package with a custom class register in nextjs app.ts.
Can someone explain why this warning exits or better how i can fix it in development?
If i'm not wrong this happens because the registerClass gets executed more then once?
I could not find any flag or possibility to suppress this warning.

@Skn0tt
Copy link
Member

Skn0tt commented Nov 28, 2022

Hi @LaCocoRoco! Yes, this warning happens because registerClass is executed more than once for a class of the same name. It's meant to uncover potential bugs in your module loading, and there's no way of supressing them.
Could you elaborate on when exactly you're seeing the warning? Is it during Hot Module Replacement? Reproduction steps / a repro repo would be greatly appreciated.

@LaCocoRoco
Copy link
Author

LaCocoRoco commented Nov 30, 2022

Hi @Skn0tt, here is a sandbox to reproduce the problem.

  1. Start project in dev mode
  2. Open the preview
  3. Change the value in pages/index.tsx
  4. Error Ambiguous class should be printed in the console

Probably fast refresh from the nextjs framework is the origin of this issue,
because on every change the page gets reloaded.
I think it is neglectable, but perhaps there is a way to fix it.

@Skn0tt
Copy link
Member

Skn0tt commented Nov 30, 2022

I'm seeing it, thank you! Yeah, that looks like it's occuring during Hot Module Replacement (HMR). That means there already was a class called Foo, and now the Next.js Dev Server dynamically loads in the updated module, which has a new version of the class Foo, which triggers the warning.

The warning was originally supposed to warn about existing classes being overwritten, e.g. when something in the build process fails and e.g. some client stub is placed in the server bundle. It's not supposed to trigger during HMR, but apparently it does, and I don't see a good way of excluding HMR here 🤔 Maybe we should disable the warning altogether. What do you think?

@LaCocoRoco
Copy link
Author

Depends if there are any significant negative effects which could happen if you run in a real ambiguous class situation. But if it is a simple information for "you unnecessary load the class more then once" in my personally opinion you probably could disable it.

@Skn0tt
Copy link
Member

Skn0tt commented Dec 6, 2022

Removed the warning in https://github.com/blitz-js/superjson/releases/tag/v1.12.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants