-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
[lucia] Attempt to switch to nextjs app dir #139
base: lucia
Are you sure you want to change the base?
[lucia] Attempt to switch to nextjs app dir #139
Conversation
0720e7c
to
0bdf789
Compare
I deployed it to here. https://t4-rm-test.pages.dev/ssr |
We could rework this PR to be against |
36c5591
to
c0d4659
Compare
To be clear, styles don't load properly in the old It does work in the |
I want to investigate this some more before merging it into the lucia branch. I feel like it could be it's own branch? The app router directives in |
Yeah... probably shouldn't merge for a bit or use a different branch.
I just tested with the iOS simulator and everything was fine. It redirected me without issue. It's using Solito's app router hooks - https://solito.dev/app-directory/hooks I see warnings in my nextjs console about I also see a jotai warning sometimes. One other note... dealing with Cloudflare's cross-domain default domains for the API ( I think the best path forward for this template is to use the NextJS rewrite feature to proxy the worker hono server from the Pages site. I've been using this for months with my personal project. It doesn't seem to add much noticeable latency. Using a custom domain and setting the worker to be on a subdomain of the app domain works though as you know... but the docs need to tell people that it's required to use a custom domain when they deploy. Here's a commit where I switched to the proxied API on my master branch rmarscher@f08abae -- that is currently deployed at https://t4-rm-test.pages.dev/. |
Essentially, yes. When using With the app router, it uses a different method to inject the styles which does work on the edge runtime. |
7bb3f7f
to
462add3
Compare
There is quite a lot of work in this PR! Much appreciated! I'm new here, just stumbled upon T4 by accident while setting up a new Web project. However, the lack of Is there anything special that I should know in order to have this PR up and running in my project? |
As mentioned in the comments, I got hung up on tRPC. The @trpc/next package only supports the pages router. They don't have an official way to work with React Server Components and app router. I think they might be waiting for React 19 and its new "use" hook. They were using that in one of the experimental app router examples they had previously published. I just checked and there are still open issues around nextjs app router in the trpc repo. Tamagui added basic support for app router but they are "actively working on a new mode that enables full server-side support with some limitations." https://tamagui.dev/docs/guides/next-js#app-router The other thing is the native Expo app communicates with the tRPC API to get all of its data. Expo and the React Native community are experimenting with how RSC can be used to optimize bundles for native apps, but that feels pretty far off from being something to use in production. That being said... this branch was working last I tried it. I don't remember there being anything special to get it working. It is missing the lucia v3.0 updates that we merged on the lucia branch though. There was a fix to how the argon2 wasm file needed to be invoked for password hashing too. |
Necessary if API_URL does not contain APP_URL.
462add3
to
3c54a4f
Compare
3c54a4f
to
bd7a8c9
Compare
@zvictor I just rebased and force-pushed the branch so it has the latest commits from the As I mentioned, this project is currently expecting a separate Cloudflare Worker for the API from the Cloudflare Pages project that hosts the NextJS app. With app router, it's probably possible to move the API server code to be part of the NextJS app. You'd have to use the wrangler.toml to in the apps/next folder to define the bindings that are currently set to the packages/api/wrangler.toml. Once you have the API server set up in your NextJS app router, you can use a server side react context to store a tRPC caller and then you could use that in your React Server Components to fetch data server side and send it down. There's a talk happening this week - "Introducing Universal React Server Components in Expo Router" - https://conf.react.dev/talks/7 Expo Router v4 is probably getting released. Looking forward to seeing how that enables RSC for native. |
This does seem to get styles working with SSR pages. It's a bit unclear if tRPC is waiting for queries to run during SSR. They say they don't have a way to hydrate those queries even if they do run during SSR, so it's a waste. trpc/trpc#3185 (comment)
They have different clients for server-side rendering including one that uses an app-dir hosted trpc api and bypasses internal http requests (which is how things work in sveltekit land with their endpoints). Their client for fetching in the browser is marked as "not implemented" in their example repo:
https://github.com/trpc/trpc/blob/main/examples/.experimental/next-app-dir/src/app/client/ClientGreeting.tsx#L11
I created a custom provider with TRPCReact which is how I've seen others integrate tRPC with NextJS app dir (the TRPCNext withTRPC HOC only works with the old Pages router).