Skip to content

docs: show how to read Harper data from the React SSR entry#106

Merged
dawsontoth merged 2 commits into
mainfrom
docs/ssr-harper-data-access
Jun 24, 2026
Merged

docs: show how to read Harper data from the React SSR entry#106
dawsontoth merged 2 commits into
mainfrom
docs/ssr-harper-data-access

Conversation

@dawsontoth

Copy link
Copy Markdown
Contributor

Why

The React SSR templates ship an entry-server whose comment says to use the request URL "to drive routing/data loading per request" — but gives no example of how. With empty schemas//resources/ and no data-flow example, a developer reaching the Vite-loaded SSR entry has nothing to go on, and can reasonably (but wrongly) conclude they can't access Harper data there. That leads to workarounds like fetching the app's own REST API over loopback, or assuming the SSR entry doesn't get Harper's globals.

In reality, tables/databases are live process-wide objects, and node_modules/harper is symlinked to the running install — so import { tables } from 'harper' works in the SSR entry.

What

Applied to both template-react-ssr and template-react-ts-ssr:

  • entry-server.{jsx,tsx} — expanded the doc comment to show the native pattern: make render async and import { tables } from 'harper' to query a table, rendering with data already in place (no client fetch).
  • vite.config.{js,ts} — added ssr: { external: ['harper'] } with an explanatory comment. Symlinked deps aren't reliably auto-externalized for SSR, so this is what makes import { tables } from 'harper' resolve to the running runtime instead of being bundled.

Both changes are additive (comment + config); the default scaffold still builds and runs unchanged.

🤖 Generated with Claude Code

The React SSR templates' entry-server told developers to use the request URL
"to drive routing/data loading per request" but showed no example, leaving them
to guess how — or whether — they can reach Harper data during SSR. That gap led
to workarounds (e.g. fetching the app's own REST API over loopback) and to the
mistaken belief that the Vite-loaded SSR entry can't see Harper's globals.

- entry-server.{jsx,tsx}: document the native pattern — make `render` async and
  `import { tables } from 'harper'` to query a table. `tables` is the same live,
  process-wide registry available everywhere in Harper; the SSR entry reaches it
  because Harper symlinks node_modules/harper to the running install.
- vite.config.{js,ts}: add `ssr.external: ['harper']` so that import resolves to
  the running runtime instead of being bundled (symlinked deps aren't reliably
  auto-externalized for SSR).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dawsontoth dawsontoth requested a review from a team as a code owner June 24, 2026 17:36

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the React and React-TS SSR templates to support server-side rendering with data fetched directly from Harper. It configures Vite to keep harper external during SSR and adds documentation/examples in the server entry files. The reviewer suggested adding notes to the code examples in both templates to clarify that the App component needs to be updated to accept the product prop, preventing potential TypeScript compilation errors or non-functional code.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread template-react-ts-ssr/src/entry-server.tsx
Comment thread template-react-ssr/src/entry-server.jsx
The data-loading example renders `<App product={product} />`, but the template's
App component takes no props — copy-pasting it as-is would cause a TS error (and
a silently-ignored prop in JS). Add a one-line note in each example.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dawsontoth dawsontoth merged commit 1fc5b9b into main Jun 24, 2026
27 checks passed
@dawsontoth dawsontoth deleted the docs/ssr-harper-data-access branch June 24, 2026 20:13
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.10.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@kriszyp kriszyp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accurate SSR data-read example, consistent with the process-wide-singleton docs. Approving. — Claude (Opus 4.8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants