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
[DevTools] Implemented re-render mechanism for React 16.9+ #17072
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2115,6 +2115,7 @@ export function attach( | |
const typeSymbol = getTypeSymbol(type); | ||
|
||
let canViewSource = false; | ||
let canForceRerender = false; | ||
let context = null; | ||
if ( | ||
tag === ClassComponent || | ||
|
@@ -2126,6 +2127,11 @@ export function attach( | |
tag === SimpleMemoComponent | ||
) { | ||
canViewSource = true; | ||
|
||
if (typeof scheduleUpdate === 'function') { | ||
canForceRerender = true; | ||
} | ||
|
||
if (stateNode && stateNode.context != null) { | ||
// Don't show an empty context object for class components that don't use the context API. | ||
const shouldHideContext = | ||
|
@@ -2247,6 +2253,9 @@ export function attach( | |
// Can view component source location. | ||
canViewSource, | ||
|
||
// Can force the component to re-render. | ||
canForceRerender, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be conditional based on the element type. Right now it shows up for all types, including e.g. context providers and consumers, etc- re-rendering these doesn't make sense. Seems like this should be for class, function, forward ref, and maybe memo components types only? |
||
|
||
// Does the component have legacy context attached to it. | ||
hasLegacyContext, | ||
|
||
|
@@ -2517,6 +2526,14 @@ export function attach( | |
} | ||
} | ||
|
||
function forceRerender(id: number) { | ||
const fiber = findCurrentFiberUsingSlowPathById(id); | ||
|
||
if (fiber !== null && typeof scheduleUpdate === 'function') { | ||
scheduleUpdate(fiber); | ||
} | ||
} | ||
|
||
function setInHook( | ||
id: number, | ||
index: number, | ||
|
@@ -3029,6 +3046,7 @@ export function attach( | |
handleCommitFiberUnmount, | ||
inspectElement, | ||
logElementToConsole, | ||
forceRerender, | ||
prepareViewElementSource, | ||
overrideSuspense, | ||
renderer, | ||
|
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.
super nit: Maybe just "forceRender" ? The "re" seems unnecessary.