Skip to content
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

Network tab #51

Merged
merged 6 commits into from
Jun 2, 2022
Merged

Network tab #51

merged 6 commits into from
Jun 2, 2022

Conversation

shuding
Copy link
Collaborator

@shuding shuding commented May 29, 2022

Closes #28.

This PR adds an initial implementation of a Network tab (waterfall chart) similar to Chrome DevTools' Network Tab. Basic design behind this:

  • I added some logic to the middleware to collect events of fetch start, success, error, discarded. Besides the SWR key, each request is also attached with a random ID to distinguish from others.
    • These events are broadcasted via window.postMessage to the extension window.
    • The event emitter is also passed to the current React tree via context, this is for demo usage.
  • SWRDevToolPanel receives the events and gives them to NetworkPanel.
  • NetworkPanel cleans up the data, grouping them by hook keys, and give it to the timeline scroller.
  • timeline/index.tsx is a headless virtual timeline scroller and handles the UI.

I tested the virtual scroller with 500 useSWR hooks and 1000+ requests and it's still pretty smooth on my laptop. Also, I added some random delay to the API and enabled the failing hook.

I noticed a couple of bugs, such as ongoing request that never ends, but should be good at the moment. Another thing to be done is supporting useSWRInfinite.

CleanShot 2022-05-30 at 00 12 35@2x

@vercel
Copy link

vercel bot commented May 29, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
swr-devtools ✅ Ready (Inspect) Visit Preview Jun 2, 2022 at 11:32AM (UTC)

@koba04
Copy link
Owner

koba04 commented May 30, 2022

Great work!!! 👏 👏
This is a great starting point 🚀 so I think It's ok to get merged this even if this still has bugs.
I'll merge this after passing CI.

image

(We should support the Dark theme as well)

@shuding
Copy link
Collaborator Author

shuding commented May 31, 2022

I'll fix the lint error as well as dark mode support :)

@shuding
Copy link
Collaborator Author

shuding commented Jun 2, 2022

It should look better under dark mode now!

CleanShot 2022-06-02 at 13 31 15@2x

Copy link
Owner

@koba04 koba04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, great works!!! 👏 👏

@koba04 koba04 merged commit 449c587 into main Jun 2, 2022
@koba04 koba04 deleted the shu/0e2a branch June 2, 2022 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: waterfall chart
2 participants