Skip to content
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

Waku community adapter #848

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

rmarscher
Copy link

No description provided.

Copy link

vercel bot commented Jan 6, 2025

@rmarscher is attempting to deploy a commit to the 47ng Team on Vercel.

A member of the Team first needs to authorize it.

@rmarscher
Copy link
Author

Backlink - dai-shi/waku#1123

It works with SSR if the Waku parent component render setting is "dynamic".

I want to see what we can do on the server / RSC side of things. I think this is only a client and SSR implementation so far.

@rmarscher rmarscher force-pushed the feat/waku-community-adapter branch from 8261402 to e112093 Compare January 6, 2025 04:56
@rmarscher
Copy link
Author

Ha. It totally works with RSC! I updated the adapter to support the scroll and shallow options.

Fun demo: https://waku-nuqs.martiandev.workers.dev/

@franky47 franky47 added the adapters/community Custom community-provided adapters label Jan 6, 2025
Copy link

vercel bot commented Jan 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nuqs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 8:30pm

@franky47 franky47 added this to the 🪵 Backlog milestone Jan 6, 2025
@franky47 franky47 added the documentation Improvements or additions to documentation label Jan 6, 2025
@rmarscher rmarscher marked this pull request as ready for review January 6, 2025 14:43
packages/docs/content/docs/community-adapters/waku.mdx Outdated Show resolved Hide resolved
import { useRouter_UNSTABLE as useRouter } from "waku";

export function renderURL(base: string, search: URLSearchParams) {
const hashlessBase = base.split("#")[0] ?? "";
Copy link
Member

Choose a reason for hiding this comment

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

note: Based on usage here, the base parameter would never contain a hash part (it's fed location.origin + location.pathname).

Copy link
Author

Choose a reason for hiding this comment

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

Ah yeah, thanks. I simplified that. Waku's useRouter returns the current path, so I also added using that. We can preserve the hash when it goes through RSC. I updated the adapter to do that. I think including location.origin isn't necessary so I dropped it.

const searchParams = new URLSearchParams(query);
const updateUrl = (search: URLSearchParams, options: AdapterOptions) => {
const query = renderQueryString(search);
const hash = typeof location !== "undefined" ? location.hash : "";
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean this can be called on the server somehow?

useQueryState(s) are client-side hooks, that can render on the server in an SSR pass, but the state updater function should only be called client-side.

Copy link
Author

Choose a reason for hiding this comment

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

OK, great. I assumed that was probably case, but the guard seemed to be safe just in case it was somehow run in an environment without a location global. I'll take it out.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@rmarscher rmarscher force-pushed the feat/waku-community-adapter branch from 91909fc to acf8a27 Compare January 12, 2025 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters/community Custom community-provided adapters documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants