Closed Bug 1668848 Opened 4 years ago Closed 4 years ago

Cleanup, rectify and improve readibility and performance of recipientAddPills()

Categories

(Thunderbird :: Message Compose Window, task)

Desktop
All

Tracking

(thunderbird_esr78 fixed, thunderbird82 fixed)

RESOLVED FIXED
83 Branch
Tracking Status
thunderbird_esr78 --- fixed
thunderbird82 --- fixed

People

(Reporter: thomas8, Assigned: thomas8)

References

(Regression)

Details

(Keywords: regression)

Attachments

(1 file, 1 obsolete file)

+++ This bug was initially created as a clone of Bug #1666463 +++

Cleanup, rectify and improve readibility and performance of recipientAddPills().
Some notes on coding style.

Find the fault!

  let addresses = MailServices.headerParser.makeFromDisplayAddress(
    element.value
  );

  for (let address of addresses) {
    let pill = createRecipientPill(element, address);
    parent.insertBefore(pill, element);
 
    // Be sure to add the user add recipient to our ignore list
    // when the user hits enter in an autocomplete widget...
    addRecipientsToIgnoreList(element.value);
  }
  • Something is wrong here: First we break up element.value (a string of comma-separated addresses) into an array of address objects, then, for each iteration, we add the full input string again to the spellcheck ignore list. We don't know anything about the performance data of the spell thingy, so doing potentially unlimited repeated rounds with that flaw isn't right.
  • Oh, element is the address input, but you could have guessed that! Not? That's exactly what leads to bugs like the above. Much easier to overlook problems with that generic element argument. Imho, a litte bit of semantic/functional connotation helps.
  • addRecipientsToIgnoreList() wants a string argument (which we had), but it won't tell you unless you dig around some levels deeper in the nested internals of other dependent functions. Should try to document a bit when we re-use those oldies.
  • Current function name, recipientAddPill(), and the existing function comment both wrongly suggest that this function will only ever add a single recipient pill (again contributing to the above coding flaw). Imho any function which can handle/create/return more than one thing should have a plural name, and description should be clear. It makes a big difference if we create a single pill (for which there's yet another function) or multiple pills.
  • Avoid repeated runs of addRecipientsToIgnoreList() for all addresses of input.value. For n address pills, we were adding addresses to the spell check ignore list.
  • Change function name from recipientAddPill() to recipientAddPills().
  • Rename 'element' argument to 'input' (for some adjacent minor functions, too).
  • Improve various function comments.
Assignee: nobody → bugzilla2007
Status: NEW → ASSIGNED
Attachment #9179294 - Flags: review?(alessandro)
Comment on attachment 9179294 [details] [diff] [review]
1668848_recipientAddPillsCleanup.diff

Review of attachment 9179294 [details] [diff] [review]:
-----------------------------------------------------------------

This is great, thank you so much for doing it.
Just a little nit if you think it's worth doing it.

::: mail/components/compose/content/addressingWidgetOverlay.js
@@ +788,1 @@
>    for (let pill of container.querySelectorAll("mail-address-pill")) {

I guess we could avoid declaring the container variable since we don't use it to check for its existence.
Attachment #9179294 - Flags: review?(alessandro) → review+
Comment on attachment 9179294 [details] [diff] [review]
1668848_recipientAddPillsCleanup.diff

Review of attachment 9179294 [details] [diff] [review]:
-----------------------------------------------------------------

Small eslint error

::: mail/components/compose/content/addressingWidgetOverlay.js
@@ +743,5 @@
>      return;
>    }
>  
>    let addresses = MailServices.headerParser.makeFromDisplayAddress(
> +    input.value

eslint nit: this fits all in a single line.

(In reply to Alessandro Castellani (:aleca) from comment #2)

Just a little nit if you think it's worth doing it.

Of course. Dotted the t's and crossed the i's - or something like that ;-)
Lovely... after double scrutiny from Alex and myself!

Attachment #9179294 - Attachment is obsolete: true
Attachment #9180263 - Flags: review+
Target Milestone: --- → 83 Branch

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/2fa5dbefac96
Cleanup, rectify and improve readibility and performance of recipientAddPills(). r=aleca

Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED

I think we should.
This is purely a "clean up" type of patch, but if we don't uplift we risk to have merging issues if future patches that touch these sections need to be uplifted.

Comment on attachment 9180263 [details] [diff] [review]
1668848_recipientAddPillsCleanup.diff

[Approval Request Comment]
Per comment 7

Attachment #9180263 - Flags: approval-comm-esr78?
Attachment #9180263 - Flags: approval-comm-beta?

Comment on attachment 9180263 [details] [diff] [review]
1668848_recipientAddPillsCleanup.diff

[Triage Comment]
Approved for beta

Attachment #9180263 - Flags: approval-comm-beta? → approval-comm-beta+

Comment on attachment 9180263 [details] [diff] [review]
1668848_recipientAddPillsCleanup.diff

[Triage Comment]
Approved for esr78

Attachment #9180263 - Flags: approval-comm-esr78? → approval-comm-esr78+

Appears to depend on another bug. The block above this contains

      if (!element || element.classList.contains("input-pill")) {
        return;
      }
Flags: needinfo?(rob)
Flags: needinfo?(alessandro)

Depends on bug 1665025 which looks benign enough, but there is also a change from bug 1665025 that come into play in addressInputOnBlur. The later is mostly renaming element to input it looks like, so adjusting accordingly.

Flags: needinfo?(rob)
Flags: needinfo?(alessandro)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: