Skip to content

Improve support for Next.js / SSR in @ldo/solid-react - #156

Merged
mrkvon merged 6 commits into
o-development:mainfrom
mrkvon:fix-153-nextjs-ssr
Jul 3, 2026
Merged

Improve support for Next.js / SSR in @ldo/solid-react#156
mrkvon merged 6 commits into
o-development:mainfrom
mrkvon:fix-153-nextjs-ssr

Conversation

@mrkvon

@mrkvon mrkvon commented May 26, 2026

Copy link
Copy Markdown
Collaborator

Make sure browser API (SharedWorker) doesn't run on server.
Add "use client" directive to @ldo/solid-react index.ts.
Test this with a new example nextjs app.

The example app has been added to a new "examples" directory.
The example app's functionality has been copied from https://github.com/o-development/ldo/tree/f68a842d7c40076ce270f70142e0444a7fdd1b92/packages/solid-react/dev.

Fixes #153

@mrkvon
mrkvon force-pushed the fix-153-nextjs-ssr branch 2 times, most recently from 9f67b5e to eb4ad42 Compare May 26, 2026 20:01
return (
<html lang="en">
<body>
{/* @ts-expect-error React types dependency mismatch (TODO fix) */}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this a complicated type fix?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed with explicit type resolution in the nextjs app's tsconfig.json to local node_modules.
Also added react to peer dependencies of @ldo/solid-react.

in 6af27ce

@@ -0,0 +1,49 @@
:root {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like that you created a "examples" folder to test the example app.

There's something similar to this at /packages/solid-react/dev. Could you also move that app here? It's just a simple vite (non nextjs) app.

@mrkvon mrkvon May 27, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Moved the /packages/solid-react/dev to dev/solid-react-vite-app in 27032b8
and added the missing files (like tsconfig.json, package.json, eslint config etc) generated by npm create vite@latest https://vite.dev/guide/#scaffolding-your-first-vite-project

@@ -0,0 +1,49 @@
:root {
--background: #ffffff;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For these example apps, let's include as little styling as possible that could distract from the actual code. Notice in /packages/solid-react/dev there's almost no styling and there's just default HTML formatting.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Styling removed in d2e9a9b


const onFetch: SubmitEventHandler<HTMLFormElement> = async (event) => {
event.preventDefault();
const response = await fetch(url);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm. On second thought. This "example" app is just to test the fetch functionality. It doesn't make sense to put it in an "example" folder because we want to encourage users to use the resource methods rather than the fetch function. So, this probably belongs next to the current /packages/solid-react/dev library. Maybe both can be renamed.

@mrkvon mrkvon May 27, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Called the directory "dev" instead of "examples" as discussed during our weekly meeting. Added README explaining its purpose. d2e9a9b

@mrkvon
mrkvon force-pushed the fix-153-nextjs-ssr branch 4 times, most recently from aef750d to 56d3cc5 Compare May 30, 2026 20:21
@mrkvon mrkvon mentioned this pull request May 30, 2026

@jaxoncreed jaxoncreed left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM Squash commits before meging

mrkvon added 5 commits July 2, 2026 22:13
npx create-next-app@latest solid-react-nextjs-app
Make sure client-only API (SharedWorker) doesn't run on server.
Add "use client" directive.
Test this with the new example nextjs app..

Fixes o-development#153
+ Add a README explaining dev directory's purpose.
+ Remove distracting styles
+ Update favicon
Also, add other files from the default Vite + React + TS app
generated with `npm create vite@latest`
Explicitly resolve @types/react to local node_modules.
List react as peerDependency of @ldo/solid-react.
@mrkvon
mrkvon force-pushed the fix-153-nextjs-ssr branch from 56d3cc5 to 85b9376 Compare July 2, 2026 20:14
@mrkvon
mrkvon merged commit 5ea3625 into o-development:main Jul 3, 2026
2 checks passed
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.

ReferenceError: SharedWorker is not defined

2 participants