Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Improve handling of lazy-loaded bundles before rendering #866

Closed
jcfranco opened this issue Feb 15, 2018 · 2 comments
Closed

Improve handling of lazy-loaded bundles before rendering #866

jcfranco opened this issue Feb 15, 2018 · 2 comments
Assignees
Milestone

Comments

@jcfranco
Copy link

There's a risk of flashing text when the target locale is dynamically set at application startup, causing widgets to render initially with the default bundle, then with the lazy-loaded bundle.

Preloading bundles may help, but there's need for a pattern to avoid this problem when preloading is not an option:

  • hard to determine which bundles to preload before rendering
  • preloading all bundles is overkill

@mwistrand Created issue as discussed. Let me know if I missed anything.


Context (gittr convo)

Hello. I have a widget + i18n question. Assuming an app allows setting the locale at startup, what's the recommended way to lazy-load NLS bundles without flashing text (default messages rendered before desired locale bundle loads)? I've modified the TodoMVC example to demonstrate this: https://jcfranco.github.io/examples/todo-mvc/?locale=es


@jcfranco If you are able to load the messages in advance, you can use the setLocaleMessages from @dojo/i18n/i18n module to preload locale-specific messages:

import { setLocaleMessages } from '@dojo/i18n/i18n';
import nlsBundle from './nls/main';

asyncLoadBundle().then(messages => {
  setLocaleMessages(nlsBundle, messages, locale);
});

That associates the bundle with the messages for the specified locale, with the result that it uses those messages instead of trying to load them with the function in the locales object map.


Belated thanks, @mwistrand.

If you are able to load the messages in advance

What if my app

  • is dynamic? Making it hard to determine which bundles to preload before rendering.

  • has more than one bundle (1 per widget)? preloading all bundles seems overkill.

Are there any patterns that would help with these scenarios?


@jcfranco At the moment, @dojo/widget-core blindly ignores anything that hasn’t been loaded yet and invalidates itself once the locale-specific messages have loaded.

However, we relatively recently updated how locale messages are loaded, so it’s now possible load them synchronously from within bundles themselves. Given that, off the top of my head I don’t see why we couldn’t check whether we receive promises or valid message objects back from the locale functions.

Would you mind opening an issue?

@mwistrand mwistrand self-assigned this Feb 15, 2018
@mwistrand
Copy link
Contributor

@jcfranco There's almost certainly a @dojo/i18n component to this, but I can create that issue if need be.

@jcfranco
Copy link
Author

but I can create that issue if need be.

👍 Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants