-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
refactor: Convert Animated directory to use ESModule imports/exports #34539
refactor: Convert Animated directory to use ESModule imports/exports #34539
Conversation
9ed091b
to
ea74740
Compare
Base commit: b2452ab |
ea74740
to
be02361
Compare
Base commit: b2452ab |
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.
Looks like CI tests are still failing and there's a lint warning.
ScrollView: AnimatedScrollView, | ||
SectionList: AnimatedSectionList, | ||
Text: AnimatedText, | ||
View: AnimatedView, | ||
...Animated, | ||
}; |
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 we'll want to keep this, as it enables lazy initialization of these modules (if you don't have the inline-requires transform enabled)
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.
Got it, I'll revert this
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.
@javache What do you mean by this if you don't have the inline-requires transform enabled
? Could you explain it a little bit more ?
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.
Reverted
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.
@TMaszko see https://reactnative.dev/docs/ram-bundles-inline-requires for details on inline-requires. It's an important transform we apply to improve bundle init time.
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.
@javache I know that optimization technique. My question is why getters do enable lazy initialization when inline-requires transform is disabled? I thought it will work only when this transform is enabled that's why I wanted you to explain it ;)
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.
Ah, sorry for misunderstanding. In this case the require
is manually inlined, and we would only invoke the module factory for that module once the getter is invoked. When using import
syntax, that manual inlining is not possible.
When the inline-requires transform is enabled, you get this behaviour for free (as long as you're using a getter in this case)
be02361
to
f24ae20
Compare
@@ -21,7 +21,7 @@ jest.mock('../../BatchedBridge/NativeModules', () => ({ | |||
}, | |||
})); | |||
|
|||
let Animated = require('../Animated'); | |||
let Animated = require('../Animated').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.
Kept it like this because using ES module imports here breaks jest mocks
const Animated = require('../Animated').default; | ||
const NativeAnimatedHelper = require('../NativeAnimatedHelper').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.
Kept it like this because using ES module imports here breaks jest mocks
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.
@javache please let me know if this approach is ok for test files of if we should do something different
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.
It should be possible to "fix" jest mocks to work with ES module imports too, but I'm no expert.
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.
If you have to dynamically import module and reset it for some reason after each test you have to stick to the require
unfortunately :(. In this case though ES module imports should work just fine.
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 believe we won't be able to replace any of these require
s from jest test files, on these tests we rely on jest.resetModules
and that seems to only work with require()
(jestjs/jest#3236).
Any thoughts on what we should do? @javache @TMaszko @necolas
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.
Tests don't matter so much. It's the Animated module syntax that I have to edit every time I sync code to React Native for Web.
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.
@gabrieldonadel Sorry, but I haven't spotted jest.resetModules
calls. In this case in my opinion we have to just deal with require
.
@@ -11,9 +11,9 @@ | |||
|
|||
'use strict'; | |||
|
|||
const createAnimatedComponent = require('../createAnimatedComponent'); | |||
const createAnimatedComponent = require('../createAnimatedComponent').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.
Using import here also breaks jest
a2155bb
to
f99174d
Compare
@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
f99174d
to
f45fb04
Compare
This is currently blocked on merging internally, since it breaks the flow-type export of |
Is there something that I can help with? |
This pull request was successfully merged by @gabrieldonadel in f63d4e7. When will my fix make it into a release? | Upcoming Releases |
…acebook#34539) Summary: This PR refactors the Animated directory to use ESModule imports/exports instead of using a mixture of the 2 module formats, as requested on facebook#34425. ## Changelog [Internal] [Changed] - Convert all files in the Animated directory to use ESModule imports/exports Pull Request resolved: facebook#34539 Test Plan: This doesn't really add or modify any existing features so checking if CI passes should be enough Reviewed By: yungsters Differential Revision: D39235720 Pulled By: yungsters fbshipit-source-id: 84b4c0a71dc9fca1ab7053263f1cf7c336df58c1
Summary
This PR refactors the Animated directory to use ESModule imports/exports instead of using a mixture of the 2 module formats, as requested on #34425.
Changelog
[Internal] [Changed] - Convert all files in the Animated directory to use ESModule imports/exports
Test Plan
This doesn't really add or modify any existing features so checking if CI passes should be enough