fix: check if content layer files have changed before writing#12962
Merged
fix: check if content layer files have changed before writing#12962
Conversation
🦋 Changeset detectedLatest commit: d3e91ec The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
CodSpeed Performance ReportMerging #12962 will not alter performanceComparing Summary
|
florian-lefebvre
approved these changes
Jan 10, 2025
bluwy
approved these changes
Jan 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
When data has changed in the content layer, the data store needs to write several different files, including the data store itself, asset imports (e.g. images) and module imports (e.g. mdx). These are all in the module graph, so will trigger HMR if changed. #12751 reported that when editing MDX it would reload twice, and the second time would take a long time for large sites. The double reload was because there was initially HMR from the changed MDX module itself. The slow second reload was because it was writing the big imports file itself too, causing Vite to re-parse the whole big graph. This isn't needed, because the imports file itself hasn't changed, just the file it was referring to.
This PR changes the write function to first check the old file content before writing, and skip if it is unchanged.
This does not stop the double-reload in the example. The first update is instant, and is the HMR for the mdx module itself. The second is a full refresh, which is triggered by the data store changing. This in unavoidable, because the data has changed, and may need a full page refresh because we don't know how it's been used. What has been fixed though is that this is much faster, because the big imports file has not been invalidated so I'm going to count this as a fix.
Fixes #12751
Testing
Docs