-
Notifications
You must be signed in to change notification settings - Fork 5
Use clipboard wasm #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
src/hooks/clipboard_wasm.rs
Outdated
| /// // To get a handle to the clipboard | ||
| /// let mut clipboard = use_signal(|| None); | ||
| /// use_effect(move || clipboard.set(ClipboardWasm::new())); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/hooks/clipboard_wasm.rs
Outdated
|
|
||
| /// Handle to access the ClipboardContext. | ||
| /// | ||
| /// Use it through [use_clipboard]. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ..
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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..?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)]
There was a problem hiding this comment.
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,
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.
|
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 |
I added a feature to integrate clipboard for wasm