Skip to content

Commit 6d3a870

Browse files
committed
fixes
1 parent ad6c458 commit 6d3a870

10 files changed

Lines changed: 40 additions & 34 deletions

File tree

apps/fixtures/hackernews/src/components/story.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Story: Component<{ story: StoryDefinition }> = props => {
1010
<span class="title">
1111
<Show
1212
when={props.story.url}
13-
fallback={<A href={`/item/${props.story.id}`}>{props.story.title}</A>}
13+
fallback={<A href={`/stories/${props.story.id}`}>{props.story.title}</A>}
1414
>
1515
<a href={props.story.url} target="_blank" rel="noreferrer">
1616
{props.story.title}

apps/fixtures/hackernews/src/lib/api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const mapStories = {
3737
export const getStories = query(
3838
async (type: StoryTypes, page: number): Promise<StoryDefinition[]> => {
3939
"use server";
40+
const storyType = mapStories[type];
41+
if (!storyType) {
42+
return [];
43+
}
4044
return fetchAPI(`${mapStories[type]}?page=${page}`);
4145
},
4246
"stories",

apps/fixtures/hackernews/src/routes/[...stories].tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createAsync, type RouteDefinition, type RouteSectionProps } from "@solidjs/router";
2-
import { For, Show } from "solid-js";
1+
import { A, type RouteDefinition, type RouteSectionProps } from "@solidjs/router";
2+
import { For, Show, createMemo } from "solid-js";
33
import Story from "~/components/story";
44
import { getStories } from "~/lib/api";
55
import { StoryTypes } from "~/types";
@@ -13,7 +13,7 @@ export const route = {
1313
export default function Stories(props: RouteSectionProps) {
1414
const page = () => +props.location.query.page || 1;
1515
const type = () => (props.params.stories || "top") as StoryTypes;
16-
const stories = createAsync(() => getStories(type(), page()));
16+
const stories = createMemo(() => getStories(type(), page()));
1717

1818
return (
1919
<div class="news-view">
@@ -26,9 +26,9 @@ export default function Stories(props: RouteSectionProps) {
2626
</span>
2727
}
2828
>
29-
<a class="page-link" href={`/${type()}?page=${page() - 1}`} aria-label="Previous Page">
29+
<A class="page-link" href={`/${type()}?page=${page() - 1}`} aria-label="Previous Page">
3030
{"<"} prev
31-
</a>
31+
</A>
3232
</Show>
3333
<span>page {page()}</span>
3434
<Show
@@ -39,17 +39,13 @@ export default function Stories(props: RouteSectionProps) {
3939
</span>
4040
}
4141
>
42-
<a class="page-link" href={`/${type()}?page=${page() + 1}`} aria-label="Next Page">
42+
<A class="page-link" href={`/${type()}?page=${page() + 1}`} aria-label="Next Page">
4343
more {">"}
44-
</a>
44+
</A>
4545
</Show>
4646
</div>
4747
<main class="news-list">
48-
<Show when={stories()}>
49-
<ul>
50-
<For each={stories()}>{story => <Story story={story()} />}</For>
51-
</ul>
52-
</Show>
48+
<For each={stories()}>{story => <Story story={story()} />}</For>
5349
</main>
5450
</div>
5551
);

apps/fixtures/hackernews/src/routes/stories/[id].tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type RouteDefinition, type RouteSectionProps } from "@solidjs/router";
1+
import { A, type RouteDefinition, type RouteSectionProps } from "@solidjs/router";
22
import { For, Show, createMemo } from "solid-js";
33
import Comment from "~/components/comment";
44
import { getStory } from "~/lib/api";
@@ -21,7 +21,7 @@ export default function Story(props: RouteSectionProps) {
2121
<span class="host">({story().domain})</span>
2222
</Show>
2323
<p class="meta">
24-
{story().points} points | by <a href={`/users/${story().user}`}>{story().user}</a>{" "}
24+
{story().points} points | by <A href={`/users/${story().user}`}>{story().user}</A>{" "}
2525
{story().time_ago} ago
2626
</p>
2727
</div>

apps/fixtures/notes/src/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function App() {
1111
return (
1212
<Router
1313
root={props => (
14-
<div class="main" $ServerOnly>
14+
<div class="main">
1515
<section class="col sidebar">
1616
<section class="sidebar-header">
1717
<a href="/">

apps/fixtures/notes/src/components/NoteList.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { createAsyncStore } from "@solidjs/router";
2-
import { For, Show } from "solid-js";
1+
import { For, createMemo, Show } from "solid-js";
32
import { getNotes } from "~/lib/api";
43
import SidebarNote from "./SidebarNote";
54

65
export default function NoteList(props: { searchText: string }) {
7-
const notes = createAsyncStore(() => getNotes(props.searchText));
6+
const notes = createMemo(() => getNotes(props.searchText));
87

98
return (
109
<Show
11-
when={notes()?.length}
10+
when={notes().length > 0}
1211
fallback={
1312
<div class="notes-empty">
1413
{props.searchText
@@ -21,7 +20,7 @@ export default function NoteList(props: { searchText: string }) {
2120
<For each={notes()}>
2221
{note => (
2322
<li>
24-
<SidebarNote note={note} />
23+
<SidebarNote note={note()} />
2524
</li>
2625
)}
2726
</For>

apps/fixtures/notes/src/components/SidebarNote.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export default function SidebarNote(props: { note: Note }) {
4949
class="sidebar-note-open"
5050
style={{
5151
"background-color": isActive()
52-
? "var(--tertiary-blue)"
53-
: "",
52+
? "var(--tertiary-blue)"
53+
: "",
5454
border: isActive() ? "1px solid var(--primary-border)" : "1px solid transparent",
5555
}}
5656
>

apps/fixtures/notes/src/routes/notes/[id]/(preview).tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { RouteDefinition, RouteSectionProps, createAsync } from "@solidjs/router";
2-
import { Show } from "solid-js";
1+
import { RouteDefinition, RouteSectionProps } from "@solidjs/router";
2+
import { Show, createMemo } from "solid-js";
33
import EditButton from "~/components/EditButton";
44
import { getNotePreview } from "~/lib/api";
55

@@ -10,22 +10,22 @@ export const route = {
1010
} satisfies RouteDefinition;
1111

1212
export default function NotePage({ params }: RouteSectionProps) {
13-
const note = createAsync(() => getNotePreview(+params.id));
13+
const note = createMemo(() => getNotePreview(+params.id));
1414
return (
1515
<Show when={note()} keyed>
1616
{note => (
1717
<div class="note">
1818
<div class="note-header">
19-
<h1 class="note-title">{note.title}</h1>
19+
<h1 class="note-title">{note()!.title}</h1>
2020
<div class="note-menu" role="menubar">
2121
<small class="note-updated-at" role="status">
22-
Last updated on {note.updatedAt}
22+
Last updated on {note()!.updatedAt}
2323
</small>
24-
<EditButton noteId={note.id}>Edit</EditButton>
24+
<EditButton noteId={note()!.id}>Edit</EditButton>
2525
</div>
2626
</div>
2727
<div class="note-preview">
28-
<div class="text-with-markdown" innerHTML={note.body} />
28+
<div class="text-with-markdown" innerHTML={note()!.body} />
2929
</div>
3030
</div>
3131
)}

apps/fixtures/notes/src/routes/notes/[id]/edit.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { RouteDefinition, RouteSectionProps, createAsync } from "@solidjs/router";
2-
import { Show } from "solid-js";
1+
import { RouteDefinition, RouteSectionProps } from "@solidjs/router";
2+
import { Show, createMemo } from "solid-js";
33
import NoteEditor from "~/components/NoteEditor";
44
import { getNote } from "~/lib/api";
55

@@ -10,7 +10,7 @@ export const route = {
1010
} satisfies RouteDefinition;
1111

1212
export default function EditNote({ params }: RouteSectionProps) {
13-
const note = createAsync(() => getNote(+params.id));
13+
const note = createMemo(() => getNote(+params.id));
1414
return (
1515
<Show when={note()}>
1616
<NoteEditor noteId={+params.id} initialTitle={note()!.title} initialBody={note()!.body} />

packages/start/src/server/server-functions-handler.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ export async function handleServerFunction(h3Event: H3Event) {
5151
if (!instance || request.method === "GET") {
5252
const args = url.searchParams.get("args");
5353
if (args) {
54-
const result = (await deserializeFromJSONString(args)) as any[];
54+
// args may be in seroval chunk format (from createServerReference)
55+
// or plain JSON (from router's .with() / hashKey for no-JS form submissions)
56+
let result: any[];
57+
if (args.startsWith(";0x")) {
58+
result = (await deserializeFromJSONString(args)) as any[];
59+
} else {
60+
result = JSON.parse(args);
61+
}
5562
for (const arg of result) {
5663
parsed.push(arg);
5764
}

0 commit comments

Comments
 (0)