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 template migration issues #14600

Merged
merged 6 commits into from
Oct 8, 2024
Merged

Conversation

philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Oct 4, 2024

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.

): Promise<{ rawCandidate: string; start: number; end: number }[]> {
let scanner = new Scanner({})
let result = scanner.getCandidatesWithPositions({ content, extension: 'html' })
let result = scanner.getCandidatesWithPositions({ content, extension })
Copy link
Member Author

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

Copy link
Member Author

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 🤔

Copy link
Contributor

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.

Copy link
Member Author

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.

@philipp-spiess philipp-spiess force-pushed the fix/fix-template-migration-issues branch from a79a96e to cd5f389 Compare October 4, 2024 15:55
@philipp-spiess philipp-spiess force-pushed the fix/fix-template-migration-issues branch from cd5f389 to 9ba6a8d Compare October 7, 2024 10:11
@philipp-spiess philipp-spiess marked this pull request as ready for review October 7, 2024 11:00
@philipp-spiess philipp-spiess force-pushed the fix/fix-template-migration-issues branch from 1296b04 to 1936261 Compare October 8, 2024 09:59
@philipp-spiess philipp-spiess force-pushed the fix/fix-template-migration-issues branch from 788c380 to 43fe42b Compare October 8, 2024 13:39
CHANGELOG.md Outdated Show resolved Hide resolved
@philipp-spiess philipp-spiess merged commit 1467dab into next Oct 8, 2024
1 check passed
@philipp-spiess philipp-spiess deleted the fix/fix-template-migration-issues branch October 8, 2024 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants