top | item 47137075

(no title)

voxic11 | 5 days ago

The idea is you wouldn't mix innerHTML and setHTML, you would eliminate all usage of innerHTML and use the new setHTMLUnsafe if you needed the old functionality.

discuss

order

extraduder_ire|5 days ago

I looked up setHTMLUnsafe on MDN, and it looks like its been in every notable browser since last year.

Good idea to ship that one first, when it's easier to implement and is going to be the unsafe fallback going forward.

croes|5 days ago

If I need the old functionality why not stick to innerHTML?

orf|5 days ago

because the "unsafe" suffix conveys information to the reader, whereas `innherHTML` does not?

tbrownaw|5 days ago

Because then your linter won't be able to tell you when you're done migrating the calls that can be migrated.

philipwhiuk|5 days ago

Because sooner or later it'll be removed.

reddalo|5 days ago

You can't rename an existing method. It would break compatibility with existing websites.

post-it|5 days ago

> you would eliminate all usage of innerHTML

The mythical refactor where all deprecated code is replaced with modern code. I'm not sure it has ever happened.

I don't have an alternative of course, adding new methods while keeping the old ones is the only way to edit an append-only standard like the web.

thenewnewguy|5 days ago

If you want to adopt this in your project, you can add a linter that explicitly bans innerHTML (and then go fix the issues it finds). Obviously Mozilla cannot magically fix the code of every website on the web but the tools exist for _your_ website.

Vinnl|5 days ago

I kinda like the way JS evolved into a modern language, where essentially ~everyone uses a linter that e.g. prevents the use of `var`. Sure, it's technically still in the language, but it's almost never used anymore.

(Assuming transpilers have stopped outputting it, which I'm not confident about.)

bulbar|5 days ago

It for sure happens for drop in replacements.

littlestymaar|5 days ago

Nobody's talking about old code here.

Having an alternative to innerHTML means you can ban it from new code through linting.

noduerme|5 days ago

Finally, a good use case for AI.