Closed Bug 1782486 Opened 2 years ago Closed 2 years ago

After calling CompFields2Recipients() with empty fields, autocomplete fails

Categories

(Thunderbird :: Add-Ons: Extensions API, defect, P3)

Thunderbird 102
Unspecified
Windows 10

Tracking

(thunderbird_esr102+ fixed, thunderbird104 fixed)

RESOLVED FIXED
105 Branch
Tracking Status
thunderbird_esr102 + fixed
thunderbird104 --- fixed

People

(Reporter: miketm1986, Assigned: TbSync)

Details

Attachments

(3 files)

Hello guys!

I did not find how to reopen Bug 1773663, so I have to create a new one.

We have investigated the issue and found that looks like function CompFields2Recipients is broken. In Bug 1773663 I mentioned that the problem does not occur if I switch off my addon.

The problem is that my add-on actively uses CompFields2Recipients function.

In ThunderBird 91 if we called CompFields2Recipients with empty fields nothing particular happend.
But in ThunderBird 102 - autocomplete just stops working in that case.

So we have problem with the following types of mails: New, ForwardAsAttachment и ForwardInline. BUT if we make reply, problem does not occur (fields are not empty).

As a walkaround we may use this:

(function (){

Services.wm.addListener({
                    onOpenWindow: function (aWindow) {
                        Services.wm.removeListener(this);
                        this.composeWin = aWindow.docShell.domWindow;
                        this.composeWin.addEventListener("compose-editor-ready", this, true);
                    },
                    handleEvent: function (event) {
                        if (event.type == "compose-editor-ready") {
                            event.currentTarget.removeEventListener(event.type, this, true);
                            let win = event.target.ownerGlobal;
                            let compFields = win.gMsgCompose.compFields;
                           
                            win.CompFields2Recipients(compFields);
                            //it is a cure (if we comment these 4 rows - the problem occurs):
                            try {
                                let row = win.document.getElementById("addressRowTo");
                                let input = row.querySelector(".address-row-input");
                                input.detachController();
                                input.attachController();
                            } catch {}

                        }
                    }
                });
ComposeMessage(Ci.nsIMsgCompType.New, Ci.nsIMsgCompFormat.Default);

})();

Please check our guess about CompFields2Recipients function being broken.
Thank you!

John, is this add-on territory?

Severity: -- → S3
Component: Address Book → Add-Ons: Extensions API
Flags: needinfo?(john)
Priority: -- → P3
Summary: Address autocomplete and Address Book SEARCH are broken.-2 → After calling CompFields2Recipients() with empty fields, autocomplete fails

I cannot reproduce this bug. I pasted the following code into Thunderbirds Javascript console and hit enter:

Services.wm.addListener({
    onOpenWindow: function (aWindow) {
        Services.wm.removeListener(this);
        this.composeWin = aWindow.docShell.domWindow;
        this.composeWin.addEventListener("compose-editor-ready", this, true);
    },
    handleEvent: function (event) {
        if (event.type == "compose-editor-ready") {
            console.log("TEST")
            event.currentTarget.removeEventListener(event.type, this, true);
            let win = event.target.ownerGlobal;
            let compFields = win.gMsgCompose.compFields;
            win.CompFields2Recipients(compFields);
        }
    }
});
ComposeMessage(Ci.nsIMsgCompType.New, Ci.nsIMsgCompFormat.Default);

The composer opens, I see "Test" written and autocomplete works. Tested in:

  • 105.0a1 (2022-08-04) (64-bit)
  • 104.0b2 (32-Bit)
  • 102.1.0 (64-Bit)

All on Windows 10.

Are you able to reproduce this in a fresh profile (with a few contacts added to the address book) on any of these versions? If it is not just the code above which is triggering this behaviour for you, it must be something else.

Flags: needinfo?(john)

Hello!

Thank you for your reply.
We spent sometime for reproducing a bug at fresh profile and looks like we found key factor.
What we did.
We set up fresh profile and found that error did not occur.
But then we add an email at "Reply adress" field in the Account settings and that the problemm immediately back.
I will attach 2 screenshots

Attached image 1.png

Screen shot shows it works

Attached image 2.png

Screen shot shows it does not work

Thanks! With that info, I can recreate it on a fresh profile by passing in a value for any of the allowed values (replyTo, followupTo, ...) but not the currently active one (To):

