Open Protonosgit opened 5 months ago
same
same
Edit: I do think this involves the expo-router team.
Got the background messages going in kill state, though I would appreciate feedback on this solution by the expo-router team:
// src/index.ts
import 'expo-router/entry'
import messaging from '@react-native-firebase/messaging'
// must register the handler as soon as possible.
messaging().setBackgroundMessageHandler(async (m) => {
console.log('GOT FROM FIREBASE', JSON.stringify(m))
})
and in package.json:
- "main": "expo-router/entry",
+ "main": "src/index.ts",
The setup we have in order to close in on traditional setups is a RootLayout
:
// src/nav/_layout.tsx
import { Slot } from 'expo-router'
import App from '../App'
export default function RootLayout() {
return (
<App>
<Slot />
</App>
)
And therefore an App
with usually all the setup
// src/App.tsx
// bunch of setup
function App({ children }: PropsWithChildren) {
return (
<WhateverProviders>
{children}
</WhateverProviders
)
}
Though adding the messaging().setBackgroundMessageHandler(...)
within App.tsx
was not "early" enough and therefore found this src/index.ts
workaround...
I already suspected something similar here but wasn't really sure so I tried to collect similar reports. Thank you for your contribution I will try your approach!
Edit: I do think this involves the expo-router team.
Got the background messages going in kill state, though I would appreciate feedback on this solution by the expo-router team:
// src/index.ts import 'expo-router/entry' import messaging from '@react-native-firebase/messaging' // must register the handler as soon as possible. messaging().setBackgroundMessageHandler(async (m) => { console.log('GOT FROM FIREBASE', JSON.stringify(m)) })
and in package.json:
- "main": "expo-router/entry", + "main": "src/index.ts",
This worked for us. Our device logs stopped showing the No task registered
error.
Edit: I do think this involves the expo-router team. Got the background messages going in kill state, though I would appreciate feedback on this solution by the expo-router team:
// src/index.ts import 'expo-router/entry' import messaging from '@react-native-firebase/messaging' // must register the handler as soon as possible. messaging().setBackgroundMessageHandler(async (m) => { console.log('GOT FROM FIREBASE', JSON.stringify(m)) })
and in package.json:
- "main": "expo-router/entry", + "main": "src/index.ts",
This worked for us. Our device logs stopped showing the
No task registered
error.
I currently cannot remove expo router from my project but this seems like the best solution for now
Minimal reproducible example
https://github.com/Protonosgit/StickerSmash
Which package manager are you using? (Yarn is recommended)
npm
If the issue is web-related, please select the bundler (
web.bundler
in theapp.json
)metro
Summary
When sending notifications they only arrive in foreground and background state but never in quit state. Appending a title/body to the custom notification (notifee) allows the notification to show up in quit state as well but the handler still fails. The setBackgroundMessageHandler handler itself works and triggers when the app is in background but not in a closed state. The notification is received by the app which starts in headless mode but then fails. (see bellow)
Notification test in all states:
Context: 1. Received in foreground 2. Received in background 3. Received in quit state I'm using expo-router and everything was implemented as suggested in the docs.
Also interesting:
Other people had this issue With expo file based routing enabled so I suppose this could be a problem with the startup sequence of the app ? Production builds crash on startup when the handler is implemented but prebuilds work fine?
Environment
expo-env-info 1.2.0 environment info: System: OS: Windows 11 10.0.22631 Binaries: Node: 22.0.0 - C:\Program Files\nodejs\node.EXE npm: 10.8.0 - C:\Program Files\nodejs\npm.CMD IDEs: Android Studio: AI-233.14808.21.2331.11709847 npmPackages: expo: ^51.0.8 => 51.0.12 expo-router: ~3.5.14 => 3.5.16 react: 18.2.0 => 18.2.0 react-native: ^0.74.2 => 0.74.2 Expo Workflow: bare