Repository navigation
Deeplinking is being interrupted by "Cannot read property 'apply' of undefined". #35577
Description
Description
This error occured after upgrading to 0.7x from 0.67 and deeplink worked properly before doing the upgrade.
Have to mention that in both cases (background state & starting through deeplink) the url of the deeplink is there (looking with console.log()).
This error is being thrown only if the app is in background, starting the app through deeplink throws no error.
TypeError: Cannot read property 'apply' of undefined, js engine: hermes
While debugging on simulator, I could just minimize the thrown error and actions defined for the deeplink are processed properly. However the thrown error seems to block the execution of the deeplink actions on a real device.
The error is caused as shown in the thrown error at emit()-method of EventEmitter.js (Line 105):
registration.listener.apply(registration.context, args);Adding a check if the listener is undefined before execution solves the issue for me and deeplink works as expected (both on the simulator and the real device):
if(typeof registration.listener !== "undefined" )
registration.listener.apply(registration.context, args);Unfortunately I am not sure, how this does effect the app in general and whether it must be solved by doing something else.
Version
0.70.4
Output of npx react-native info
System:
OS: macOS 13.0
CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
Memory: 32.26 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.14.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 8.3.1 - /usr/local/bin/npm
Watchman: 2022.03.21.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
Android SDK:
API Levels: 30, 31, 32
Build Tools: 30.0.2, 30.0.3, 32.0.0, 32.1.0
System Images: android-30 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom, android-31 | Google Play Intel x86 Atom_64
Android NDK: Not Found
IDEs:
Android Studio: 2021.2 AI-212.5712.43.2112.8609683
Xcode: 14.0.1/14A400 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_322 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.4 => 0.70.4
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
Create a project and configure deeplinking using the docs.
Add to AppDelegate.m:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [RCTLinkingManager application:application openURL:url options:options];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}in JSX:
Linking.getInitialURL().then(url => { //ACTIONS FOR DEEPLINK START }
Linking.addEventListener('url',(url)=>{ //ACTIONS FOR DEEPLINK DURING RUNTIME})
Activity
s123121 commentedon Dec 9, 2022
Upgrading from 0.67 to 0.70.6 and meet exactly this problem
taoqf commentedon Dec 10, 2022
I came to this, too. and I find the
nullmodules is always the multiple depended in my project.olosegres commentedon Dec 19, 2022
Same problem after update to 0.70.6
seco35 commentedon Dec 20, 2022
@olosegres @s123121 @taoqf
Have you tried the workaround (adding check for undefined)? Does it solve your issues too?
SerafinAna commentedon Dec 29, 2022
I also have this issue with React native 0.69.7
does anyone use in the project firebase package. maybe this is causing the problem
seco35 commentedon Jan 9, 2023
No firebase usage within my project.
gdeusdara commentedon Jan 20, 2023
Same problem after updating to 0.71.0
iBotPeaches commentedon Feb 1, 2023
@seco35 - I investigated this and I believe a regression occurred in this commit - e5c5dcd
old
new
It seems a possibility that we could have a registration without listener. I'm guessing since this was changed in RN70 that it might be at least the original issue reported here. Thought the typing looks like this shouldn't be possible :/
@yungsters - Sorry for ping, but you authored the commit I linked and perhaps have an idea if I'm off base or not on this research.
fix(EcentEmitter) only apply if listener exists react#35577
fix(EventEmitter) only apply if listener react#35577
DerBasler commentedon Feb 8, 2023
Thanks for the investigation @iBotPeaches hopefully they will merge it soon.
AlexandreMuskus commentedon Feb 8, 2023
hey guys!
when is this correction expected to be published?
yungsters commentedon Feb 8, 2023
This error is symptomatic of
EventEmitter.addListener(…)being called with a non-function second argument.Can someone help me understand the source of the non-function value being supplied to the 2nd argument to
EventEmitter.addListener(…)? That is what should be fixed here.cc @javache
21 remaining items
javache commentedon Sep 18, 2023
That's great! It would be good to understand which layer of the stack is causing this bug though. Polyfilling of Set/Map should no longer be required for RN builds, since modern JS engines support them natively.
yungsters commentedon Sep 18, 2023
@mikollo — It seems like the spread operator (
...) is not correctly iterating overSetin your application.Can you try verifying the following in your environment?
Are you able to reproduce this in a standard application setup?
We can certainly (and probably should) replace
[...registrations]withnew Set(registrations)orArray.from(registrations), but if there is something else that's broken with spreading iterators into arrays… that's also worrisome and worth fixing.yungsters commentedon Sep 18, 2023
In the meantime, I've created #39525 to change
EventEmitterto useArray.frominstead of the spread operator.mikollo commentedon Sep 18, 2023
I now see what was the root cause, I had the
looseoption turned on in my Babel config:and it transpiles
[...registrations]to[].concat(registrations). And sinceconcatdoes not treat all array-like objects as arrays by default, the problem arises. It was actually predicted in this comment for the Babel PR which introduced theconcatmechanism - babel/babel#9108 (comment).I believe this is not a standard application setup (
loosemode turned on), and therefore a bug on thereact-nativeside. I guess this issue can be closed. Thank you for your help!yungsters commentedon Sep 18, 2023
Thanks for following up with that context, @mikollo!
I am curious whether other folks who have encountered this issue (and commented above) also made use of the
looseoption when configuring@babel/plugin-transform-spread. It would be great if anyone else who has reported this issue could chime in on whether their problems are the result of the same root cause.RN: Switch EventEmitter to `Array.from(...)` (react#39525)
RN: Switch EventEmitter to `Array.from(...)` (#39525)
RN: Switch EventEmitter to `Array.from(...)` (#39525)
[0.72] Merge up to 0.72.6 upstream (#1952)
github-actions commentedon Mar 17, 2024
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
github-actions commentedon Mar 24, 2024
This issue was closed because it has been stalled for 7 days with no activity.