Failed to apply Custom Components in Svelte 4/5 + SvelteKit 2 #691
Unanswered
ironkayman
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello! I can't seem to make Custom Compoenents' replacement work within an imported
.mdx
module as described in documentation. I am currently using SvelteKit 2 and have tried both Svelte 4 and Svelte 5:# svelte 4 @sveltejs/kit@2.5.28 mdsvex@0.12.3 remark@15.0.1 svelte-check@3.8.6 svelte-routing@2.13.0 svelte@4.2.19
The same behavior described below I am also observing in Svelte 5:
5.19.6
, to which I have migrated over the course of other elements of the project being updated, while being unable to resolve the issue in question myself:# svelte 5 @sveltejs/kit@2.16.1 mdsvex@0.12.3 remark@15.0.1 svelte-check@4.1.4 svelte-routing@2.13.0 svelte@5.19.6
I have tried multiple ways to use an imported
.mdx
component with a prior established layout configuration (see below):src/routes/.../+page.svelte
(usage variant 1):src/routes/.../+page.svelte
(usage variant 2):src/routes/.../+page.svelte
(usage variant 3):With none of those variants so far I managed to make Custom Components work. As I understand, there had been some changes in the naming convention of layouts across svelte and sveltekit:
__layout.svelte
is used in earlier versions of SvelteKit+layout.svelte
is used in the latest versions of SvelteKitlayout.svelte
is generally used in basic Svelte applications (non-SvelteKit)The reason I looked into it is due to inability to anyway import cusom components, as placing and renaming the layout does not seem to cause any components working:
src/routes/__layout.svelte
/src/routes/+layout.svelte
/src/routes/.../Layout.svelte
(naming from mdsvex docs, see below) /src/routes/.../+layout.svelte
:The last case (
src/routes/.../+layout.svelte
) also contains other logic, which works as intended, apart from the components, as they are not applied silently (no logs or errors on the dev console):The compoent in question, with which I want to replace a default link (tag
<a>
), -simple_link.svelte
, - is the dummy component from #292 (comment), I have also tried, just in case, other components wich also contain slots and only add a few wrapping html tags in order to chack if they are actually applied.I have tried the sveltekit layouts as above, and, based on #292 (reply in thread) attempted to use
src/routes/.../layout.svelte
andsrc/routes/.../Layout.svelte
, although I did not quite understand, weather it is mdsvex's own layout file or its just is Svelte's naming convention.Based on the custom components section -
exports from the context="module" script of your Layout file
, I understood that it is Svelte's and SvelteKit's layout file, but written in Svelte 3 and/or SvelteKit 1 paradigm:Svelte configuration in my project:
mdsvex.config.js
:svelte.config.js
:I had also tried applying solutions such as:
which also haven't resolved the issue in question.
My current workaround consists of preprocessing entirety of the project in 2 steps: pasting
<script>
with my components' imports and through regular expressions replace.mdx
syntax, such as links ([...](...)
), as sloted components. Of course, this is far from ideal, as more components had to be reimplimented through preprocessing/templating for separate svelte routes, wherein each implimentation of a component, for example, a link, varies.I understand, that this package greatly simplies the process of working with already nuanced specification of mdx. As far as I can see, I might be missing something very obvious regarding layout managements/routing within SvelteKit 2 ecosystem and its design patterns.
Creating this thread due to #292 being already answered, but not seemingly solving my issue.
Appreciate any help. Thank you.
Beta Was this translation helpful? Give feedback.
All reactions