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

Shiki Theme Changes Not Reflected in Content Collection #12700

Closed
1 task
kirawat opened this issue Dec 9, 2024 · 5 comments · Fixed by #12984
Closed
1 task

Shiki Theme Changes Not Reflected in Content Collection #12700

kirawat opened this issue Dec 9, 2024 · 5 comments · Fixed by #12984
Labels
- P2: has workaround Bug, but has workaround (priority) feat: content collections Related to the Content Collections feature (scope)

Comments

@kirawat
Copy link

kirawat commented Dec 9, 2024

Astro Info

Astro                    v5.0.3
Node                     v22.12.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When changing the theme value within shikiConfig in the astro.config.mjs file, the Shiki theme updates correctly and instantly on Pages. However, the theme does not change for code blocks in posts generated from the Content Collection. Additionally, hot reload stops functioning for the Content Collection after modifying astro.config.mjs.

To Reproduce

  1. Create an Astro project with at least one Markdown post in the src/content directory.

  2. Add a code block to both a Page and a Markdown post.

  3. Configure Shiki in astro:config:mjs:

    export default defineConfig({
      markdown: {
        shikiConfig: {
          theme: 'github-dark', // Initially set to 'github-dark'
        },
      },
    });
  4. Start the development server (astro dev).

  5. Observe that the code blocks on both the Pages and the post use the github-dark theme.

  6. Change the theme value in astro.config.mjs to a different theme (e.g., github-light).

  7. Observe that the theme updates on the Page but not on the post.

  8. Make a change to the Markdown content of the post and save. Observe that hot reload does not reflect the changes.

What's the expected result?

The Shiki theme should update instantly on both Pages and Content Collection posts when the theme value in astro.config.mjs is changed. Hot reload should continue to function correctly for the Content Collection after modifying astro.config.mjs.

Workaround

Deleting the data-store.json file from the .astro directory and restarting the development server temporarily resolves the issue. Shiki themes then change correctly on all content, and hot reload functionality is restored.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-k8fzhwqy

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 9, 2024
@pdlug
Copy link

pdlug commented Dec 13, 2024

I can confirm this is a problem, got bit by it today.

@ematipico
Copy link
Member

Can you use the --force CLI option as a workaround?

@cworld1
Copy link

cworld1 commented Dec 15, 2024

I thought Astro will not plan to provide deep integration with Shiki. Don't realize it was a bug at all :(

@kirawat
Copy link
Author

kirawat commented Dec 16, 2024

Can you use the --force CLI option as a workaround?

Yes. Stop dev server and then run npm run astro dev --force after changed the theme in astro.config.mjs does successfully clear the content layer cache and forced a full rebuild.

Just have to do it every time when changes the theme in astro.config.mjs file.

@pdlug
Copy link

pdlug commented Dec 17, 2024

It's also misleading behavior, either needs to be fixed or noted in the docs.

@ascorbic ascorbic added - P2: has workaround Bug, but has workaround (priority) feat: content collections Related to the Content Collections feature (scope) and removed needs triage Issue needs to be triaged labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) feat: content collections Related to the Content Collections feature (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants