baseballyama / svelte-preprocess-delegate-events

You can delegate events by on:* πŸŽ‰
MIT License
51 stars 0 forks source link

Not working with multi "svelte:component" tag in same component file #120

Closed KiraPC closed 3 months ago

KiraPC commented 3 months ago

I'm trying to use this library with svelte4 and vitePreprocess but configuring the svelte.config.js as follow:

import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import delegateEvents from "svelte-preprocess-delegate-events/preprocess";

/** @type {import('@sveltejs/kit').Config} */
const config = {
    // Consult https://kit.svelte.dev/docs/integrations#preprocessors
    // for more information about preprocessors
    preprocess: [vitePreprocess({}), delegateEvents()],

I'm receiving a transform error:

Screenshot 2024-05-09 alle 11 16 39

What am I wrong?

baseballyama commented 3 months ago

Can you share minimal REPL and take a screenshot for showing error message?

baseballyama commented 3 months ago

I quickly try to use svelte-preprocess-delegate-events with latest SvelteKit and Svelte 4, but it works properly, so I think specific condition is needed. So could you please share me the REPL and error message?

KiraPC commented 3 months ago

@baseballyama Prepare a REPL is not possible now for me, I know that I'm asking a question but unfortunately I can't now, but maybe, this is a thing related to the fact that I'm using "on:*" on a svelte:component tag? Should it work also on this scenario?

KiraPC commented 3 months ago

@baseballyama I guess not. I've just modified your REPL here https://stackblitz.com/edit/sveltejs-kit-template-default-zkzqgi?file=src%2Flib%2Fui%2FComponentWrapper.svelte and a simil error appears.

baseballyama commented 3 months ago

@KiraPC Nice! Thank you for your REPL. I will fix it and make a new release! Please give me a few hours or a few days.πŸ™

KiraPC commented 3 months ago

@baseballyama No problem, thank for your work :)

baseballyama commented 3 months ago

@KiraPC

I checked it again but REPL uses svelte-preprocess-delegate-events 0.4.1. This is not latest version. After I upgrade to 0.4.3, it works well. Can you check it? (I noticed that when I wrote the test to submit a PR for thisπŸ˜…)

KiraPC commented 3 months ago

@baseballyama Ok found the issue. It is related to an if else statement.

So basically, when there is more then one "svelte:component" tag inside the same component

Here the error: https://stackblitz.com/edit/sveltejs-kit-template-default-ycquvy?file=src%2Flib%2Fui%2FComponentWrapper.svelte,src%2Flib%2Fui%2FComponent2.svelte&terminal=dev

baseballyama commented 3 months ago

@KiraPC 0.4.4 is released. Could you please confirm that this has been fixed?

KiraPC commented 3 months ago

@baseballyama Yeh now it seems working and events are correctly dispatched, but it seems is not generating the types from +[page|layout].server.ts files

baseballyama commented 3 months ago

@KiraPC

Yeh now it seems working and events are correctly dispatched

Nice!

it seems is not generating the types from +[page|layout].server.ts files

What do you mean? svelte-preprocess-delegate-events is preprocessor for .svelte files. Why +[page|layout].server.ts is relevant for this?

KiraPC commented 3 months ago

@baseballyama Ok, sorry, it was related to the added of

"include": ["./svelte-jsx.d.ts"]

to the tsconfig.json file