Skip to content

Commit aaa5c51

Browse files
authored
Merge branch 'main' into vite-8-compat
2 parents 65448a9 + abe3979 commit aaa5c51

28 files changed

Lines changed: 1294 additions & 312 deletions

.changeset/purple-taxes-join.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/start": patch
3+
---
4+
5+
reload ssr server when new route files are created in dev

.changeset/rare-canyons-travel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/start": minor
3+
---
4+
5+
Add new directives plugin with shorter function IDs and inner declaration support

apps/tests/src/e2e/server-function.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ test.describe("server-function", () => {
8181
await page.goto("http://localhost:3000/server-function-blob");
8282
await expect(page.locator("#server-fn-test")).toContainText('{"result":true}');
8383
});
84+
test("should remove exports for non-function values when top-level use server is used", async ({ page }) => {
85+
await page.goto("http://localhost:3000/server-function-query-toplevel");
86+
await expect(page.locator("#server-fn-test")).toContainText('false');
87+
});
8488

8589
// TODO not sure if this is the correct place
8690
test("should build with a env:server", async ({ page }) => {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use server";
2+
3+
import { query } from "@solidjs/router";
4+
import { isServer } from "solid-js/web";
5+
6+
export const testQuery = query(() => isServer, 'testQuery');
7+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { createEffect, createSignal } from "solid-js";
2+
import * as testModule from "~/functions/solid-router-query";
3+
4+
export default function App() {
5+
const [output, setOutput] = createSignal<boolean | null>();
6+
7+
createEffect(() => {
8+
setOutput('testQuery' in testModule);
9+
});
10+
11+
return (
12+
<main>
13+
<span id="server-fn-test">{JSON.stringify(output())}</span>
14+
</main>
15+
);
16+
}

apps/tests/test-results/.last-run.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/start/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"@babel/traverse": "^7.29.0",
4242
"@babel/types": "^7.29.0",
4343
"@solidjs/meta": "^0.29.4",
44-
"@tanstack/server-functions-plugin": "1.134.5",
4544
"@types/babel__traverse": "^7.28.0",
4645
"@types/micromatch": "^4.0.10",
4746
"cookie-es": "^2.0.0",

packages/start/src/config/fs-routes/fs-watcher.ts

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import type {
22
EnvironmentModuleNode,
33
FSWatcher,
4-
ModuleGraph,
5-
ModuleNode,
64
PluginOption,
75
ViteDevServer,
86
} from "vite";
7+
import { VITE_ENVIRONMENTS } from "../constants.ts";
98
import { moduleId } from "./index.ts";
109
import type { BaseFileSystemRouter } from "./router.ts";
1110

@@ -32,30 +31,24 @@ function createRoutesReloader(
3231
return () => routes.removeEventListener("reload", handleRoutesReload);
3332

3433
function handleRoutesReload(): void {
35-
if (environment === "ssr") {
36-
// Handle server environment HMR reload
37-
const serverEnv = server.environments.server;
38-
if (serverEnv && serverEnv.moduleGraph) {
39-
const mod: EnvironmentModuleNode | undefined =
40-
serverEnv.moduleGraph.getModuleById(moduleId);
41-
if (mod) {
42-
const seen = new Set<EnvironmentModuleNode>();
43-
serverEnv.moduleGraph.invalidateModule(mod, seen);
44-
}
45-
}
46-
} else {
47-
// Handle client environment HMR reload
48-
const { moduleGraph }: { moduleGraph: ModuleGraph } = server;
49-
const mod: ModuleNode | undefined = moduleGraph.getModuleById(moduleId);
50-
if (mod) {
51-
const seen = new Set<ModuleNode>();
52-
moduleGraph.invalidateModule(mod, seen);
53-
server.reloadModule(mod);
54-
}
34+
const envName =
35+
environment === "ssr" ? VITE_ENVIRONMENTS.server : VITE_ENVIRONMENTS.client;
36+
const devEnv = server.environments[envName];
37+
if (!devEnv?.moduleGraph) return;
38+
39+
const mod: EnvironmentModuleNode | undefined =
40+
devEnv.moduleGraph.getModuleById(moduleId);
41+
if (mod) {
42+
const seen = new Set<EnvironmentModuleNode>();
43+
devEnv.moduleGraph.invalidateModule(mod, seen);
5544
}
5645

57-
if (!server.hot) {
58-
server.ws.send({ type: "full-reload" });
46+
if (environment !== "ssr") {
47+
if (mod) {
48+
devEnv.reloadModule(mod);
49+
} else if (devEnv.hot) {
50+
devEnv.hot.send({ type: "full-reload" });
51+
}
5952
}
6053
}
6154
}

packages/start/src/config/index.ts

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { TanStackServerFnPlugin } from "@tanstack/server-functions-plugin";
21
import { defu } from "defu";
32
import { globSync } from "node:fs";
43
import { extname, isAbsolute, join } from "node:path";
54
import { fileURLToPath } from "node:url";
65
import { normalizePath, type PluginOption } from "vite";
76
import solid, { type Options as SolidOptions } from "vite-plugin-solid";
8-
7+
import { serverFunctionsPlugin } from "../directives/index.ts";
98
import { DEFAULT_EXTENSIONS, VIRTUAL_MODULES, VITE_ENVIRONMENTS } from "./constants.ts";
109
import { devServer } from "./dev-server.ts";
1110
import { type EnvPluginOptions, envPlugin } from "./env.ts";
@@ -190,38 +189,15 @@ export function solidStart(options?: SolidStartOptions): Array<PluginOption> {
190189
envPlugin(options?.env),
191190
// Must be placed after fsRoutes, as treeShake will remove the
192191
// server fn exports added in by this plugin
193-
TanStackServerFnPlugin({
194-
// This is the ID that will be available to look up and import
195-
// our server function manifest and resolve its module
196-
manifestVirtualImportId: VIRTUAL_MODULES.serverFnManifest,
197-
directive: "use server",
198-
callers: [
199-
{
200-
envConsumer: "client",
201-
envName: VITE_ENVIRONMENTS.client,
202-
getRuntimeCode: () =>
203-
`import { createServerReference } from "${normalizePath(
204-
fileURLToPath(new URL("../server/server-runtime", import.meta.url)),
205-
)}"`,
206-
replacer: opts => `createServerReference('${opts.functionId}')`,
207-
},
208-
{
209-
envConsumer: "server",
210-
envName: VITE_ENVIRONMENTS.server,
211-
getRuntimeCode: () =>
212-
`import { createServerReference } from '${normalizePath(
213-
fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)),
214-
)}'`,
215-
replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')`,
216-
},
217-
],
218-
provider: {
219-
envName: VITE_ENVIRONMENTS.server,
220-
getRuntimeCode: () =>
221-
`import { createServerReference } from '${normalizePath(
222-
fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)),
223-
)}'`,
224-
replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')`,
192+
serverFunctionsPlugin({
193+
manifest: VIRTUAL_MODULES.serverFnManifest,
194+
runtime: {
195+
server: normalizePath(
196+
fileURLToPath(new URL("../server/server-fns-runtime.ts", import.meta.url)),
197+
),
198+
client: normalizePath(
199+
fileURLToPath(new URL("../server/server-runtime.ts", import.meta.url)),
200+
),
225201
},
226202
}),
227203
{
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type * as babel from "@babel/core";
2+
import * as t from "@babel/types";
3+
4+
export function bubbleFunctionDeclaration(path: babel.NodePath<t.FunctionDeclaration>): void {
5+
const decl = path.node;
6+
// Check if declaration is FunctionDeclaration
7+
if (decl.id) {
8+
const block = (path.findParent(current => current.isBlockStatement()) ||
9+
path.scope.getProgramParent().path) as babel.NodePath<t.BlockStatement>;
10+
11+
if (path.parentPath.isExportNamedDeclaration()) {
12+
path.parentPath.replaceWith(
13+
t.exportNamedDeclaration(undefined, [t.exportSpecifier(decl.id, decl.id)]),
14+
);
15+
} else if (path.parentPath.isExportDefaultDeclaration()) {
16+
path.replaceWith(decl.id);
17+
} else {
18+
path.remove();
19+
}
20+
21+
const [tmp] = block.unshiftContainer(
22+
"body",
23+
t.variableDeclaration("const", [
24+
t.variableDeclarator(
25+
decl.id,
26+
t.functionExpression(decl.id, decl.params, decl.body, decl.generator, decl.async),
27+
),
28+
]),
29+
);
30+
block.scope.registerDeclaration(tmp);
31+
tmp.skip();
32+
}
33+
}

0 commit comments

Comments
 (0)