Skip to content

Comments

fix: check if content layer files have changed before writing#12962

Merged
ascorbic merged 1 commit intomainfrom
content-layer-file-check
Jan 10, 2025
Merged

fix: check if content layer files have changed before writing#12962
ascorbic merged 1 commit intomainfrom
content-layer-file-check

Conversation

@ascorbic
Copy link
Contributor

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

@changeset-bot
Copy link

changeset-bot bot commented Jan 10, 2025

🦋 Changeset detected

Latest 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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jan 10, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 10, 2025

CodSpeed Performance Report

Merging #12962 will not alter performance

Comparing content-layer-file-check (d3e91ec) with main (f00c2dd)

Summary

✅ 6 untouched benchmarks

@ascorbic ascorbic merged commit 4b7a2ce into main Jan 10, 2025
16 checks passed
@ascorbic ascorbic deleted the content-layer-file-check branch January 10, 2025 14:42
@astrobot-houston astrobot-houston mentioned this pull request Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate HMR reloads when using large collections

3 participants