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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃悰 BUG: Astro.fetchContent causes circular dependency when used with fetched content #1247
Comments
I think the problem is that fetchContent returns Maybe this is a good case for @natemoo-re's idea of allowing user interfaces to augment the shape of data returned, so maybe you could opt out of the html being passed to you? interface NoHTML {/** ... */};
const posts = Astro.fetch<NoHTML>("**/*.md"); |
Deleted a previous comment I know realize was wrong. The underlying issue here is that That means that this is actually a bug in snowpack, which I guess should be filtering out imports of itself. I have a feeling that the new compiler will be required to see this one fixed. |
@matthewp, is this now resolved in the new compiler? |
Seems not. I just ran into this. (v0.22.15) Especially devious... it works in development, but not when you build. |
I've seen similar issues pop up a few times and it always seems to come down to Three possible solutions (maybe there's more?):
|
This is avoidable, for sure, in many cases. But sometimes the only reason you'd need to use JS is to avoid this problem. In my case, I've got a nav menu that is totally dynamically built based off of files in the
I like this idea quite a lot: it would work well in the case I laid out above. |
I'm going to close this one as "Won't fix", but not because it isn't a use case worth solving! This really is a limitation of how I just opened an RFC discussion to start the conversation to come up with the right solution for this. The use case of needing to know what pages will be built for navigation menus, sidebars, etc. is really common - please feel free to jump into the RFC discussion to share any ideas, concerns, or examples you'd like to see supported here! |
What package manager are you using?
npm
What operating system are you using?
Mac
Describe the Bug
I started with Astro's built-in blog starter for a small blog. From there, I wanted to add a Sidebar component that uses
Astro.fetchContent
to pull in a list of all blog posts.However, it seems that when viewing one of the blog posts (let's say,
post.md
), fetching all posts withAstro.fetchContent
creates a circular dependency error in the console.I've created a repo with the minimum conditions to reproduce here. Here's the specific error message:
Ideally, it would be nice to be able to load an MD file while also viewing that MD file; it's very conceivable that a user would perhaps want a sidebar with a listing of all posts on a post view page.
Steps to Reproduce
Clone this repo and run
npm i
followed bynpm run dev
.The only changes from the default blog starter template are:
Sidebar.astro
componentBlogPost
layoutLink to Minimal Reproducible Example (Optional)
https://github.com/josh-collinsworth/astro-circular-dependency-demo
The text was updated successfully, but these errors were encountered: