Skip to content

fix(migrations): resolve text replacement issue#59452

Closed
crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto:migration-insert-left
Closed

fix(migrations): resolve text replacement issue#59452
crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto:migration-insert-left

Conversation

@crisbeto
Copy link
Copy Markdown
Member

@crisbeto crisbeto commented Jan 9, 2025

Based on #59353 (comment), fixes a text replacement issue that seems to cause code to be duplicated in some setups.

Based on angular#59353 (comment), fixes a text replacement issue that seems to cause code to be duplicated in some setups.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: rc This PR is targeted for the next release-candidate labels Jan 9, 2025
@crisbeto crisbeto requested a review from devversion January 9, 2025 14:42
@angular-robot angular-robot bot added the area: migrations Issues related to `ng update`/`ng generate` migrations label Jan 9, 2025
@ngbot ngbot bot added this to the Backlog milestone Jan 9, 2025
recorder
.remove(c.data.position, c.data.end - c.data.position)
.insertLeft(c.data.position, c.data.toInsert);
.insertRight(c.data.position, c.data.toInsert);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@devversion I think that historically we were using insertRight for migrations, but the tsurge-based ones seem to lean towards insertLeft instead. Maybe we should switch all of them over?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm. I don't see why it would fix duplications. do you understand?

(not opposed changing; but sounds like it's dependent on the order of replacements rather?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm just speculating since I haven't been able to reproduce it (see #59353 (comment)), but we've had other weird text replacement issues after the CLI swapped out their string buffer implementation, especially if ranges end up overlapping. My thinking is that when we do insertLeft, the new text technically overlaps the range that was just deleted which is throwing it off. With insertRight it gets inserted after the removed range so it's fine.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So we got another report about this bug in #59466 and it has a reproduction. It's really weird, because I can reproduce the bug on my end and I can verify that the fix works, but I can't reproduce it in our testing setup. I have a feeling that some test-specific logic might be normalizing it.

Copy link
Copy Markdown
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

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

LGTM as I don't think this is a problem to merge, but I don't fully understand what would be best.

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 10, 2025
@kirjs
Copy link
Copy Markdown
Contributor

kirjs commented Jan 10, 2025

This PR was merged into the repository by commit 966a370.

The changes were merged into the following branches: main, 19.1.x

@kirjs kirjs closed this in 966a370 Jan 10, 2025
kirjs pushed a commit that referenced this pull request Jan 10, 2025
Based on #59353 (comment), fixes a text replacement issue that seems to cause code to be duplicated in some setups.

PR Close #59452
crisbeto added a commit to crisbeto/angular that referenced this pull request Jan 13, 2025
Adds a test for the fix from angular#59452 now that we know what caused the issue.
kirjs pushed a commit that referenced this pull request Jan 13, 2025
Adds a test for the fix from #59452 now that we know what caused the issue.

PR Close #59497
kirjs pushed a commit that referenced this pull request Jan 13, 2025
Adds a test for the fix from #59452 now that we know what caused the issue.

PR Close #59497
PrajaktaB27 pushed a commit to PrajaktaB27/angular that referenced this pull request Feb 7, 2025
Based on angular#59353 (comment), fixes a text replacement issue that seems to cause code to be duplicated in some setups.

PR Close angular#59452
PrajaktaB27 pushed a commit to PrajaktaB27/angular that referenced this pull request Feb 7, 2025
Adds a test for the fix from angular#59452 now that we know what caused the issue.

PR Close angular#59497
@angular-automatic-lock-bot
Copy link
Copy Markdown

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 Feb 11, 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: migrations Issues related to `ng update`/`ng generate` migrations target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants