[Django] #33336: Widget.Media.JS ESM support

12 views
Skip to first unread message

Django

unread,
Dec 2, 2021, 3:48:58 AM12/2/21
to django-...@googlegroups.com
#33336: Widget.Media.JS ESM support
---------------------------------------+------------------------
Reporter: James Pic | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
---------------------------------------+------------------------
Currently, Django only renders widget JS media as scripts:

https://github.com/django/django/blob/main/django/forms/widgets.py#L82

It would be great to support type=module right there.

https://developer.mozilla.org/fr/docs/Web/JavaScript/Guide/Modules#charger_le_module_via_le_document_html

--
Ticket URL: <https://code.djangoproject.com/ticket/33336>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 2, 2021, 4:10:56 AM12/2/21
to django-...@googlegroups.com
#33336: Widget.Media.JS ESM support
-----------------------------+--------------------------------------

Reporter: James Pic | Owner: nobody
Type: New feature | Status: closed
Component: Forms | Version: 3.2
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


Comment:

As far as I'm aware we can close is as a duplicate of more general ticket
#9357.

--
Ticket URL: <https://code.djangoproject.com/ticket/33336#comment:1>

Django

unread,
Dec 2, 2021, 4:19:58 AM12/2/21
to django-...@googlegroups.com
#33336: Widget.Media.JS ESM support
-----------------------------+--------------------------------------
Reporter: James Pic | Owner: nobody
Type: New feature | Status: closed
Component: Forms | Version: 3.2
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------

Comment (by James Pic):

And that's how the decision has been made to not support ESM in Django.
There goes a very convenient feature for modern web development!

--
Ticket URL: <https://code.djangoproject.com/ticket/33336#comment:2>

Django

unread,
Dec 2, 2021, 4:59:03 AM12/2/21
to django-...@googlegroups.com
#33336: Widget.Media.JS ESM support
-----------------------------+--------------------------------------
Reporter: James Pic | Owner: nobody
Type: New feature | Status: closed
Component: Forms | Version: 3.2
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------

Comment (by Mariusz Felisiak):

Replying to [comment:2 James Pic]:


> And that's how the decision has been made to not support ESM in Django.
There goes a very convenient feature for modern web development!

I wouldn't say that. There are other media types that we could support
but the first step to opening this door is to handle `Media` subclasses in
Django. It would be straightforward to support JavaScript modules (or
others) with #9357, e.g.:
{{{
class MyMedia(Media):
def __init__(self, media=None, css=None, js=None, js_modules=None):
self.js_modules = js_modules
super().__init__(media, css, js)

def render_js_modules(self):
return format_html(...)
}}}

You can start a discussion on the DevelopersMailingList, where you'll
reach a wider audience and see what other think. We can always reopen this
ticket after reaching a consensus that JavaScript modules should be
treated and handled separately.

--
Ticket URL: <https://code.djangoproject.com/ticket/33336#comment:3>

Django

unread,
Dec 2, 2021, 5:09:23 AM12/2/21
to django-...@googlegroups.com
#33336: Widget.Media.JS ESM support
-----------------------------+--------------------------------------
Reporter: James Pic | Owner: nobody
Type: New feature | Status: closed
Component: Forms | Version: 3.2
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------

Comment (by James Pic):

Thank you Mariusz! I'm not on the mailing list but if anyone's looking for
an example they can use there's one here I just made up:
https://yourlabs.io/oss/djhacker/-/commit/9695044ebb6047b86bf3d573383f412a5917bfc9

--
Ticket URL: <https://code.djangoproject.com/ticket/33336#comment:4>

Reply all
Reply to author
Forward
0 new messages