Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt tanstack server fn plugin #1715

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

brenelz
Copy link
Contributor

@brenelz brenelz commented Jan 16, 2025

PR Checklist

I went deep to try and integrate Tanner's new Server Function plugin.

This was a proof of concept that seems to work.

Need someone more familiar with the code to take a look

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • infrastructure changes
  • Other... Please describe:

Copy link

changeset-bot bot commented Jan 16, 2025

🦋 Changeset detected

Latest commit: 80c77a5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/start Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tannerlinsley
Copy link

This is insanely cool.

@birkskyum
Copy link
Member

birkskyum commented Jan 16, 2025

@brenelz , to make the CI green for the docs build, it's just a matter of adjusting the rollup config to avoid the AsyncLocalStorage error for the client bundle.

You can move external

  • From: server.rollupConfig.external
  • To: vite.build.rollupOptions.external

Or have both for now like below:

// docs/app.config.ts

import { defineConfig } from "@solidjs/start/config";
import tailwindcss from "tailwindcss";
import { config } from "vinxi/plugins/config";

export default defineConfig({
  // experimental: { islands: true },
  server: {
    preset: "cloudflare_module",
    alias: {
      "_mime": "mime/index.js"
    },
    rollupConfig: {
      external: ["__STATIC_CONTENT_MANIFEST", "node:async_hooks"]
    }
  },
  vite: {
    build: {
      rollupOptions: {
        external: ["__STATIC_CONTENT_MANIFEST", "node:async_hooks"]
      }
    },
    plugins: [
      config("tailwind", {
        css: {
          postcss: {
            plugins: [tailwindcss]
          }
        }
      } as any)
    ]
  }
});

@atilafassina atilafassina self-requested a review January 16, 2025 07:22
@atilafassina
Copy link
Member

That's awesome!!
Thanks a lot for this, @brenelz 🏆

Meanwhile I'm working on improving the test story around here so we can merge this more confidently.
Once the CI is green, let's make sure we add a Changeset and then we should be in good shape for reviews / merge. :)

@birkskyum
Copy link
Member

birkskyum commented Jan 19, 2025

Since we don't have a test suite, the manual testing I've done here is to install the pkg.pr.new, and add the below to the Counter of the basic example, and set ssr:false in app config:

function useServer() {
  "use server";  
  console.log("Counter Server Function", isServer) // <- returns True on server
}

export default function Counter() {

  console.log("Counter Init", isServer) // <- returns False in client

  useServer()
  const [count, setCount] = createSignal(0);
  return (
    <button class="increment" onClick={() => setCount(count() + 1)} type="button">
      Clicks: {count()}
    </button>
  );
}

And it appear to work as expected both in vinxi dev mode, and after build + start

@katywings
Copy link
Contributor

I am wondering how easy it would be to test this out in one of my projects via npm link 🙈, or is there a chance we could publish this on some special name/tag to give it a try?

@birkskyum
Copy link
Member

@katywings , there is the pkg.pr.new link here - can you use that?

@brenelz
Copy link
Contributor Author

brenelz commented Jan 22, 2025

@birkskyum I was just going to say the same thing. I haven't actually used it before but seems cool

@atilafassina
Copy link
Member

Just merged #1719
if we solve the conflicts on this PR we can pull main and it would be more straightforward to add tests.

@brenelz brenelz changed the title WIP: Adopt tanstack server fn plugin Adopt tanstack server fn plugin Jan 23, 2025
birkskyum
birkskyum previously approved these changes Jan 24, 2025
Copy link
Member

@birkskyum birkskyum left a comment

Choose a reason for hiding this comment

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

E2E test passing. LGTM

@@ -0,0 +1,5 @@
---
"@solidjs/start": minor
Copy link
Member

Choose a reason for hiding this comment

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

I was kinda expecting this one to be a patch since it's not changing any API nor is it adding a new feature.

wdyt?

Copy link
Member

@birkskyum birkskyum Jan 24, 2025

Choose a reason for hiding this comment

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

I recommended the minor but I'm good with a patch too.

@katywings
Copy link
Contributor

katywings commented Jan 24, 2025

Testing this out right now, so far it doesn't work at all for me, most likely because it seems to have a completely different approach to decide which dependencies to externalize. Still figuring it out the details though. You gonna get a second analysis soon 😅

Edit: Yeah so it looks like this completely fails to externalize server libraries in the client bundling, resulting in errors during the build. Plus countless warnings for every node built-in module (Module "fs / path / stream / xyz" has been externalized for browser compatibility).

@katywings
Copy link
Contributor

Here is a very basic reproduction of the missing externalization, this works in dev but fails to npm run build.
https://stackblitz.com/edit/github-vts2k1cp?file=src%2Froutes%2Findex.tsx

@katywings
Copy link
Contributor

katywings commented Jan 24, 2025

I wonder if this is a problem in this PR or a general thing with the Tanstack Server Functions plugin 🤔 - afaik @tannerlinsley mentioned that the Tanstack plugin actually should externalize more heavily than Vinxi and not less - so I assume this must be a problem on our side 🤔.

@birkskyum birkskyum self-requested a review January 24, 2025 15:34
@birkskyum birkskyum dismissed their stale review January 24, 2025 15:34

Waiting for this #1722

@birkskyum
Copy link
Member

birkskyum commented Jan 24, 2025

There are externalization tests added to the test suite, so this PR should be rebased, and pass those.

@birkskyum
Copy link
Member

@katywings , next time you have a chance to check it, let us know if it fares better for you now with the externalization fixed.

@birkskyum birkskyum marked this pull request as ready for review January 25, 2025 12:18
@birkskyum birkskyum requested a review from katywings January 25, 2025 12:19
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.

5 participants