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

makeId should prepend an alphabetical character for HTML4 #635

Closed
pugnascotia opened this issue Apr 6, 2018 · 3 comments
Closed

makeId should prepend an alphabetical character for HTML4 #635

pugnascotia opened this issue Apr 6, 2018 · 3 comments
Labels

Comments

@pugnascotia
Copy link
Contributor

The makeId utility generates a random DOM identifier, which is a mixture of alphanumeric characters. Sometimes this results in an identifier that starts with a number, which is not valid in HTML4 (but is in HTML5). This caused a problem in Cloud when integrating with Recurly, since the latter's code would choke on IDs that started with numbers. We were able to work around this by setting explicit IDs, however it would be nice to avoid this issue more widely by preventing it in makeId.

See: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id

@pugnascotia pugnascotia added the bug label Apr 6, 2018
@pugnascotia
Copy link
Contributor Author

We could do something like:

export default function makeId() {
  const id = Math.random().toString(36).slice(-8);
  return /^\d/.test(id) ? 'x' + id : id;
}

It feels a bit icky though. I'd be interested to hear @cjcenizal's thoughts.

@timroes
Copy link
Contributor

timroes commented Apr 6, 2018

@pugnascotia I was actually aware of that issue when creating the service in the very first place. I just didn't expect that we have any UIs running, that can't be HTML5 compliant :D But I think we can just prefix every id with a letter i and we should be fine. Will setup a PR for that.

@chandlerprall
Copy link
Contributor

makeId has been deprecated in favour of htmlIdGenerator.

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

No branches or pull requests

4 participants