-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
refactor: update schematics to work with new UpdateBuffer #26504
Conversation
This change is needed for the upcoming changes in Angular CLI version 16 where the default `UpdateBuffer` is replaced with the `UpdateBuffer2`. This commits changes how certain updates are applied to avoid overlapping changes which would otherwise result in broken output due to the offset would be out of sync.
This commit adds a new step in CI to tests schematics using the `UpdateBuffer2` which will be the default and only `UpdateBuffer` in Angular CLI vertsion 16.
Is there a little more context on why this previously worked? The old update recorder always worked even if updates are applied not necessarily in reverse order. Just asking for better understanding. |
It works because of a bug which was leveraged in this case. We now switched to For context here is the bug that was levraged const buffer = Buffer.from('Hello beautiful World');
//Old
const recorder = new UpdateBuffer(buffer);
recorder.remove(0, 5);
recorder.insertRight(0, Buffer.from('Hola amazing'));
recorder.remove(0, 5);
recorder.insertRight(0, Buffer.from(' and fantastic'));
recorder.toString() // Hola amazing and fantastic beautiful World
// New
const recorder2 = new UpdateBuffer2(buffer);
recorder2.remove(0, 5);
recorder2.insertRight(0, Buffer.from('Hola amazing'));
recorder2.remove(0, 5);
recorder2.insertRight(0, Buffer.from(' and fantastic'));
recorder2.toString() // and fantastic beautiful World
|
Note: this reverse "trick" is not something new as it's used in other places
|
Yeah, we did it a couple of times, but also quite a few migrations (especially older ones) did not follow that pattern because the update recorder was assumed to intentionally handle this out of the box, only ever considering the original source indices. I will need to experiment a bit to get a better understanding |
There is definitely something weird with this migration though as there was an attempt to correct the node positions before as well which is odd. |
Yeah, those are not ideal. I'm good with this change anyway. I like the fact that magic-string is used under the hood. I just want to make sure we document the semantic changes well when Angular CLI releases. Arguably, the behavior you outlined in #26504 (comment) seemed expected to me and also reasonable to me. i.e. remove always operates on the original string indices. This makes a lot of sense. Going forward the way |
Yeah that is indeed a confusing behaviour especially considering that docs state otherwise. |
* refactor: update schematics to work with new UpdateBuffer This change is needed for the upcoming changes in Angular CLI version 16 where the default `UpdateBuffer` is replaced with the `UpdateBuffer2`. This commits changes how certain updates are applied to avoid overlapping changes which would otherwise result in broken output due to the offset would be out of sync. * ci: add test step to test schematics with `UpdateBuffer2` This commit adds a new step in CI to tests schematics using the `UpdateBuffer2` which will be the default and only `UpdateBuffer` in Angular CLI vertsion 16. (cherry picked from commit c4414ad)
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This change is needed for the upcoming changes in Angular CLI version 16 where the default
UpdateBuffer
is replaced with theUpdateBuffer2
.This commits changes how certain updates are applied to avoid overlapping changes which would otherwise result in broken output due to the offset would be out of sync.