Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for lazy loading promises #163

Merged
merged 2 commits into from
Jan 14, 2019
Merged

Wait for lazy loading promises #163

merged 2 commits into from
Jan 14, 2019

Conversation

Alex--C
Copy link

@Alex--C Alex--C commented Dec 5, 2018

According to the docs, lazy loaded locales should be able to return a promise. Doing this creates a warning message ever since nuxt switched to https://github.com/Rich-Harris/devalue .

This pull request prevents this warning. If lazy loading returns a promise, it waits for it before returning from loadLanguageAsync and returns the resolved value instead.
Resolves nuxt/nuxt#4424 . Related: #161 .

@@ -20,9 +20,10 @@ export async function loadLanguageAsync (i18n, locale) {
try {
const module = await import(/* webpackChunkName: "lang-[request]" */ '~/<%= options.langDir %>' + file)
const messages = module.default ? module.default : module
i18n.setLocaleMessage(locale, typeof messages === 'function' ? await Promise.resolve(messages()) : messages)
let result = typeof messages === 'function' ? await Promise.resolve(messages()) : messages

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const result is better I guess

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I changed that.

@michaelwnyc michaelwnyc mentioned this pull request Jan 6, 2019
@paulgv paulgv merged commit 8b42631 into nuxt-modules:master Jan 14, 2019
@paulgv
Copy link
Collaborator

paulgv commented Jan 14, 2019

Thanks @Alex--C and sorry for the delay!

@Alex--C
Copy link
Author

Alex--C commented Jan 14, 2019

Thanks @Alex--C and sorry for the delay!

No problem - thank you for the merge! :D

farnabaz added a commit to farnabaz/i18n-module that referenced this pull request Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WARN Cannot stringify a function
3 participants