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

Improve MDX glob perf - move Layout to async import #4428

Merged
merged 3 commits into from
Aug 22, 2022
Merged

Conversation

bholmesdev
Copy link
Contributor

Changes

Wait, why an async import?

We found some interesting import.meta.glob behavior in the dev server after #4255 was introduced.

Scenario: a directory of MDX files use the same layout in their frontmatter. This layout includes an Astro.glob call for that same directory of MDX files. This is common when generating a "what to read next" section, navigation, etc.

  • Before: When editing a single MDX file imported by the layout glob, only that file is re-transformed by Vite. All other globbed files will come from cache. This means near-instant dev server feedback (ignoring initial startup time).
  • After: When editing a single MDX file imported by the layout glob, all globbed files are re-transformed by Vite. This could mean a 5-10 sec delay for every change in a project with 200ish MDX files.

I discovered that moving the frontmatter layout from an asynchronous import to a synchronous one introduced this issue. Recursion is to blame here: layout -> glob -> posts, which import -> layout -> glob -> posts, which import -> layout -> glob...

Testing

N/A

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Aug 22, 2022

🦋 Changeset detected

Latest commit: 8fc7469

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@astrojs/mdx Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/svelte-component Patch

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: integration Related to any renderer integration (scope) label Aug 22, 2022
Copy link
Member

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with 1 comment to document

@bholmesdev bholmesdev merged commit a2414bf into main Aug 22, 2022
@bholmesdev bholmesdev deleted the fix/mdx-glob-perf branch August 22, 2022 22:18
@astrobot-houston astrobot-houston mentioned this pull request Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: integration Related to any renderer integration (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slow DX with @astrojs/mdx 0.9.0 (not 0.8.1)
2 participants