forked from facebook/react
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
[WIP]: Injecting parse function from extension to devtools #91
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vibhorgupta-gh
changed the title
Injecting parse function from extension to devtools
[WIP]: Injecting parse function from extension to devtools
Nov 10, 2020
First thing I noticed when trying this branch out is that it throws an error whenever I selected a component (even one that has hooks):
|
bvaughn
reviewed
Nov 10, 2020
packages/react-devtools-shared/src/devtools/views/Components/InspectedElementContext.js
Outdated
Show resolved
Hide resolved
vibhorgupta-gh
force-pushed
the
InjectFunctionFromExtension
branch
from
November 13, 2020 07:38
208c1ee
to
4518c29
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Requesting review for this commit.
How it's intended to work:
injectHookVariableNamesFunction
returns a promise that resolves to the new hook object after 2 seconds (to mock for the potential delay in parsing) which gets passed down via context for rendering. As per the last discussion, the following happens:hookResource
is declared (with the defaultfetch
argument forcreateResource
simply returning a promise that resolves to the initial hook object of the originalinspectedElement
objectinjectHookVariableNamesFunction
is present, this function is called and the promise for new hooks obtained is written to the new hook resourcegetInspectedElement
we read the hook resource to extract the new hooks objects and set it in theinspectedElement
objectHow it's working:
We aren't able to handle promises properly along with the suspense and resource approach. Observations from looking in
cache.js
:accessResult
, a.then()
is called on a thenable and a pending status with the value as the thenable is returnedresource.write(key, val)
and object with resolved state and value asval
is set andaccessResult
simply returns this objectIn this approach, we're writing the promise of the new hook object as the value with the
inspectedElement
as the key in thehookResource
and while reading from this resource, fulfilled promise object (containing the desired new hook object) is returned, instead of the actual object. However, if we don't write anything to thehookResource
and trigger the default case (which returns the original hooks for now), things work as expected and hook array is returned on reading the resource.Screenshots of the
inspectedElement
for both these cases follow:injectHookVariableNamesFunction
and then try to read It from the resource. This results in the hook key being a promise object.hookResource
, and it perfectly returns an array of hooks, set ininspectedElement
Note: The approach in the concerned commit works if we don't return a promise from
injectHookVariableNamesFunction
, instead just return a dummy hook object (for experimentation purposes) and write that tohookResource
.Maybe we're missing something really nuanced or something very basic? It feels like we have some degree of understanding of how suspense and
createResource
work, but there still are gaps in our knowledge and need nudging in the right direction