-
Notifications
You must be signed in to change notification settings - Fork 324
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
Add client performance markers and measurements #1534
base: v1.x-2022-07
Are you sure you want to change the base?
Conversation
9f8cf50
to
8db4969
Compare
@@ -231,7 +231,15 @@ function useServerResponse(state: any) { | |||
|
|||
if (rscReader) { | |||
// The flight response was inlined during SSR, use it directly. | |||
response = createFromReadableStream(rscReader); | |||
const [streamForRsc, streamForMetrics] = rscReader.tee(); |
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 wish there was a better way to know when the stream is finished without tee-ing it.
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.
We are the ones creating this rscReader
in this same file so we could just add a hook there, no? It's basically the same as DOMContentLoaded
.
However, I don't think any of this is measuring the work that React does internally in createFromReadableStream
since it's async and there are no hooks for that. We could add one and ask the React team to consider the use case, e.g. response.onDone = () => {}
. I guess I'm not sure what part we're trying to measure here.
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.
Leaving a couple of comments here but I'm not sure if I understand the use-case.
Also, hydration
vs rsc
is kind of confusing to me. What do you think about using initial-hydration
/ssr-hydration
vs rsc
/hydration
performance.mark('--hydrogen-rsc-start'); | ||
|
||
// Request a new flight response. | ||
response = createFromFetch( | ||
fetch(`${RSC_PATHNAME}?state=` + encodeURIComponent(key)) | ||
); | ||
performance.mark('--hydrogen-rsc-end'); |
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.
Hmm, this all happens synchronously so I don't think there's a difference between rsc-start and rsc-end here, no?
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.
Looks like you are right. I had assumed that createFromFetch
throw'ed.
@@ -231,7 +231,15 @@ function useServerResponse(state: any) { | |||
|
|||
if (rscReader) { | |||
// The flight response was inlined during SSR, use it directly. | |||
response = createFromReadableStream(rscReader); | |||
const [streamForRsc, streamForMetrics] = rscReader.tee(); |
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.
We are the ones creating this rscReader
in this same file so we could just add a hook there, no? It's basically the same as DOMContentLoaded
.
However, I don't think any of this is measuring the work that React does internally in createFromReadableStream
since it's async and there are no hooks for that. We could add one and ask the React team to consider the use case, e.g. response.onDone = () => {}
. I guess I'm not sure what part we're trying to measure here.
Resolves: Shopify/hydrogen#1479
Before submitting the PR, please make sure you do the following:
fixes #123
)yarn changeset add
if this PR cause a version bump based on Keep a Changelog and adheres to Semantic Versioning