Skip to content

ssr flip: use start.node instead of a baked server.js - #91

Open
ryansolid wants to merge 3 commits into
mainfrom
start-node-flip
Open

ryansolid wants to merge 3 commits into
mainfrom
start-node-flip

Conversation

@ryansolid

Copy link
Copy Markdown
Contributor

Follow-up to solidjs/templates#304 (rc.9 / @solidjs/vite-plugin next.44 repin) and solidjs/solid-vite-plugin#366 (start.node).

@solidjs/vite-plugin 3.0.0-next.44 adds start.node: with start: { node: true } the ssr build emits a ready-to-run Node entry at dist/server/node.js (static dist/client with immutable/must-revalidate cache headers, PORT/HOST, everything else through handleRequest with nativeEvent). The templates adopted it and deleted solid-v2/fullstack/server.js, which the CLI's --ssr flip was baking byte-for-byte into every flipped scaffold (SERVER_JS, kept in sync by scripts/gen-ssr-flip-server.mjs). This PR is the CLI side of the spec in templates#304's body.

Changes

  • packages/create/src/utils/ssr-flip.ts
    • anchor rewrite solid({ start: truesolid({ start: { node: true }, ssr: true (SSR_ANCHOR_REPLACEMENT); the hint comment is still stripped. templates#304 preserves both the anchor and the // add \ssr: true` for streaming SSR` hint in every client-mode config, so detection is unchanged.
    • SSR_START_SCRIPT = node --env-file-if-exists=.env dist/server/node.js (--env-file-if-exists stays: the emitted entry does not read .env itself).
    • removed SERVER_JS, the @generated-server-js-* markers and the server.js write — the flip now touches exactly vite.config.ts + package.json.
  • deleted scripts/gen-ssr-flip-server.mjs.
  • create-solid-v2.ts: comment only. retargetTSFilenames / the --js conversion need no change (the config edit still happens on the .ts source; dist/server/node.js is a build artifact, not a source file to convert). There was no server.js copy step to remove — it was written by applySsrFlip inside the temp dir and copied by the generic conversion walk.
  • tests/ssr-flip.test.ts: asserts the new config text and start script, that the flip leaves only package.json + vite.config.ts in the dir (no server.js), and the abort path still writes nothing. The solid-v2-basic fixture now mirrors templates#304's basic (vite.config.ts incl. diagnostics: true / fileRoutes({ types: true }), rc.9 / next.44 / next.26 pins).
  • changeset (minor for create-solid + @solid-cli/create), matching the repo's changesets flow.
  • Baked fallback manifest (utils/manifest.ts / constants.ts): checked, nothing references server.js. Templates copied whole (fullstack, fullstack-tanstack) need nothing — the file is simply no longer in the tree.

Verification

  • pnpm build && pnpm test: 58/58 tests, 11/11 files (suite grew from 54 on main with the devtools/tsOnly work; all green).
  • Live scaffold against templates#304's basic (ref 65899ca). The CLI has no ref override any more (0.10.0 removed SOLID_CLI_TEMPLATES_REF; it tracks templates HEAD), so I drove the real createSolidV2(..., ssr = true) code path with downloadTemplate swapped for a local copy of the PR branch's solid-v2/basic:
    • TS + --ssr: vite.config.tssolid({ start: { node: true }, ssr: true, extensions: ['.jsx', '.tsx'], diagnostics: true }), hint comment gone, no server.js, start = node --env-file-if-exists=.env dist/server/node.js. npm install resolves @solidjs/vite-plugin@3.0.0-next.44 / solid-js@2.0.0-rc.9; npm run build emits dist/server/node.js (7.14 kB) + dist/server/server.js; npm startListening on http://localhost:<PORT>; GET / 200 text/html with the SSR'd shell + hydration script; hashed /assets/web-*.js 200 Cache-Control: public, max-age=31536000, immutable; /favicon.ico 200 must-revalidate + Last-Modified; /users/1 200 with SSR'd <h2>Ada Lovelace</h2>; unknown route 404; /../package.json 404.
    • --js + --ssr on the same template: .project temp dir cleaned, vite.config.jssolid({ start: { node: true }, ssr: true, extensions: ['.jsx'], diagnostics: true }), setupFiles: ['./vitest-setup.js'], no server.js; build emits dist/server/node.js; npm start serves GET / 200 and /users/2<h2>Grace Hopper</h2>.

Merge order: after templates#304

The flip itself is order-independent: it only rewrites vite.config.ts + package.json, and the solid({ start: true anchor is identical on templates main and on #304, so it applies cleanly against either. What is not order-independent is the runtime of the flipped scaffold: templates main pins @solidjs/vite-plugin ^3.0.0-next.38 and ships a pnpm-lock.yaml resolving next.38, which predates start.node. Verified against a flipped copy of main's basic: with pnpm install --frozen-lockfilenext.38, start: { node: true } is silently ignored, no dist/server/node.js is emitted and npm start fails with MODULE_NOT_FOUND; with npm install (no lockfile) the caret resolves to next.44 and it works. So merging this first would break --ssr scaffolds for pnpm users until #304 lands (and the CLI tracks templates HEAD, so there is no window where the old baked server.js is needed after #304 merges). Merge #304 first, then this.

Not for merging by the author — please review.

@solidjs/vite-plugin 3.0.0-next.44 adds `start.node` (solidjs/solid-vite-plugin#366):
with `start: { node: true }` the ssr build emits a ready-to-run Node entry at
dist/server/node.js. The templates adopted it and deleted the hand-written
solid-v2/fullstack/server.js (solidjs/templates#304), so the CLI's --ssr flip
must stop baking a copy of that file into scaffolds.

- ssr-flip.ts: rewrite the `solid({ start: true` anchor to
  `solid({ start: { node: true }, ssr: true` (anchor + hint comment are preserved
  by templates#304, so detection is unchanged); SSR_START_SCRIPT is now
  `node --env-file-if-exists=.env dist/server/node.js`; drop SERVER_JS, the
  @generated-server-js markers and the server.js write.
- Delete scripts/gen-ssr-flip-server.mjs (nothing left to embed).
- tests: assert the new config text / start script and that the flip touches
  only vite.config.ts + package.json; solid-v2-basic fixture mirrors
  templates#304's basic (rc.9 / next.44 / next.26 pins, diagnostics: true).
- changeset (minor).

retargetTSFilenames / the --js conversion are unaffected: the config edit still
happens on the .ts source and dist/server/node.js is a build artifact.
…e, start: { node: true })"

This reverts commit 225cb51.
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 this pull request may close these issues.

1 participant