Skip to content
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

fix(ivy): don't project removed placeholders with runtime i18n #30783

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/core/src/render3/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {attachI18nOpCodesDebug} from './instructions/lview_debug';
import {allocExpando, elementPropertyInternal, getOrCreateTNode, setInputsForProperty} from './instructions/shared';
import {LContainer, NATIVE} from './interfaces/container';
import {COMMENT_MARKER, ELEMENT_MARKER, I18nMutateOpCode, I18nMutateOpCodes, I18nUpdateOpCode, I18nUpdateOpCodes, IcuType, TI18n, TIcu} from './interfaces/i18n';
import {TElementNode, TIcuContainerNode, TNode, TNodeType, TProjectionNode} from './interfaces/node';
import {TElementNode, TIcuContainerNode, TNode, TNodeFlags, TNodeType, TProjectionNode} from './interfaces/node';
import {RComment, RElement, RText} from './interfaces/renderer';
import {SanitizerFn} from './interfaces/sanitization';
import {StylingContext} from './interfaces/styling';
Expand Down Expand Up @@ -910,6 +910,8 @@ function removeNode(index: number, viewData: LView) {
}
}

// Define this node as detached so that we don't risk projecting it
removedPhTNode.flags |= TNodeFlags.isDetached;
ngDevMode && ngDevMode.rendererRemoveNode++;
}

Expand Down
13 changes: 8 additions & 5 deletions packages/core/src/render3/interfaces/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,22 @@ export const enum TNodeType {
*/
export const enum TNodeFlags {
/** This bit is set if the node is a component */
isComponent = 0b00001,
isComponent = 0b000001,

/** This bit is set if the node has been projected */
isProjected = 0b00010,
isProjected = 0b000010,

/** This bit is set if any directive on this node has content queries */
hasContentQuery = 0b00100,
hasContentQuery = 0b000100,

/** This bit is set if the node has any "class" inputs */
hasClassInput = 0b01000,
hasClassInput = 0b001000,

/** This bit is set if the node has any "style" inputs */
hasStyleInput = 0b10000,
hasStyleInput = 0b010000,

/** This bit is set if the node has been detached by i18n */
isDetached = 0b100000,
}

/**
Expand Down
20 changes: 11 additions & 9 deletions packages/core/src/render3/node_manipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,15 +784,17 @@ export function appendProjectedNodes(
appendChild(nodeToProject, tProjectionNode, lView);
} else {
while (nodeToProject) {
if (nodeToProject.type === TNodeType.Projection) {
appendProjectedNodes(
lView, tProjectionNode, (nodeToProject as TProjectionNode).projection,
findComponentView(projectedView));
} else {
// This flag must be set now or we won't know that this node is projected
// if the nodes are inserted into a container later.
nodeToProject.flags |= TNodeFlags.isProjected;
appendProjectedNode(nodeToProject, tProjectionNode, lView, projectedView);
if (!(nodeToProject.flags & TNodeFlags.isDetached)) {
if (nodeToProject.type === TNodeType.Projection) {
appendProjectedNodes(
lView, tProjectionNode, (nodeToProject as TProjectionNode).projection,
findComponentView(projectedView));
} else {
// This flag must be set now or we won't know that this node is projected
// if the nodes are inserted into a container later.
nodeToProject.flags |= TNodeFlags.isProjected;
appendProjectedNode(nodeToProject, tProjectionNode, lView, projectedView);
}
}
nodeToProject = nodeToProject.projectionNext;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/core/test/acceptance/i18n_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,7 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => {
.toEqual('<child><grand-child><div><b>Bonjour</b> monde!</div></grand-child></child>');
});

// FW-1319 Runtime i18n should be able to remove projected placeholders
xit('should be able to remove projected placeholders', () => {
it('should be able to remove projected placeholders', () => {
mhevery marked this conversation as resolved.
Show resolved Hide resolved
@Component({selector: 'grand-child', template: '<div><ng-content></ng-content></div>'})
class GrandChild {
}
Expand Down