Migrate <stringbundle> from XBL binding to Custom Element to prove out the script loading plan for future Custom Elements

RESOLVED FIXED in Firefox 62

Status

()

enhancement
RESOLVED FIXED
a year ago
11 months ago

People

(Reporter: bgrins, Assigned: bgrins)

Tracking

(Blocks 1 bug)

unspecified
mozilla62
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox62 fixed)

Details

Attachments

(1 attachment)

(Assignee)

Description

a year ago
Since the <findbar> conversion (Bug 1411707) is tied in with some Fluent work and is generally just a more complex binding, I'd like to prove out the plan in MainProcessSingleton (which was also discussed in Bug 1442006) with a trivial binding, like <stringbundle>.
Comment hidden (mozreview-request)
(Assignee)

Comment 2

a year ago
Requesting review now, but definitely don't want to land anything here until after the merge
Assignee: nobody → bgrinstead
Status: NEW → ASSIGNED
(Assignee)

Comment 3

a year ago
Jorg, after this patch in order for stringbundle to work, stringbundle.js will need to be loaded in all XUL documents. Does mail already load toolkit/components/processsingleton/MainProcessSingleton.js? If so, I don't think there will need to be any changes in comm-central. If not, then the new lines from that file will have to be copied across to whatever the equivalent file is for mail.

Consumers of <stringbundle> won't need to change as long as the Custom Element gets registered properly.

The patch is still subject to change, but just wanted to give a heads up that this is likely to be the first XBL to Custom Element migration to land so hoping for a smooth transition.
Flags: needinfo?(jorgk)

Comment 5

a year ago
Thanks, I'll look into it.
Comment hidden (mozreview-request)

Comment 7

a year ago
mozreview-review
Comment on attachment 8973271 [details]
Bug 1459245 - Migrate <stringbundle> from a XBL binding to a Custom Element;

https://reviewboard.mozilla.org/r/241726/#review248016
Attachment #8973271 - Flags: review?(dtownsend) → review+

Comment 9

a year ago
Pushed by bgrinstead@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/80fc39b7c5ec
Migrate <stringbundle> from a XBL binding to a Custom Element;r=mossop

Comment 10

