metonym / svelte-time

Svelte component and action to format a timestamp using day.js
https://metonym.github.io/svelte-time
MIT License
137 stars 8 forks source link

Cannot use `$$restProps` in runes mode (Svelte 5) #48

Open kvangrae opened 3 weeks ago

kvangrae commented 3 weeks ago

When using svelte-time as a dependency in my project and compiling in runes mode using Svelte 5:

svelte.config.js

export default {
    compilerOptions: {
        runes: true
    }
};

I get the following error:

✘ [ERROR] node_modules/svelte-time/Time.svelte:65:18 Cannot use `$$restProps` in runes mode [plugin vite-plugin-svelte:optimize-svelte]                                                                 

    node_modules/svelte-time/Time.svelte:65:18:                                                                                                                                                         
      65 │ time {title} {...$$restProps} datetime={timestamp}>                                                                                                                                          
         ╵                   ^                                                                                                                                                                          

  The plugin "vite-plugin-svelte:optimize-svelte" was triggered by this import                                                                                                                          

    node_modules/svelte-time/index.js:3:24:                                                                                                                                                             
      3 │ export { default } from "./Time.svelte";                                                                                                                                                      
        ╵                         ~~~~~~~~~~~~~~~                                                                                                                                                       

This is a limitation for other projects that are using Svelte 5 and runes.

kvangrae commented 3 weeks ago

When upgrading to support Svelte 5 and runes, you can replace $$restProps with $props.

Example:

<script>
    ...
    const props = $props();
    ...
</script>

<time {title} {...props} datetime={timestamp}>
    {formatted}
</time>