在反应应用程序中,我在同一个文件中有两个几乎相同的函数来将文档添加到子集合中。一个每次都有效,另一个使用不同的子集合,大多数时候都会收到以下警告(注意:不是错误),并且不会添加数据。
await addDoc(collection(db, 'users', uid, 'medications'), med);
[2022-02-16T20:54:44.216Z] @firebase/firestore: Firestore (9.6.6): 连接 WebChannel 传输错误: Vd {type: 'c', target: Y, g: Y, defaultPrevented: false,状态:1}
另一个奇怪的行为是,调用 addDoc 后,应用程序会重新导航到当前页面,但会将要添加到文档中的数据附加到 URL 中。页面中根本没有导航链接。无论是否添加数据都会发生这种情况。
导航到 http://localhost:3000/create?name=test+med+again&description=a+med+for+testing&form=capsule&dosage=1&measurement=ea&occurrence=2&often=daily
关于 firestore Connection WebChannel 传输错误。我在尝试在 React Native 中实现简单的增删改查操作时遇到了类似的问题。我在互联网上找到的大多数解决方案都与向 firestore 初始化添加设置有关,但它们也使用 firebase v8 语法(请参阅:React Native 重复超时将集合写入 firestore@firebase/firestore:Firestore (8.4.2):连接 WebChannel 传输错误 https://stackoverflow.com/questions/67374674/react-native-repeated-timeouts-writing-collection-to-firestorefirebase-firestor)
这种初始化 firestore 的方式在 firebase(9.8.3) 上为我解决了这个问题
const app = initializeApp(firebaseConfig);
export const db = initializeFirestore(app, {
experimentalForceLongPolling: true,
useFetchStreams: false,
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)