-
Notifications
You must be signed in to change notification settings - Fork 7
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: socket.io infra and decouple ws and chatroom #261
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
f2e768e
to
ef43ed9
Compare
ef43ed9
to
4071626
Compare
實測發現只要在 _app.tsx 中塞入 SocketProvider 就會導致 Lighthouse CI 失敗,如圖: |
🤖 Lighthouse Scan Result for 8388796 /rooms
/rooms/abc
/login
|
Hello Justin @ttpss930141011 ,
以上說明,感謝! |
Hello @Yuwen-ctw ,
修改完之後有幾點想討論:
的情況就會失敗,我猜想是在本專案 Lighthouse CI 中,在
就能讓 ChatroomProvider 那邊的 socket 取得正常而不會是 undefined,所以我猜想是因為我們使用了 useRef,導致 socket 在連接過後子組件不會因為 socket 改變而 re-render 進而取得正確的值,而 Shirley 剛好在 SocketProvider 裡面有寫了一個 state 誤打誤撞(還是其實有設計好XD) re-render 了 SocketProvider,而 ChatroomProvider 因為 Parent re-render 所以自己也 re-render,然後就取得了正確的 socket。所以我想或許我們這邊改用 useState 會比較好? 以上幾點感謝抽空討論! |
Hello Justin, |
87e26aa
to
73c84dc
Compare
- Refactor the code relevant to Websocket (ws) to use socket.io instead. - Decouple the socket-relevant functionality with ChatroomProvider - Moved Socket Constants to file `@/contexts/SocketContext` - Encapsulated connect logic to function - Added onlineUsers setInterval console in mock socketio server to observer easily
73c84dc
to
914ca06
Compare
Kudos, SonarCloud Quality Gate passed!
|
✅ Knip Scan Result for 914ca06 Unused files (10)
Unused dependencies (2)
Unused devDependencies (5)
Configuration issues (1)
|
Hello @Yuwen-ctw 在最新的 commit 除了有以下改動:
還有額外在 mock socket server 路由 |
Why need this change? / Root cause:
這隻 PR & branch 是從這邊分出來的:Here,因為寫一寫忘記切 branch 出來導致弄亂了 @arealclimber 的分支還真不好意思,基本上這支 PR 只是在上面這支 PR 多做一點微調與調整 commit 而已,完整資訊請查閱以上 PR。
@/contexts/SocketContext
Changes made:
useSocketCore.ts
.SocketProvider.ts
as a function.SocketContext.tsx
Test Scope / Change impact:
Issue