-
Notifications
You must be signed in to change notification settings - Fork 221
🐛 Make the webpack plugins return regular objects intead of Modules #618
Conversation
d91ca56
to
43fd2e8
Compare
I considered doing a one liner like: return {
...(await import(/* webpackChunkName: "Locales-i18n-[request]" */ `locales/${locale}.json`)),
}; But the two-step approach seemed clearer to me. Opinions? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look at this. I think the more appropriate solution is to return the default export of the module, though.
Oh you're right, I didn't realize we could do that as well. Updated the PR :D |
@@ -37,7 +37,8 @@ describe('babel-pluin-react-i18n', () => { | |||
id: 'MyComponent_${defaultHash}', | |||
fallback: _en, | |||
async translations(locale) { | |||
return await import(/* webpackChunkName: "MyComponent_${defaultHash}-i18n", webpackMode: "lazy-once" */ \`./translations/$\{locale}.json\`); | |||
const dictionary = await import(/* webpackChunkName: "MyComponent_${defaultHash}-i18n", webpackMode: "lazy-once" */ \`./translations/$\{locale}.json\`); | |||
return dictionary.default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it may be safer to do dictionary && dictionary.default
since there is not a 100% guarantee a module will be resolved totally correctly (and undefined is a valid value to return)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, especially since this is added to the code post-compile. Done!
cc8d2ae
to
3bce59e
Compare
33a2f1c
to
fe3ca32
Compare
…o hooks__react-shortcuts * 'hooks__react-shortcuts' of github.com:Shopify/quilt: yarn lock feedback Adds useShortcut hook Publish React testing improvements (#621) Publish 🐛Make the webpack plugins return regular objects intead of Modules (#618) Publish @shopify/react-testing (#603) Publish update changelog ✅ updates tests to use GraphQL success response 🐛 check success via valid webhookSubscription field Publish adding changelog entry and docs for #601 Add client submit errors to errors in render prop Publish Update trigger to support act() (#612) Add a promise mock (#614)
Currently the webpack plugin in
react-i18n
gives consumers aModule
object to work with. This isn't what's expected, and this PR changes it to return a simple Object instead.Dynamic
import
statements return object-like data primitives calledModules
. These modules behave roughly like an object in terms of access, but don't have any of the standardObject
functions since they're not created with anObject
as a prototype.I believe the expectation here is that react-i18n return a standard object for people to manipulate, not a Module, hence this change. For example, this caused a regression in
web
when@shopify/polaris
was updated to use a custom simplifiedmerge
function, instead oflodash
's merge function.lodash
could deal withModules
, but the new simplified function expects simpleObjects
.