Reset Hermes timezone cache on system timezone change#55467
Reset Hermes timezone cache on system timezone change#55467Im-awesome-Aadi wants to merge 1 commit intofacebook:mainfrom
Conversation
5e847ce to
f19553f
Compare
f19553f to
38b9ec3
Compare
…mezone change Summary: When the device timezone changes while the app is running, JavaScript Date still return the local time according to the previous timezone. This happens because Hermes caches timezone information to improve performance. If the device timezone changes during app runtime, local time calculations continue using the old cached timezone. Hermes provides a native API, resetTimezoneCache(), to reset this cached information. This PR adds an internal Android module that calls this API whenever the platform detects a timezone change. Changes: Kotlin: TimeZoneModule Listens for Intent.ACTION_TIMEZONE_CHANGED broadcasts Calls a JNI method to reset Hermes timezone cache Safely registers/unregisters the receiver during Catalyst lifecycle Open for unit testing C++: TimeZoneCache Provides resetNativeHermesTimeZoneCache() JNI method Calls hermes::IHermes::resetTimezoneCache() No-op if runtime pointer is null or runtime is not Hermes Test Plan: Java unit tests Verify broadcast receiver registration/unregistration Verify native reset hook is invoked on timezone change
38b9ec3 to
ed755dc
Compare
|
|
||
| private fun handleTimeZoneChange() { | ||
| try { | ||
| val catalystInstance = reactApplicationContext.catalystInstance ?: return |
There was a problem hiding this comment.
catalystInstance is a legacy arch concept and javaScriptContextHolder won't work there. Please ensure this works with the new arch.
There was a problem hiding this comment.
Thanks — that’s a good point. I’ll remove the dependency on CatalystInstance and switch to using RuntimeExecutor so this works correctly in the New Architecture and Bridgeless mode as well. I’ll update the JNI signature to accept a jsi::Runtime& instead of relying on JavaScriptContextHolder.
|
Hello @javache @Im-awesome-Aadi Do you have plans to merge this PR? |
Hey @troZee , i saw your repo addresses the same issue. I'm trying to fix it in core react-native. |
Changelog: [Android] [Fixed] Reset Hermes timezone cache on system timezone change
Summary:
When the device timezone changes while the app is running, JavaScript Date still return the local time according to the previous timezone.
This happens because Hermes caches timezone information to improve performance. If the device timezone changes during app runtime, local time calculations continue using the old cached timezone.
Hermes provides a native API, resetTimezoneCache(), to reset this cached information. This PR adds an internal Android module that calls this API whenever the platform detects a timezone change.
Changes:
Kotlin: TimeZoneModule
Listens for Intent.ACTION_TIMEZONE_CHANGED broadcasts
Calls a JNI method to reset Hermes timezone cache
Safely registers/unregisters the receiver during Catalyst lifecycle
Open for unit testing
C++: TimeZoneCache
Provides resetNativeHermesTimeZoneCache() JNI method
Calls hermes::IHermes::resetTimezoneCache()
No-op if runtime pointer is null or runtime is not Hermes
Test Plan:
Java unit tests
Verify broadcast receiver registration/unregistration
Verify native reset hook is invoked on timezone change