-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 template migration issues #14600
Conversation
): Promise<{ rawCandidate: string; start: number; end: number }[]> { | ||
let scanner = new Scanner({}) | ||
let result = scanner.getCandidatesWithPositions({ content, extension: 'html' }) | ||
let result = scanner.getCandidatesWithPositions({ content, extension }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to myself: Let's try to see if we can find out why this emits duplicates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't really able to repro this in unit tests 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can chat about this some time today but I'd guess one of the routines we use to slice up a candidate into multiple candidates produces two identical entries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thecrypticace Sounds good yeah, I was trying to reproduce it inside Rust unit tests to no avail. I wonder if this has to do with the fact that we have two files in the repro—I have a feeling that there's some shared state but I didn't see anything that stood out.
a79a96e
to
cd5f389
Compare
cd5f389
to
9ba6a8d
Compare
1296b04
to
1936261
Compare
788c380
to
43fe42b
Compare
This PR fixes two issues we found when testing the candidate codemodes: 1. Sometimes, core would emit the same candidate twice. This would result into rewriting a range multiple times, without realizing that this change might already be applied, causing it to swallow or duplicate some bytes. 2. The codemods were mutating the `Candidate` object, however since the `Candidate` parsing is _cached_ in core, it would sometimes return the same instance. This is an issue especially since we monkey patch the prefix to `null` when migrating prefixed candidates. This means that a candidate would be cached that would be _invalid relative to the real design system_. We fixed this by making sure the mutations would only be applied to clones of the `Candidate` and I changed the `DesignSystem` API to return `ReadOnly<T>` versions of these candidates. A better solution would maybe be to disable the cache at all but this requires broader changes in Core.
This PR fixes two issues we found when testing the candidate codemodes:
Candidate
object, however since theCandidate
parsing is cached in core, it would sometimes return the same instance. This is an issue especially since we monkey patch the prefix tonull
when migrating prefixed candidates. This means that a candidate would be cached that would be invalid relative to the real design system. We fixed this by making sure the mutations would only be applied to clones of theCandidate
and I changed theDesignSystem
API to returnReadOnly<T>
versions of these candidates. A better solution would maybe be to disable the cache at all but this requires broader changes in Core.