Services.wm.addListener({
    onOpenWindow: function (aWindow) {
        Services.wm.removeListener(this);
        this.composeWin = aWindow.docShell.domWindow;
        this.composeWin.addEventListener("compose-editor-ready", this, true);
    },
    handleEvent: function (event) {
        if (event.type == "compose-editor-ready") {
            console.log("TEST")
            event.currentTarget.removeEventListener(event.type, this, true);
            let win = event.target.ownerGlobal;
            let compFields = win.gMsgCompose.compFields;
            win.CompFields2Recipients({followupTo: "test@user.net"});
        }
    }
});
ComposeMessage(Ci.nsIMsgCompType.New, Ci.nsIMsgCompFormat.Default);

This bug is also affecting the WebExtension API. Executing

browser.compose.beginNew({replyTo: "test@user.net"}) 

will open up a new composer where the autocomplete on the To field is not working either, while it does work after calling

browser.compose.beginNew({to: "test@user.net"}) 

Setting focus from the To field to the Subject and back fixes it for me. I will try to understand why.

@ alessandro : Do you have an idea, why the autocomplete feature gets disabled for the currently active address input field (To), if CompFields2Recipients() is changing another(!) address input field (replyTo, followupTo, cc, bcc)?

The autocomplete feature is enabled again, if focus is removed and added back.

Flags: needinfo?(alessandro)
Status: UNCONFIRMED → NEW
Ever confirmed: true
Assignee: nobody → john
Status: NEW → ASSIGNED

This is the important stack when calling browser.compose.beginNew({replyTo: "test@user.net"}) (from top to bottom, for better readability)

  • chrome://messenger/content/parent/ext-compose.js#272 :
    setComposeDetails({replyTo: "test@user.net"})
    
  • chrome://messenger/content/parent/ext-compose.js#521 :
    SetComposeDetails({replyTo: "test@user.net"})
    
  • chrome://messenger/content/messengercompose/MsgComposeCommands.js#5567 :
    CompFields2Recipients({replyTo: "test@user.net"})
    
  • chrome://messenger/content/messengercompose/addressingWidgetOverlay.js#114 :
    setAddressRowFromCompField(
        "addressRowReply",
        "test@user.net",
        true
    )
    
  • chrome://messenger/content/messengercompose/addressingWidgetOverlay.js#99 :
    recipientAddPills(
        hbox#replyAddrContainer.input-container.wrap-container.address-container (=input)
        true
    )
    
  • chrome://messenger/content/messengercompose/addressingWidgetOverlay.js#856 :
    input.detachController();
    input.attachController()
    

detachController() checks if the current controller belongs to the given input - and since ReplyTo != AddrTo, it does not detach the controller. However, attachController() overwrites the controller nevertheless, which causes the autocomplete to break.

My proposed fix it therefore to attach the controller only if it was detached.

Grrr.

My change to detachController() to return a boolean did not make it into my patch, because it is toolkit code. Will need a different approach.

Checking for !input.mController.input now.

Maybe there is a better way to identify if detach/attach is needed at all?

Flags: needinfo?(alessandro)
Target Milestone: --- → 105 Branch

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/05446ad14e1a
Re-attach autocomplete controller only if it was detached. r=aleca

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

Comment on attachment 9288883 [details]
Bug 1782486 - Re-attach autocomplete controller only if it was detached. r=aleca

[Approval Request Comment]
Regression caused by (bug #):
User impact if declined:
Autocompete in composer does not work under certain conditions

Testing completed (on c-c, etc.):
3 days on Daily

Risk to taking this patch (and alternatives if risky):
I do not see an obvious risk. The code change is minimal.

Attachment #9288883 - Flags: approval-comm-beta?

Comment on attachment 9288883 [details]
Bug 1782486 - Re-attach autocomplete controller only if it was detached. r=aleca

[Triage Comment]
Approved for beta.

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

Comment on attachment 9288883 [details]
Bug 1782486 - Re-attach autocomplete controller only if it was detached. r=aleca

[Approval Request Comment]
Regression caused by (bug #):
User impact if declined:
Autocompete in composer does not work under certain conditions

Testing completed (on c-c, etc.):
On Beta since 104

Risk to taking this patch (and alternatives if risky):
I do not see an obvious risk. The code change is minimal.

Attachment #9288883 - Flags: approval-comm-esr102?

Comment on attachment 9288883 [details]
Bug 1782486 - Re-attach autocomplete controller only if it was detached. r=aleca

[Triage Comment]
Approved for esr102

Attachment #9288883 - Flags: approval-comm-esr102? → approval-comm-esr102+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: