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

allow import server action in client side #403

Closed
himself65 opened this issue Jan 20, 2024 · 6 comments · Fixed by #714
Closed

allow import server action in client side #403

himself65 opened this issue Jan 20, 2024 · 6 comments · Fixed by #714
Assignees

Comments

@himself65
Copy link
Contributor

himself65 commented Jan 20, 2024

See https://github.com/himself65/waku-openai/tree/issue-2

cp .env.template .env
pnpm run dev

Error:

TypeError: Cannot read properties of undefined (reading 'A')
image
"use client"
import { useFormState } from "react-dom"
import { generateResponse } from '../actions/chat.js'

export function Client () {
  const [state, dispatch] = useFormState(
    generateResponse,
    null
  )
  return (
    <div>
      {state}
      <button
        onClick={() => {
          dispatch()
        }}
      >
        Generate Response
      </button>
    </div>
  )
}

chat.tsx:

'use server'
import { getEnv } from 'waku'

const apiKey = getEnv('A')!

export async function generateResponse () {
  return `apiKey: ${apiKey}`
}

.env.local:

A=Hello
@dai-shi
Copy link
Owner

dai-shi commented Jan 20, 2024

This is simply not supported. You need to pass the server reference from a server component to a client component. "use server" in a function isn't supported either.

To support it, we would need to write a custom client bundler. (We don't have one, and use Vite as is.)

@himself65
Copy link
Contributor Author

@himself65
Copy link
Contributor Author

OK, my mistake, they have prebuild script for such feature. Let me try if we can do the same thing in waku https://github.com/rauchg/react-postgres-components/tree/main/build

@himself65 himself65 changed the title server action run in the client side rpc call in the client side Jan 20, 2024
@himself65
Copy link
Contributor Author

Closing as this not waku issue

@himself65 himself65 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 20, 2024
@himself65
Copy link
Contributor Author

Reopen this, as this is like what we will support

@himself65 himself65 reopened this Feb 28, 2024
@dai-shi
Copy link
Owner

dai-shi commented Feb 28, 2024

we may try it for v0.21.0, but no guarantee.

@dai-shi dai-shi self-assigned this Feb 28, 2024
@himself65 himself65 changed the title rpc call in the client side allow import server action in client side Feb 28, 2024
@dai-shi dai-shi mentioned this issue Mar 1, 2024
dai-shi added a commit that referenced this issue May 21, 2024
close #403

- [x] dev
- [x] prd

Remaining
- refactor
- tests
- docs
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 a pull request may close this issue.

2 participants