#Help with an issue (#7317) re markdoc tags, content collections, and getEntry()

13 messages · Page 1 of 1 (latest)

vestal birch
#

Hey folks! Hope to get some help with this weird issue. (FYI it won't make too much sense without looking at the linked github issue).

I've detailed a unique case here https://github.com/withastro/astro/issues/7317 where invoking an Astro component via a custom tag runs into issues with getEntry() and getEntryBySlug(). As explained in the OP of the issue, this only happens with a combination of factors involving content collections.

@vale sentinel intrepidly found that the issue was arising out of a memory issue in Vite, and suggested a workaround (https://github.com/withastro/astro/issues/7317#issuecomment-1581230856). It involves passing the function getEntry() inside a variable.

The workaround works fine when using the component as a custom Astro tag. I'd like to also invoke the component from ordinary Astro files as well, and that means having to use the same workaround—passing getEntry() into Astro.props inside an attribute, even though getEntry() is perfectly available to an ordinary Astro file. That gets annoying when having to keep passing it from endpoint to layout to component, to subcomponent, etc.

Here's a stackblitz that shows the complications the workaround causes: https://stackblitz.com/edit/github-pq3pgo-j623al?file=src%2Fpages%2F[...slug].astro

I'd like to just use the same component in both cases (Astro file and markdoc tag).

If anyone has any suggestions, I'd be very grateful!

GitHub

What version of astro are you using? 2.6.0 Are you using an SSR adapter? If so, which one? None What package manager are you using? pnpm What operating system are you using? Mac What browser are yo...

exploring complications arising from using workaround with Astro files invoking the same component

cobalt roseBOT
#
No-one around right now?

It looks like no-one has responded to your question yet. People might not be available right now or don’t know how to answer your question. Want an answer while you wait? Try asking our experimental bot in #1095492539085230272.

vale sentinel
#

Hey there! Yes, I've spent some more hours this week... and no, I don't have a great answer 😕

#

I'm working on a more fundamental change to how the Markdoc config works to see if that fixes it. It's a change that'll unlock features like Markdoc in our Starlight template, so I've been meaning to work on this anyways. Hope it also solves this issue

#

Chance it won't, so bear with me

vestal birch
#

Absolutely, I know it's a minor bug and I really appreciate that it's on your radar anyway! Thanks for the update 🥳

vale sentinel
#

Holy crap... I think I've done it starlight_spin

#

I'm playing with a new pipeline that requires you pass the component path in your config, instead of importing directly. Something like this:

import { defineMarkdocConfig, component } from '@astrojs/markdoc/config';

export default defineMarkdocConfig({
    tags: {
        aside: {
            render: component('./src/components/Aside.astro'),
            attributes: {
                type: { type: String },
                title: { type: String },
            },
        },
});

By just passing the name, we can be a lot smarter about inserting component imports in the right place for style and script bundling

#

Tested against your repro and no more build errors with this change 🥳

#

Gonna take some time to refine the API, document, and PR review, so be patient! But I'm feeling more confident in this change now.

vestal birch
#

Woo hoo! Thank you so much! I think I hear you implying that this might be useful for more than just my peculiar case, and if so, I'm glad!

#

Happy to be patient 🙂

vale sentinel