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

[Bug?]: use server works only if start: { ssr: false } is set #1186

Closed
2 tasks done
leaysgur opened this issue Dec 27, 2023 · 3 comments · Fixed by #1188
Closed
2 tasks done

[Bug?]: use server works only if start: { ssr: false } is set #1186

leaysgur opened this issue Dec 27, 2023 · 3 comments · Fixed by #1188
Labels
bug Something isn't working

Comments

@leaysgur
Copy link
Contributor

leaysgur commented Dec 27, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Call server function like

import { createSignal } from "solid-js";

const serverFn = async () => {
  "use server";
  return ["Hello", "from", "server"];
};

export default function App() {
  const [messages, setMessages] = createSignal(["Not", "ready", "yet"]);

  const fetchMessages = async () => {
    setMessages(["Loading", "..."]);
    serverFn()
      .then((d) => setMessages(d))
      .catch((e) => setMessages(["Error:", e.message]));
  };

  return (
    <main>
      <h1>Test Server Function!</h1>
      <button class="increment" onClick={fetchMessages}>
        Fetch
      </button>
      <pre>{JSON.stringify(messages())}</pre>
    </main>
  );
}

ends up with

Error: $R is not defined

It seems POST /_server returns response with ($R["server-fn:0"]=[],($R=>$R[0]=["Hello","from","server"])($R["server-fn:0"])); w/ status code 200.

Expected behavior 🤔

Error should not be thrown.

If start: { ssr: false } is set in vite.config.js(= Select SSR ? No at create-solid), it works without error.

Steps to reproduce 🕹

Steps:

  1. npm init solid@latest
  2. Select SSR ? Yes / TypeScript ? No / Template ? Bare
  3. Update src/app.jsx like above and npm run dev
  4. Click button

Context 🔦

No response

Your environment 🌎

"@solidjs/start": "^0.4.2",
"solid-js": "^1.8.7",
"vinxi": "0.0.54"

Node.js v21.2.0
@leaysgur leaysgur added the bug Something isn't working label Dec 27, 2023
@leaysgur leaysgur mentioned this issue Dec 27, 2023
10 tasks
@lxsmnsyc
Copy link
Member

hmmm weird, I thought we fixed this

@lxsmnsyc
Copy link
Member

lxsmnsyc commented Dec 27, 2023

Can I ask what does your initial server html look like? Solid (not Start) should automatically declare $R here

edit:
found the issue

@leaysgur
Copy link
Contributor Author

Thank you for the fix! 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants