Skip to content

Attachment support for svelte 5.29+ - #185

Open
SteelAlloy wants to merge 2 commits into
ghostdevv:mainfrom
SteelAlloy:main
Open

SteelAlloy wants to merge 2 commits into
ghostdevv:mainfrom
SteelAlloy:main

Conversation

@SteelAlloy

Copy link
Copy Markdown

Hi!

With the release of Svelte 5.29, svelte-copy can now be used through the new attachment API, including on components.

The Svelte documentation recommends attachments over actions where possible:

In Svelte 5.29 and newer, consider using attachments instead, as they are more flexible and composable.

— Svelte documentation: use:

A consumer can already use svelte-copy as an attachment via the fromAction helper:

<script>
  import { copy } from 'svelte-copy';
  import { fromAction } from 'svelte/attachments';
</script>

<button {@attach fromAction(copy, () => 'Hello World')}>
  Copy
</button>

However, I think it would be useful for this library to expose a first-class attachment API directly, rather than requiring every consumer to wrap the action with fromAction.

Potential breaking change

In this MR, I renamed the existing copy action to copyAction and made copy the attachment export.

<script>
  import { copy } from 'svelte-copy';
</script>

<button {@attach copy('Hello World')}>
  Copy
</button>

I chose this naming because copyAttachment felt unnecessarily verbose, while copy is the most natural name for the primary API going forward. Actions would remain available as copyAction for backward compatibility and existing codebases.

That said, I understand that renaming the existing copy export could be considered too disruptive. If maintaining the current copy action export is preferred, we can instead expose the attachment under a separate name. Naming suggestions are welcome.

Documentation

The documentation has been updated accordingly:

  • Attachment examples are presented first.
  • Existing action examples are still included, but presented as the legacy/compatibility approach.

This branch has not been deployed

No deployments
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.

1 participant