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

Tracking feasibility of unshipping assert contextual keyword in Chrome #135

Closed
syg opened this issue Mar 27, 2023 · 9 comments · Fixed by #161
Closed

Tracking feasibility of unshipping assert contextual keyword in Chrome #135

syg opened this issue Mar 27, 2023 · 9 comments · Fixed by #161

Comments

@syg
Copy link

syg commented Mar 27, 2023

Chrome has landed use counters tracking the use of the deprecated assert contextual keyword in import attributes.

This will go to stable in 114, which is scheduled for May 30, 2023. We will need some time after the counter reaches the stable population to gather numbers.

@nicolo-ribaudo nicolo-ribaudo pinned this issue May 3, 2023
@nicolo-ribaudo
Copy link
Member

Usage stats: https://chromestatus.com/metrics/feature/timeline/popularity/4528 (⚠️ as mentioned above, the number is so close to zero just because the counter is not in stable yet)

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented May 7, 2023

I was exploring Chrome use counters, and I found counters for JSON modules (https://chromestatus.com/metrics/feature/timeline/popularity/3804 - 0.012% of page loads) and CSS modules (https://chromestatus.com/metrics/feature/timeline/popularity/3805 - 0.000061% of page loads). I don't think it's unreasonable to expect the usage of import assertions to roughly match the usage of JSON modules.

I manually checked some of the sample URLs, and all the usages I found (using the assert[:{ ] regexp on their code) are from https://github.com/guybedford/es-module-shims/blob/main/src/features.js, which try/catches around evaluating CSS/JSON modules with import assertions to detect if they are supported and thus if they need to be polyfilled. Removing support for assert would cause the polyfill to kick in, and to restore such support in websites that rely on it.

@guybedford
Copy link

Note that es-module-shims does not by default engage the JSON / CSS modules feature detection path at all in polyfill mode, unless it is explicitly enabled via https://github.com/guybedford/es-module-shims#pollyfill-enable-option, which I'd expect would be a very small percentage of es-module-shims users.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jul 4, 2023

Going back to #135 (comment) again, it looks like many of the usages of CSS/JSON modules are from v0.13.1 of es-modules-shims, that performs feature-detection even if then they are not used.

@syg
Copy link
Author

syg commented Jul 5, 2023

There are now some URLs at the bottom of https://chromestatus.com/metrics/feature/timeline/popularity/4528 now, if you want to take a look again @nicolo-ribaudo.

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jul 7, 2023

Thank you!

Some preliminary analysis of the the first websites listed there (I only checked the homepage), searching with the assert[ /{] regex:

  • var.blog.jp — it uses CSS modules for syntax highlighting, I get no hightlighting on Firefox (it's a blog about JS)
  • www .eurokosher.it — uses es-modules-shim v0.13.1 which has feature detection, but does not actually use assertions
  • app.ulu.io/login — uses JSON modules with an assert static import to load localization data. They do something like this:
    <script type='module'>
    import locale from '/locale.json?locale=it' assert {type:'json'};
    window.I18n = locale;
    </script>
    <script>
    window.I18n = { /* ... hard-coded contents of locale.json?locale-it ... */ };
    </script>
    so that their localization also works in browsers without import assertions support. Actually, in browsers that do not have import assertions supports their website works the same but it avoids loading one additional 250k file 😛
  • classlocator.live — the search at the top does not work if the assert syntax is not supported
  • council.csie.ntu.edu.tw — the buttons to filter the people list do not work without assert support
  • gewofit.de — they use a static JSON import in their index.js file to load some data for a library, but I cannot find any behavior difference between Chrome and Firefox (which does not support assert)
  • labdash.net — they have a map that only loads if import assertions are supported, but even if they don't the rest of the website keeps working
  • live.cartracker.nl — this is exactly the same code as in app.ulu.io. Maybe it's generated by some sort of framework that we could get to stop using assertions since it's just redundant for them.
  • mijnomgeving.justlease.nl — same as app.ulu.io
  • registrs.ur.gov.lv — they use it to show the website version in the footer. It's in a self-contained script tag, so the rest of the page works even with the syntax error.
  • sanlam.ma/fr/professionnel/ has a contact form with autocompletion for cities that only loads suggestions if assert are supported
  • secure.labdash.net — same as labdash.net
  • shifthappens.site — uses es-modules-shim v0.13.1 which has feature detection, but does not actually use assertions
  • shop.lepiantagionidelcaffe.com — they seem to use import assertions to load a list of regions, but their checkout form shows me the list of regions even in browsers without import assertions support. The rest of the JS still works. I couldn't find a behavioral difference.

Overall, it looks like most those website have been designed to fail gracefully in browsers without import assertions support, so that they keep working just with (sometimes) one specific feature unavailable.

@nicolo-ribaudo
Copy link
Member

image

Looking good :)

@syg
Copy link
Author

syg commented Jan 29, 2024

V8 has landed a CL that will warn on assert usage, recommending to use with instead. The plan is to remove assert support by 12.6, which will be stable by mid-June, 2024.

Edit: I should say the plan is, barring new data, like newly discovered incompat.

ludoaubert added a commit to ludoaubert/linkedboxdraw that referenced this issue Jun 18, 2024
TC39 has consensus for trying to deprecate and remove the `assert` keyword in favor of the new `with` keyword in import attribute syntax. That is, `import m from 'foo' assert { type: 'json' }` will now throw a SyntaxError, and developers must change to `import m from 'foo' with { type: 'json' }`. tc39/proposal-import-attributes#135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@syg @guybedford @nicolo-ribaudo and others