View Issue Details

IDProjectCategoryView StatusLast Update
0003537Composr alpha bug reports[All Projects] General / Uncategorisedpublic2018-03-14 23:12
ReporterChris GrahamAssigned ToSalman 
SeverityFeature-request 
Status resolvedResolutionfixed 
Summary0003537: Late JS loading discussion
DescriptionI want to open a discussion about how JS is loading as deferred.
I know this is for performance, and I'm not saying we shouldn't do this, but there's definitely a discussion to have as I noticed at least one nasty issue we need to resolve.

If you go to a posting form (e.g. cms_news module add screen) and click one of the Comcode toolbar buttons before JS loads, it will post the form.

I'm interested in how we should tackle this. I have no immediate thoughts, so I'm pushing to you (Salman).
TagsNo tags attached.
Sponsorship open

Activities

Salman

2018-03-12 18:08

reporter   ~0005572

Interestingly I've not had to tackle this one before. One solution is: we can attach a global listener to the 'submit' event and prevent all form submissions before DOM ready, using event.preventDefault(). What do you think?

Chris Graham

2018-03-12 18:20

administrator   ~0005573

Problems with that:
1) We need to do non-deferred load on some JS again, somewhat defeating the point (we'd need to add a server hop or inline JS which'd be messy). A server hop is comparable in badness to just loading global.js, as it's about the latency more than the bandwidth.
2) To do it well we'd need to give UI feedback, or to reinject the event later somehow, meaning even more overhead, just for this corner case.

What if we change action="..." to action="#" data-jsready-action="..." for all JS-controlled forms? Obviously we then do a switcheroo once JS has loaded.

Chris Graham

2018-03-12 18:22

administrator   ~0005574

Well, we'd need to switcheroo method="post" too.

Actually I am now wondering what would happen if we did method="js", would browsers not submit the form? I guess they'd remap to post.

Chris Graham

2018-03-12 18:26

administrator   ~0005575

Actually my solution doesn't given any UI feedback either.

Maybe we could do the non-JS action to something like...

"javascript: window.alert('Page still loading');"

Salman

2018-03-13 01:26

reporter   ~0005578

Last edited: 2018-03-13 01:31

View 2 revisions

>We need to do non-deferred load on some JS again
Sorry I forgot to mention, we already preventDefault() for <a>'s and <form>'s with [href="#!"] and [action="#!"] in dom_init.js, which is loaded early synchronously to keep track of dependencies and provide $dom.ready/load.then() early for those who still want to use inline script tags. We can add to it, we can add the alert message there too.

>Actually I am now wondering what would happen if we did method="js"
I think it would do an HTTP 'JS' request instead of GET or POST.

The switcheroo method seems like a good idea but might be a bit intrusive and potentially break third party forms/code somehow (Edit: If we set the data attributes using JS). Thoughts?

Chris Graham

2018-03-13 01:34

administrator   ~0005579

Last edited: 2018-03-13 01:34

View 2 revisions

Okay, so looking at this case, the problem is those Comcode editor buttons are within the main add/edit form, hence why your "#!" solution isn't working.

"The switcheroo method seems like a good idea but might be a bit intrusive and potentially break third party forms/code somehow. Thoughts?"

We'd only do it if data-jsready-action was there (or whatever you called it).

So perhaps we combine what you already do, with my suggestions...

<form action="#!" data-jsready-action="..." ...>

Your dom_init.js code would inject the window.alert's for the above case only.

Your full JS lib would then do the switcheroo when it loads.

(I'm assuming your existing solution removes the need to set a non-POST method)


So here we are solving 3 problems:
1) Forms submitting prior to JS checks
2) Lack of UI feedback on some forms prior to JS loading fully
3) Fixing the specific bug reported here

Salman

2018-03-14 17:32

reporter   ~0005584

I have fixed the form submission issue using the preventDefault() method and showing an alert message.

Issue History

Date Modified Username Field Change
2018-02-10 14:56 Chris Graham New Issue
2018-02-10 14:56 Chris Graham Status non-assigned => assigned
2018-02-10 14:56 Chris Graham Assigned To => Salman
2018-03-12 18:08 Salman Note Added: 0005572
2018-03-12 18:20 Chris Graham Note Added: 0005573
2018-03-12 18:22 Chris Graham Note Added: 0005574
2018-03-12 18:26 Chris Graham Note Added: 0005575
2018-03-13 01:26 Salman Note Added: 0005578
2018-03-13 01:31 Salman Note Edited: 0005578 View Revisions
2018-03-13 01:34 Chris Graham Note Added: 0005579
2018-03-13 01:34 Chris Graham Note Edited: 0005579 View Revisions
2018-03-14 17:32 Salman Note Added: 0005584
2018-03-14 23:12 Chris Graham Status assigned => resolved
2018-03-14 23:12 Chris Graham Resolution open => fixed
2023-02-26 18:29 Chris Graham Category General => General / Uncategorised