a year ago
It looks like you forgot to cover the profile manager :-(
JavaScript error: chrome://mozapps/content/profile/profileSelection.js, line 41:
 TypeError: gProfileManagerBundle.getFormattedString is not a function
Flags: needinfo?(jorgk) → needinfo?(bgrinstead)

Comment 11

a year ago
I also see:
JavaScript error: chrome://global/content/elements/stringbundle.js, line 61: Not
SupportedError: Operation is not supported

That comes from
customElements.define("stringbundle", MozStringbundle);

Comment 12

a year ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/80fc39b7c5ec
Status: ASSIGNED → RESOLVED
Last Resolved: a year ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla62
(Assignee)

Comment 13

a year ago
(In reply to Jorg K (GMT+1) from comment #10)
> It looks like you forgot to cover the profile manager :-(
> JavaScript error: chrome://mozapps/content/profile/profileSelection.js, line
> 41:
>  TypeError: gProfileManagerBundle.getFormattedString is not a function

Hm, I guess we don't have any tests covering that :(. I'll take a look.
Flags: needinfo?(bgrinstead)
(Assignee)

Comment 14

a year ago
If I copy the contents of stringbundle.js into profileSelection.js then the CE does get registered. It looks like the profile picker is loaded before MainProcessSingleton is loaded. Mossop, is there a different place we could set up observer notifications that will detect them for the profile manager window? Alternatively, we could move the block

```
for (let script of [
  "chrome://global/content/elements/stringbundle.js",
]) {
  Services.scriptloader.loadSubScript(script, doc.ownerGlobal);
}
```

into a new JS file and then subscript load it from mainprocesssingleton and explicitly include it as a <script> at the top of the profile manager document(s).
Flags: needinfo?(dtownsend)
(Assignee)

Comment 15

a year ago
Or a temporary fix would be to include:

  <script type="application/x-javascript"
          src="chrome://global/content/elements/stringbundle.js"/>

at the top of profileSelection.xul and createProfileWizard.xul.

Comment 16

a year ago
Please also fix the error from comment #11.
(Assignee)

Comment 17

a year ago
(In reply to Jorg K (GMT+1) from comment #16)
> Please also fix the error from comment #11.

When do you see that error, in the profile manager? At least in m-c we aren't even loading the script before opening the profile manager.

Comment 18

a year ago
(In reply to Brian Grinstead [:bgrins] from comment #15)
> Or a temporary fix would be to include:
> 
>   <script type="application/x-javascript"
>           src="chrome://global/content/elements/stringbundle.js"/>
> 
> at the top of profileSelection.xul and createProfileWizard.xul.

Shouldn’t we be using the unprefixed `application/javascript` MIME type instead?

Comment 19

a year ago
(In reply to Brian Grinstead [:bgrins] from comment #17)
> When do you see that error, in the profile manager? At least in m-c we
> aren't even loading the script before opening the profile manager.
Sorry, afk right now. I saw it in the debug console when starting TB without the p/m. Don't you see it in FF? What does that line do?
(In reply to Brian Grinstead [:bgrins] from comment #14)
> If I copy the contents of stringbundle.js into profileSelection.js then the
> CE does get registered. It looks like the profile picker is loaded before
> MainProcessSingleton is loaded. Mossop, is there a different place we could
> set up observer notifications that will detect them for the profile manager
> window?

Not really no. We could hardcode loading that component into NS_InitXPCOM2 but that's probably more effort than it is worth. The profile manager (and related profile startup UI) are something of a special snowflake here, I can't think of anything else that shows UI before the app-startup notification so I suggest we handle it specially rather than trying to fix for the general case.

> Alternatively, we could move the block
> 
> ```
> for (let script of [
>   "chrome://global/content/elements/stringbundle.js",
> ]) {
>   Services.scriptloader.loadSubScript(script, doc.ownerGlobal);
> }
> ```
> 
> into a new JS file and then subscript load it from mainprocesssingleton and
> explicitly include it as a <script> at the top of the profile manager
> document(s).

I wonder if we'd be better preprocessing all the CE implementations into a single file so it is just one load, then we can just use a script tag in the profile manager UI.
Flags: needinfo?(dtownsend)
(Assignee)

Comment 21

a year ago
(In reply to Dave Townsend [:mossop] from comment #20)
> (In reply to Brian Grinstead [:bgrins] from comment #14)
> > If I copy the contents of stringbundle.js into profileSelection.js then the
> > CE does get registered. It looks like the profile picker is loaded before
> > MainProcessSingleton is loaded. Mossop, is there a different place we could
> > set up observer notifications that will detect them for the profile manager
> > window?
> 
> Not really no. We could hardcode loading that component into NS_InitXPCOM2
> but that's probably more effort than it is worth. The profile manager (and
> related profile startup UI) are something of a special snowflake here, I
> can't think of anything else that shows UI before the app-startup
> notification so I suggest we handle it specially rather than trying to fix
> for the general case.

OK, I'll file a new bug and get a patch up.

> > Alternatively, we could move the block
> > 
> > ```
> > for (let script of [
> >   "chrome://global/content/elements/stringbundle.js",
> > ]) {
> >   Services.scriptloader.loadSubScript(script, doc.ownerGlobal);
> > }
> > ```
> > 
> > into a new JS file and then subscript load it from mainprocesssingleton and
> > explicitly include it as a <script> at the top of the profile manager
> > document(s).
> 
> I wonder if we'd be better preprocessing all the CE implementations into a
> single file so it is just one load, then we can just use a script tag in the
> profile manager UI.

My preference would be to not do this until we have to for perf reasons, since it makes it harder to debug (line numbers / file names don't map back to the source files).
(Assignee)

Updated

a year ago
Depends on: 1459985

Comment 22

a year ago
I see
  JavaScript error: chrome://global/content/elements/stringbundle.js, line 61: Not Supported
  Error: Operation is not supported
when starting TB with |-p Testing| where "Testing" is my testing profile.
(Assignee)

Comment 23

a year ago
(In reply to Jorg K (GMT+1) from comment #22)
> I see
>   JavaScript error: chrome://global/content/elements/stringbundle.js, line
> 61: Not Supported
>   Error: Operation is not supported
> when starting TB with |-p Testing| where "Testing" is my testing profile.

Hm, I don't see that on m-c (locally or on logs from bc tests in treeherder). Do stringbundles not work at all? Or, I wonder if this is happening only on a single window - could you `console.log(window.location.toString());` right before the call to customElements.define?
Flags: needinfo?(jorgk)

Comment 24

a year ago
Hmm, with this code:
dump(window.location.toString()+"================\n");
customElements.define("stringbundle", MozStringbundle);
dump("after CE ================\n");

I see:
chrome://messenger/content/newmailalert.xul================
after CE ================
chrome://messenger/content/newmailalert.xul================
JavaScript error: chrome://global/content/elements/stringbundle.js, line 62: Not
SupportedError: Operation is not supported

chrome://messenger/content/msgAccountCentral.xul================
after CE ================
chrome://messenger/content/msgAccountCentral.xul================
JavaScript error: chrome://global/content/elements/stringbundle.js, line 62: Not
SupportedError: Operation is not supported

chrome://messenger/content/messenger.xul================
after CE ================
chrome://messenger/content/messenger.xul================
JavaScript error: chrome://global/content/elements/stringbundle.js, line 62: Not
SupportedError: Operation is not supported

Almost looks like this is called twice and the second one fails.

Maybe we got this wrong:
https://hg.mozilla.org/comm-central/rev/b00e830b9e5e3a006102519c34b8fc8e862e9cdf
Flags: needinfo?(jorgk)
(Assignee)

Comment 25

a year ago
(In reply to Jorg K (GMT+1) from comment #24)
> Hmm, with this code:
> dump(window.location.toString()+"================\n");
> customElements.define("stringbundle", MozStringbundle);
> dump("after CE ================\n");
> 
> I see:
> chrome://messenger/content/newmailalert.xul================
> after CE ================
> chrome://messenger/content/newmailalert.xul================
> JavaScript error: chrome://global/content/elements/stringbundle.js, line 62:
> Not
> SupportedError: Operation is not supported
> 
> chrome://messenger/content/msgAccountCentral.xul================
> after CE ================
> chrome://messenger/content/msgAccountCentral.xul================
> JavaScript error: chrome://global/content/elements/stringbundle.js, line 62:
> Not
> SupportedError: Operation is not supported
> 
> chrome://messenger/content/messenger.xul================
> after CE ================
> chrome://messenger/content/messenger.xul================
> JavaScript error: chrome://global/content/elements/stringbundle.js, line 62:
> Not
> SupportedError: Operation is not supported
> 
> Almost looks like this is called twice and the second one fails.
> 
> Maybe we got this wrong:
> https://hg.mozilla.org/comm-central/rev/
> b00e830b9e5e3a006102519c34b8fc8e862e9cdf

Oh OK. Yes, if it's already defined it will throw that (not very helpfully named) exception - for example:

data:text/html,<script>customElements.define("foo-bar", class extends HTMLElement {}); customElements.define("foo-bar", class extends HTMLElement {})</script>

Are you sure that MainProcessSingleton isn't running already? Maybe you don't need to port it to mail glue. You could check with `console.trace();` right before your logs.

Comment 26

a year ago
OK, let's continue the discussion in bug 1459743.
(Assignee)

Updated

a year ago
Depends on: 1460334
(Assignee)

Updated

a year ago
Blocks: 1460334
No longer depends on: 1460334
(Assignee)

Updated

11 months ago
Blocks: 1461388
(Assignee)

Updated

11 months ago
No longer blocks: 1460334
You need to log in before you can comment on or make changes to this bug.