idiomorph icon indicating copy to clipboard operation
idiomorph copied to clipboard

Log warning in console if duplicate ids are detected

Open botandrose opened this issue 2 months ago • 0 comments

Background

Idiomorph relies on ids being unique within the morphed document for two main reasons:

  1. It knows how to match up the old and new content
  2. It ensure elements with hidden state are reused, and thus retain their hidden state.

Problem

It's not easy to know when your html documents have duplicate ids, and resultant failures in the morph may be subtle or non-obvious in cause. It would likely take a deep dive into Idiomorph's algorithm with a debugger to identify that the problem is duplicate ids.

Proposition

Idiomorph already knows on startup when you have duplicate ids, so this PR simply prints a warning to the console with a list of them, leaving it up to the user to decide to either address or ignore. I've tried to make the message generic, so that vicarious users of Idiomorph (e.g. Turbo) who may have never heard it can still understand what the problem is, and what to do.

Questions

  1. Do we want to add some kind of option for users to disable this warning?
  2. Can we improve the warning message? Maybe link to a document explaining the issue in more detail?
  3. Any reason not to do this?

Closes #141

botandrose avatar Oct 17 '25 15:10 botandrose