Closed Bug 1115773 Opened 9 years ago Closed 9 years ago

Fallback mechanism keeps loading last locale for each missing entity

Categories

(Firefox OS Graveyard :: Gaia::L10n, defect)

x86
All
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: zbraniecki, Assigned: stas)

References

Details

Attachments

(1 file)

It seems that there's a bug in our code, that I noticed while working on langpacks.

When an entity is missing from en-US (defaultLocale), we load it. When the next entity is missing we seem to start loading it again.

I didn't debug it yet, but I see in logs that if en-US.json is empty, we load it many times.

We should fix it because with misuse of mozL10n.get (for testing if the entity is empty) we will load en-US Locale for each call. :/
Without any own debugging yet I wonder if it's the mutation observer that you see in the logs?  When we localize the HTML, the mutation observer calls getEntity, which starts loading the fallback locale.  Could it be that the next mutation is processed before en-US.json loads?  The loading should be synchronous but I'm not sure if I remember how exactly the mutation microtasks are executed.
idk. I'll try to reproduce it today.
I started debugging this earlier today and all I was seeing was telling me our sync XHR isn't sync.  After exploring many possible reasons (I suspected Gecko changes) I had a closer look at our io.loadJSON method:

https://github.com/mozilla-b2g/gaia/blob/2a39e2f4fb9785ce6dd5a914f9b844021d59a5f6/shared/js/l10n.js#L52

It's always async :)

I'll have a patch when I'm back tonight.  I noticed that we can't override the MIME type to JSON anymore in sync requests ("InvalidAccessError: A parameter or an operation is not supported by the underlying object") so we'll need to JSON.parse manually, I think.
Gosh, thanks! I was considering panicking. :)
Assignee: nobody → stas
Attachment #8545548 - Flags: review?(gandalf)
Comment on attachment 8545548 [details] [review]
Allow loadJSON to be async

I think there's still a major benefit in most common scenario to use responseType json. I'd like to preserve that.

Can we just check if it's sync and skip responseType and JSON.parse in the callback?
OK, I'll update the patch.  I was hoping we can get rid of the redundant code here though :(
Oops, it looks like I broke all l10n tests ^^.
Aaaand it's fixed now.  It looks like the treeherder is having a hiccup though;  I don't have the URL to a new build yet.
Comment on attachment 8545548 [details] [review]
Allow loadJSON to be async

sweet, thanks!
Attachment #8545548 - Flags: review?(gandalf) → review+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: