change: pass Scope
into Resource::read()
and Resource::with()
#542
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Calling
Resource::read()
orResource::with()
crawls up theScope
tree, looking for the nearest<Suspense/>
component, if any. This is used for streaming resource and suspense data from the server to the client during initial load, which is a significant optimization over waiting to start loading data until Wasm has loaded on the client.Previously, a
Scope
was given to theResource
when it was created, and it carried thisScope
around with it. Unfortunately, this meant that aResource
created in a "higher" scope couldn't be read correctly under a "lower"<Suspense/>
. For example, if you created a resource in the root of your application, reading it under a<Suspense/>
in one of your routes would not correctly register with the suspense, so would not properly stream.This PR corrects that behavior for the hopefully-small cost of passing the omnipresent
cx
as the first argument toResource::read()
andResource::with()
. Now, you can create a singleResource
somewhere in your app, pass it to multiple parts of the app viaprovide_context
, and read it under multiple streaming<Suspense/>
components while only actually loading the resource once.