Skip to content

fix(svelte): add missing components-manifest prop#183

Merged
farnabaz merged 12 commits into
mainfrom
feat/svelte-component-manifest
May 20, 2026
Merged

fix(svelte): add missing components-manifest prop#183
farnabaz merged 12 commits into
mainfrom
feat/svelte-component-manifest

Conversation

@atinux

@atinux atinux commented May 6, 2026

Copy link
Copy Markdown
Contributor

🔗 Linked issue

resolves #177

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)

📚 Description

We did not have the components-manifest prop on Svelte's comark components.

This PR aims to add them, but my lack of knowledge on Svelte makes me unconfortable right now, I would love a review from @elliott-with-the-longest-name-on-github first 🙏

Maybe @Serator as well?

📝 Checklist

  • I have linked an issue or discussion.
  • I have run pnpm verify and it passes.
  • I have updated the documentation accordingly.

@vercel

vercel Bot commented May 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
comark Ready Ready Preview May 20, 2026 11:04am
comark-json-render Ready Ready Preview May 20, 2026 11:04am
comark-nextjs Ready Ready Preview May 20, 2026 11:04am
comark-nuxt Ready Ready Preview May 20, 2026 11:04am
comark-svelte Ready Ready Preview May 20, 2026 11:04am
comark-twoslash Ready Ready Preview May 20, 2026 11:04am
comark-vue Ready Ready Preview May 20, 2026 11:04am

@pkg-pr-new

pkg-pr-new Bot commented May 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

comark

npm i https://pkg.pr.new/comark@183

@comark/ansi

npm i https://pkg.pr.new/@comark/ansi@183

@comark/html

npm i https://pkg.pr.new/@comark/html@183

@comark/nuxt

npm i https://pkg.pr.new/@comark/nuxt@183

@comark/react

npm i https://pkg.pr.new/@comark/react@183

@comark/svelte

npm i https://pkg.pr.new/@comark/svelte@183

@comark/vue

npm i https://pkg.pr.new/@comark/vue@183

commit: 91bde62

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm out of town until Monday but I do know that at least as is current, the import.meta.glob example does not lazily load components (unless something has changed on the Vite end). import.meta.glob basically performs a buildtime lookup of all available files and inlines them as imports into the file.

I'll take a better look at this on Monday!

@atinux

atinux commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

@elliott-with-the-longest-name-on-github actually the eager: true strategy make sure to not lazy-load the chunks, see https://vite.dev/guide/features#glob-import

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, just one nit and one slightly more substantial change to support experimental async

Comment thread packages/comark-svelte/src/components/ComarkNode.svelte Outdated
Comment thread packages/comark-svelte/src/components/ComarkNode.svelte Outdated
@Serator

Serator commented May 17, 2026

Copy link
Copy Markdown

Hey @atinux. I don't know how it happened, but I missed the notification. 🤷 @elliott-with-the-longest-name-on-github has already mentioned import.meta.glob earlier. import.meta.glob(‘./components/*.svelte’, {eager: true}) will cause all components under the specified path to be loaded; in other words, they will be included in the final bundle even if they are not used. I tried your PR in SSG mode, and in my case, that's exactly how it is.

A few words about my case:

I have some Markdown pages, some of which contain custom widgets. I'd like to be able to store these widgets directly in the pages' directories and load them during the build (SSG). Something like:

...

![Some widget](./SomeWidget/index.svelte)

...

(The path to the widget may or may not be unique)

With import.meta.glob, I would have to specify the path in advance (In fact, you cannot use variables in it, as is done in the example with the current documentation), which completely defeats the purpose of loading the component on demand (in my case).

Co-authored-by: Elliott Johnson <hello@ell.iott.dev>
@atinux

atinux commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

@Serator you don't need to use import.meta.glob but directly from the page where you need to lazy-load the components that will be rendered in your Markdown to create your componentsMap:

<script lang="ts">
  import { ComarkAsync } from '@comark/svelte/async'
  import type { PageData } from './$types'

  let { data }: { data: PageData } = $props()

  const componentMap: Record<string, () => Promise<any>> = {
    'alert': () => import('$lib/components/Alert.svelte'),
    'card': () => import('$lib/components/Card.svelte'),
  }

  const componentsManifest = (name: string) => componentMap[name]?.()
</script>

<article>
  <ComarkAsync markdown={data.markdown} {componentsManifest} />
</article>

See https://comark.dev/examples/frameworks/sveltekit

@farnabaz farnabaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

@farnabaz
farnabaz merged commit c78885c into main May 20, 2026
10 checks passed
@farnabaz
farnabaz deleted the feat/svelte-component-manifest branch May 20, 2026 11:21
@atinux atinux mentioned this pull request May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

componentsManifest is missing in @comark/svelte

5 participants