Skip to content

Conversation

@SkyZeroZx
Copy link
Contributor

The stringify function is only needed for debugging purposes and should not be called in production mode.

The `stringify` function is only needed for debugging purposes and
should not be called in production mode.
@pullapprove pullapprove bot requested a review from JeanMeche February 7, 2026 22:30
@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Feb 7, 2026
@ngbot ngbot bot added this to the Backlog milestone Feb 7, 2026
}

return new R3Injector(providers, parent || getNullInjector(), name || null, scopes);
return new R3Injector(providers, parent || getNullInjector(), source || null, scopes);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This value, as I understand it, is only used in dev

if (ngDevMode) {
prependTokenToDependencyPath(error, token);
if (previousInjector) {
// We still have a parent injector, keep throwing
throw error;
} else {
// Format & throw the final error message when we don't have any previous injector
throw augmentRuntimeError(error, this.source);
}

try {
if (record.value === CIRCULAR) {
throw cyclicDependencyError(stringify(token));
throw cyclicDependencyError(ngDevMode ? stringify(token) : '');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a similar case here; the value is only used for dev mode.

export function cyclicDependencyError(token: string, path?: string[]): Error {
const message = ngDevMode ? `Circular dependency detected for \`${token}\`.` : '';
return createRuntimeError(message, RuntimeErrorCode.CYCLIC_DI_DEPENDENCY, path);
}

(<any>forwardRefFn).__forward_ref__ = forwardRef;
(<any>forwardRefFn).toString = function () {
return stringify(this());
return ngDevMode ? stringify(this()) : '';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’d only have a question in the case of toString. From what I reviewed, I couldn’t find any usage other than a possible development-time debug scenario.
Would this be necessary, similar to R3Injector, if we want to remove the stringify function from the final bundle

Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of return an empty string here.
If we were to drop that custom implem, I would rather wrap it entirely with a if(ngDevMode) { ... }.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated both cases. Also, in R3Injector, I adding // @ts-ignore to suppress specific TypeScript warning

return `R3Injector[${tokens.join(', ')}]`;
}
return `R3Injector[${tokens.join(', ')}]`;
}
Copy link
Member

Choose a reason for hiding this comment

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

We still have an issue here as toString will return undefined.
I think its's reasonable to return something like R3Injector[...]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in this case should be enough return 'R3Injector[...] wdyt ?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's what I had in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Issues related to the framework runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants