Skip to content

Conversation

@cpt-n3mo
Copy link

I added a feature to integrate clipboard for wasm

@marc2332 marc2332 self-requested a review February 12, 2025 07:52
/// // To get a handle to the clipboard
/// let mut clipboard = use_signal(|| None);
/// use_effect(move || clipboard.set(ClipboardWasm::new()));

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change


/// Handle to access the ClipboardContext.
///
/// Use it through [use_clipboard].
Copy link
Member

Choose a reason for hiding this comment

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

/// Use it through [use_clipboard].
But it can't

Copy link
Member

Choose a reason for hiding this comment

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

Why didn't you integrate it in the existing hook? This just complicates things

Copy link
Author

@cpt-n3mo cpt-n3mo Feb 12, 2025

Choose a reason for hiding this comment

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

because it cant be used in the same way sadly.
web-sys exposes window but this is not available on the server, so it will panic the thread if you try to load it on the server. window does return a Option but it will will just panic if it cant find window,
so when doing SSR on first load it will panic, This is way it has to be used from a use_effect.
i could not find a way to check if we are on the server or client or in wasm for that matter,
i agree it would be match nicer to have it in the same hook, if you have any suggestions, on how to solve these problems, then i gladly change it ..

Copy link
Member

Choose a reason for hiding this comment

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

You should be able to just use #[cfg(target = etc)] no? Only downside is we would need to make the native functions also have an async

Copy link
Author

Choose a reason for hiding this comment

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

i will take a look if this will work.. and would making use_clipboard async not be a breaking change..?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I am actually not so sure that an always async version is a good idea... Do you have something else on mind?

Copy link
Author

Choose a reason for hiding this comment

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

if we can make it work with the last commit, async will not be needed on the other stuff. as it just returns a different use_clipboard for wasm targets. i cant seem to figure out how to make this work though, there is just not a real good way to check if we are on the server or client. i cant get it to work with #[cfg(target)]

Copy link
Author

Choose a reason for hiding this comment

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

it now works for client and desktop but not server......
i would say just discard the pull request,

@marc2332 marc2332 added the enhancement New feature or request label Feb 13, 2025
if you can find a way to make it work with the target then this should
be ok now. i cant get it to work on wasm32 targets this way.
I added a enum to select between desktop or wasm targets
this works for desktop and client now, it only fails on server
functions.

this does leave it all with a breaking change as now everything is
async.
@marc2332
Copy link
Member

The only thing that I just don't like is that native targets now have to use async mmm, maybe we could just make it async if a wasm-compat feature is enabled? Wdyt @cpt-n3mo ?

@marc2332 marc2332 mentioned this pull request Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants