Skip to content

Conversation

@Avcharov
Copy link
Contributor

@Avcharov Avcharov commented Jul 4, 2025

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

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:
Click here for Demo Video

Снимок экрана 2025-07-04 в 10 30 01

Does this PR introduce a breaking change?

  • Yes
  • No

@pullapprove pullapprove bot requested a review from AleksanderBodurri July 4, 2025 08:04
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: devtools labels Jul 4, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 4, 2025
@Avcharov
Copy link
Contributor Author

Avcharov commented Jul 4, 2025

Help needed:

  • In presented solution it looks for transferState script only by ng-state id. However if APP_ID would not be default it will not work. How to inject APP_ID from debugged applications?
  • I used material for layout if needed can be edited to custom solution.

@Avcharov Avcharov force-pushed the devtools/transfer-state-tab branch 2 times, most recently from eb9c225 to a331ee5 Compare July 7, 2025 09:44
@pullapprove pullapprove bot requested a review from AndrewKushnir July 7, 2025 09:44
@Avcharov Avcharov force-pushed the devtools/transfer-state-tab branch from a331ee5 to 5ca05aa Compare July 8, 2025 11:53
Comment on lines 22 to 35
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>;
Copy link
Member

@JeanMeche JeanMeche Jul 8, 2025

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).

Copy link
Member

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.

@JeanMeche JeanMeche force-pushed the devtools/transfer-state-tab branch from 93d523a to 9c20601 Compare July 18, 2025 23:53
@JeanMeche
Copy link
Member

@Avcharov I've allowed myself to force push an update following the merge of #62627

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a 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.

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JeanMeche thanks for the update, I've left a comment with a couple of suggestions.

Comment on lines 71 to 77
/**
* Set of transfer state keys that are used internally by the framework
*/
export const internalHydrationTransferStateKeys = [
TRANSFER_STATE_TOKEN_ID,
TRANSFER_STATE_DEFER_BLOCKS_INFO,
];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to propose a couple of changes:

  • Create a function (instead of an array) as mentioned below
  • Use the function to filter out such keys from the transfer state (in the logic inside of getTransferState)
  • For tests, we can use regular hydration specs as a base, just add a few more keys to the transfer state and after that assess whether getTransferState returns only public/application keys
Suggested change
/**
* Set of transfer state keys that are used internally by the framework
*/
export const internalHydrationTransferStateKeys = [
TRANSFER_STATE_TOKEN_ID,
TRANSFER_STATE_DEFER_BLOCKS_INFO,
];
/**
* Checks whether a given key is used by the framework for transferring hydration data.
*/
export function isInternalHydrationTransferStateKey(key: string): boolean {
return key === TRANSFER_STATE_TOKEN_ID || key === TRANSFER_STATE_DEFER_BLOCKS_INFO;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've extracted the core part of this PR into a separate PR #62722

@JeanMeche
Copy link
Member

JeanMeche commented Jul 20, 2025

Blocked on #62722
We'll split the core part of this PR into a separate one to simplify the review !

@JeanMeche JeanMeche force-pushed the devtools/transfer-state-tab branch from 7be7172 to 9c20601 Compare July 20, 2025 23:00
@Avcharov
Copy link
Contributor Author

@JeanMeche what you think about adding checkbox "Hide internal keys" on top of the page to hide hydration and other internal keys conditionally?

As sometimes maybe that keys can be useful, as @eneajaho mentioned in this PR

@JeanMeche
Copy link
Member

That could an idea, but let's keep that for as a follow-up and let's try to land this PR first 🙂

@JeanMeche JeanMeche force-pushed the devtools/transfer-state-tab branch from 9c20601 to 35a701d Compare July 21, 2025 21:09
@JeanMeche JeanMeche force-pushed the devtools/transfer-state-tab branch from 35a701d to 7ec3fc2 Compare July 21, 2025 21:10
@JeanMeche
Copy link
Member

PR is now unblocked, we need a final approval and we can send it to the merge queue !

@JeanMeche JeanMeche force-pushed the devtools/transfer-state-tab branch from 7ec3fc2 to 037febd Compare July 21, 2025 22:01
Copy link
Contributor

@dgp1130 dgp1130 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks good to me, happy to merge this as is and we can iterate more as we move forward with it.

Thanks @Avcharov for contributing this! It's a very cool addition to Angular DevTools.

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.
@JeanMeche JeanMeche force-pushed the devtools/transfer-state-tab branch from 037febd to 03f1d92 Compare July 21, 2025 22:24
Copy link
Contributor

@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

reviewed-for: fw-general

@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release labels Jul 22, 2025
@kirjs
Copy link
Contributor

kirjs commented Jul 22, 2025

This PR was merged into the repository by commit a2f366f.

The changes were merged into the following branches: main

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: devtools detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants