-
Notifications
You must be signed in to change notification settings - Fork 26.4k
feat(devtools): add transfer state tab #62465
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
base: main
Are you sure you want to change the base?
Conversation
Help needed:
|
devtools/projects/ng-devtools-backend/src/lib/client-event-subscribers.ts
Outdated
Show resolved
Hide resolved
devtools/projects/ng-devtools-backend/src/lib/ng-debug-api/ng-debug-api.ts
Outdated
Show resolved
Hide resolved
devtools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.ts
Outdated
Show resolved
Hide resolved
devtools/projects/ng-devtools-backend/src/lib/client-event-subscribers.ts
Outdated
Show resolved
Hide resolved
...ools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.scss
Outdated
Show resolved
Hide resolved
...ools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.scss
Outdated
Show resolved
Hide resolved
...ools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.scss
Outdated
Show resolved
Hide resolved
...ools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.html
Outdated
Show resolved
Hide resolved
...ools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.html
Outdated
Show resolved
Hide resolved
eb9c225
to
a331ee5
Compare
a331ee5
to
5ca05aa
Compare
const doc = getDocument(); | ||
|
||
const appId = injector.get(APP_ID); | ||
const scriptId = appId + '-state'; | ||
const script = doc.getElementById(scriptId) as HTMLScriptElement; | ||
|
||
if (!script) { | ||
return {}; | ||
} | ||
|
||
if (!script.textContent || script.textContent.trim() === '') { | ||
return {}; | ||
} | ||
return JSON.parse(script.textContent) as Record<string, unknown>; |
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 can basically be replaced by retrieveTransferredState()
located in transfer_state.ts
(we'll need to export it first).
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 would expect this function to strip internal framework keys from packages/core/src/hydration/utils.ts
: __nghData__
& __nghDeferData__
which are used for (incremental) hydration and don't have real meaning for developers.
|
||
@Component({ | ||
selector: 'ng-transfer-state', | ||
standalone: true, |
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.
nit: those aren't necessary anymore (since v19).
standalone: true, |
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.
can also remove it, thank you.
devtools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.ts
Outdated
Show resolved
Hide resolved
devtools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.ts
Outdated
Show resolved
Hide resolved
devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.html
Outdated
Show resolved
Hide resolved
...ools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.html
Outdated
Show resolved
Hide resolved
devtools/projects/ng-devtools-backend/src/lib/ng-debug-api/ng-debug-api.ts
Show resolved
Hide resolved
devtools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.ts
Outdated
Show resolved
Hide resolved
devtools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.ts
Outdated
Show resolved
Hide resolved
devtools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.ts
Outdated
Show resolved
Hide resolved
devtools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.ts
Outdated
Show resolved
Hide resolved
devtools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.ts
Outdated
Show resolved
Hide resolved
devtools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.ts
Outdated
Show resolved
Hide resolved
devtools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.ts
Outdated
Show resolved
Hide resolved
devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.ts
Outdated
Show resolved
Hide resolved
...ools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.scss
Outdated
Show resolved
Hide resolved
5ca05aa
to
cf4c8bb
Compare
const formatted = getFormattedValue(value); | ||
if (isExpanded) { | ||
return formatted; | ||
} | ||
return truncateText(formatted, maxLength); |
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.
Should replace this with a pure CSS solution (https://developer.mozilla.org/en-US/docs/Web/CSS/line-clamp) ?
(which would be applied to the DOM node that invokes this)
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.
Thanks for putting this together, very cool feature!
No major concerns on my side, just a few minor suggestions and potential UX improvements.
return; | ||
} | ||
|
||
const transferStateData = ng.ɵgetTransferState?.(injector) as Record<string, TransferStateValue>; |
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.
Nit: I think this should be | undefined
since ng.ɵgetTransferState
may not exist.
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 know that currently if the protocol event data type and ɵgetTransferState
return type diverge, we will get a compile-time error that they don't sufficiently overlap, but maybe it's safer to drop the assertion altogether?
devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.ts
Show resolved
Hide resolved
...ools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.html
Show resolved
Hide resolved
devtools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.ts
Outdated
Show resolved
Hide resolved
...ools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.html
Show resolved
Hide resolved
...ools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.scss
Show resolved
Hide resolved
...ools/projects/ng-devtools/src/lib/devtools-tabs/transfer-state/transfer-state.component.scss
Outdated
Show resolved
Hide resolved
cf4c8bb
to
0581d10
Compare
0581d10
to
93d523a
Compare
Add transfer state tab, which is taking transfer state script by using APP_ID. Created internal api ɵgetTransferState to retrieve transfer state value from app into devtools app.
93d523a
to
9c20601
Compare
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 great, just left one comment.
delete transferState[TRANSFER_STATE_TOKEN_ID]; | ||
delete transferState[TRANSFER_STATE_DEFER_BLOCKS_INFO]; |
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.
It'd be great to add a test for this change, to make sure we do not "leak" other private fields (we may add more in the future) into the transfer state visualization.
Unrelated (for followup PRs): it'd be great to rename TRANSFER_STATE_TOKEN_ID
-> TRANSFER_STATE_HYDRATION_INFO
to better represent the role of the symbol.
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.
cc @JeanMeche
PR Type
What kind of change does this PR introduce?
What is the current behavior?
transfer state is visible only on elements tab in ng-state script.
Issue Number: #62237
What is the new behavior?
Did workaround with adding of new transfer state tab. Still consider solution with transfer state list in components tab intead of proposed. Let me know which one is prefered.
Demo:

Does this PR introduce a breaking change?