-
Notifications
You must be signed in to change notification settings - Fork 37
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
Use ReadableStreamLinks for normal data transport, too #424
base: next
Are you sure you want to change the base?
Conversation
|
commit: |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
#457 Bundle Size — 1.33MiB (+6.79%).49c78d2(current) vs 5293db1 main#409(baseline) Warning Bundle contains 1 duplicate package – View duplicate packages Warning Bundle introduced one new package: process – View changed packages Bundle metrics
Bundle size by type
Bundle analysis report Branch pr/use-readable-stream-everywher... Project dashboard Generated by RelativeCI Documentation Report issue |
c4219d8
to
43ce452
Compare
@@ -313,6 +315,7 @@ describe( | |||
appendToBody`<div hidden id="S:1"><div id="user">User</div></div>`; | |||
$RS("S:1", "P:1"); | |||
|
|||
await new Promise((resolve) => setTimeout(resolve, 10)); |
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.
Arriving request data (simulateRequestData
) now takes a tick as it goes through the link chain instead of directly being written to the store. Without this delay, this test would have written the query first and then the data from the link would have arrived.
} | ||
|
||
setLink(newLink: ApolloLink) { | ||
super.setLink.call( | ||
this, | ||
ApolloLink.from([ | ||
new ReadFromReadableStreamLink(), | ||
new TeeToReadableStreamLink(), | ||
newLink, | ||
]) | ||
); | ||
} |
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.
All implementations (SSR, RSC, Browser) now use the same links - RSC could omit the ReadFromReadableStreamLink
, but keeping all those separate details is very prone to subtle bugs; this is more reasonable.
if ( | ||
!queryManager["inFlightLinkObservables"].peekArray(cacheKeyArr) | ||
?.observable | ||
) { |
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.
No more manually added inFlightLinkObservables
- we really use a link, so this doesn't need to fiddle with QueryManager
internals.
observable: streamObservable, | ||
return super.watchQuery({ | ||
...options, | ||
context: teeToReadableStream(() => this.pushEventStream(options), { |
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.
Moving this into a callback that only executes if the link is actually called means we will never inject a "started" event (or worse, a stream) when the query is deduplicated or for some other reason doesn't cause a network request.
constructor(options: WrappedApolloClientOptions) { | ||
super(options); | ||
this.setLink(this.link); | ||
} | ||
class ApolloClientBrowserImpl extends ApolloClientClientBaseImpl {} | ||
|
||
setLink(newLink: ApolloLink) { | ||
super.setLink.call(this, new ReadFromReadableStreamLink().concat(newLink)); | ||
} | ||
} | ||
|
||
class ApolloClientRSCImpl extends ApolloClientBase { | ||
constructor(options: WrappedApolloClientOptions) { | ||
super(options); | ||
this.setLink(this.link); | ||
} | ||
|
||
setLink(newLink: ApolloLink) { | ||
super.setLink.call(this, new TeeToReadableStreamLink().concat(newLink)); | ||
} | ||
} | ||
class ApolloClientRSCImpl extends ApolloClientBase {} |
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 these here even though they're empty - those class names might help in stack traces submitted by users to more quickly identify problems (and tbh., at some point I'll add back some env-specific logic here anyways)
const script = `__APOLLO_EVENTS__.push(${jsesc(event, { | ||
isScriptContext: true, | ||
wrap: true, | ||
json: true, | ||
})})`; | ||
ssr.injectScript(() => script); |
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.
This previously had a bug, where the injectScript
callback would be called later and at that point in time the AC core had actually written additional properties to event
, which meant that unneccessary data was transported over the wire.
We now stringify the object immediately.
No description provided.