-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: use __SWR_DEVTOOLS_USE__ hook #55
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
If we inject a middleware from a web accessible resource, we have to use the same the React instance the application is using, otherwise we have an invalid hook call error. That seems to be a bit tricky. |
13506f8 just sends post messages in a middleware. This works fine, but it only gives us limited functionality. |
f61c092 uses the existing middleware without the use of React Hooks. |
In this approach, we don't have a way to invoke discarded events because we cannot use a cleanup function of |
09898a6
to
657dd41
Compare
I'll do a beta release of SWR these two days and we can try it out. ❤️ |
const { useLayoutEffect, useEffect, useRef } = | ||
typeof window !== "undefined" && | ||
// @ts-expect-error | ||
typeof window.__SWR_DEVTOOLS_REACT__ !== "undefined" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@koba04 Do you feel we could also use a "hook" or "callback" thing to pass down more stuff? like
const { React: SharedReact } = window.__SWR_DEVTOOLS_HOOK__()
const { useLayoutEffect, useEffect, useRef } = SharedReact
once we need anything else besides the shared React
, we can pass more parameters to the return value of the callback. so that the devtools protocol might not need to change in the future if the return values is changed. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any example for things other than React that we might need @huozhi?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet, I just feel it's easier to not break the protocol, for now we only need React
, but later we might have others. Returning from a hook function can be pretty flexible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think of React as a special case here (because the same instance in required) and we don’t want to pass around things in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@huozhi @shuding
As @shuding mentioned, React is a special case for that reason, so we don't have other things we'd like to pass.
But something might come up in the future. In this case, I can add a new "hook" like __SWR_DEVTOOLS_HOOK__
and include React
in the hook, so I feel __SWR_DEVTOOLS_REACT__
is enough at this time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that sounds fair. Maybe a renaming to SWR_DEVTOOLS_XXX else not tight to react itself can be nicer since it's not that too specific, and could be upgraded loosely without needed to be tight with swr version. But it's just my personal thought not a blocking at all for any current change 👍 🚀
If devtool is tighted with version then we can also change it later when it's necessary
vercel/swr#2016 has been merged, so I'll merge this too. If there is any issue, I'll fix it later. |
fixes #52
This requires to add the hook into
swr
, so I'm working on it in https://github.com/koba04/swr/tree/devtools-hook