๐บ๏ธ Remix SPA Target #7638
Replies: 22 comments 56 replies
-
Instead of ignoring the |
Beta Was this translation helpful? Give feedback.
-
That's great! SPA target will probably unlock us to use Remix for micro-frontends powered by Single-Spa + Vite. |
Beta Was this translation helpful? Give feedback.
-
you have no idea how relevant this to our current needs. Very hopeful this happens. |
Beta Was this translation helpful? Give feedback.
-
This is exactly what I wanted to have for our Vite+RR app! Looking forward |
Beta Was this translation helpful? Give feedback.
-
This could open the door to a SSG mode in the future that just do SSR and fetch a set of URLs to generate static HTML inside the public folder. It could work in hybrid mode by removing the static routes from the manifest. |
Beta Was this translation helpful? Give feedback.
-
Have you considered sticking to Remix could take your I was experimenting with that approach before and I have a POC ready. I was initially working on it as a part of my research bringing RSC and Server Actions into non-server targets (such as React Native). Happy to send you some more information or demonstrate it. |
Beta Was this translation helpful? Give feedback.
-
Michael and I bike-shedded a bit here, thinking maybe just do a boolean since "spa" is a muddy term. ssr: false We'll also want |
Beta Was this translation helpful? Give feedback.
-
OK, so I'll write down my problem and someone smarter please tell me if this proposal solves it. I have a Remix app that I want to wrap inside a native shell using Capacitor.js and distribute it to the app stores. Capacitor supports a server url option but if you enable it, all the assets don't get bundled on the device. This causes apple to decline the app from the store saying that there isn't a big enough difference from the web version. If the server url option is off, Capacitor looks for an index.html file in the public directory. So in a dream world for me, if you set ssr: false in your Remix config, the build ignores entry.server and the root route?! And supports some way for you to have an index.html file that points to your static assets? I don't really know if it can work like this but if someone has and idea, I think being able to move between ssr and no ssr with the same codebase would solve a lot of problems. |
Beta Was this translation helpful? Give feedback.
-
If I understood the proposal correctly just a single HTML file will be generated, correct? Are there plans to create multiple entry HTMLs at some point (to support different initial prerendered layouts) which all act as a valid starting point for the same SPA? |
Beta Was this translation helpful? Give feedback.
-
If I understand correctly, this would allow Remix to be used as-is in browser extensions, which require all templates to be bundled! Great! |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to have SSR for the initial page load and switch to a single-page application (SPA) approach for subsequent navigations? Our site works as follows: Initially, upon visiting our website, a server-side request to our API fetches the necessary data to render the page. As users browse the site, they directly retrieve additional data from the API, bypassing the server for these subsequent requests. |
Beta Was this translation helpful? Give feedback.
-
Will this and other proposals support having a mix of static routes and SSR routes?
What about mostly static, prerendered routes with some SSR sections? (eg product page with personalized recommendation) |
Beta Was this translation helpful? Give feedback.
-
Will the root route only render on the browser side? This means that when the project changes from spa mode to ssr mode, I'll have to do some modifications to the root and entry. |
Beta Was this translation helpful? Give feedback.
-
Does the I was actually sort of envisioning a world in which we render the
It might veer a bit off from standard vite SPA practice though where the user manages a raw HTML file. |
Beta Was this translation helpful? Give feedback.
-
I read this proposal as primarily having the motivation for ease of migration from React Router SPA to Remix SPA, and eventually to Remix SSR. In the case of servers where a JavaScript backend isn't possible (e.g. GitHub Pages), I think the Remix documentation should have some guidance for new applications to help them make a choice between React Router SPA and Remix SPA. What are the advantages and disadvantages of starting with one over the other? |
Beta Was this translation helpful? Give feedback.
-
Missing features like SPA mode + Module federation is why I am looking at Modern JS framework otherwise I ll be using Remix all the way :) |
Beta Was this translation helpful? Give feedback.
-
We use Vite's library mode to distribute our React Router SPA, rather than an index.html. This is so that the app can be embedded within other sites. Would the following be possible? // vite.config.js
import { resolve } from 'path'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
remix({
target: "spa",
}),
],
build: {
lib: {
entry: resolve(__dirname, 'src/app/entry.client.tsx'),
name: 'MyApp',
fileName: 'my-app',
},
},
}) |
Beta Was this translation helpful? Give feedback.
-
Sorry if this is a silly question but will API routes still work with in SPA mode? |
Beta Was this translation helpful? Give feedback.
-
Exporting server loaders in SPA mode now raises a breaking error. Is it possible to have loaders be truly ignored (via a warning or optional flag) and have I.e. I want SSR & loaders for the website but have have an SPA for mobile use - I can handle the gathering of loader data client side seperately but breaking loaders appears like it would require a big rewrite. |
Beta Was this translation helpful? Give feedback.
-
Released in |
Beta Was this translation helpful? Give feedback.
-
Hi everyone! Can somebody clarify for me please? In February I am going to start develop a new project. It HAS to be an SPA. For SPA we used React Router + TanStack Query. But now I see that there is SPA Mode and clientLoaders and clientActions in Remix. We would love to unify our DX, It would be sooo great if we could use Remix and the same mindset for SSR and SPA projects. So far I understand this:
Development of this project will take 2-3 months I guess, and we would really like to start this project with Remix SPA. More than that, Vite fixes all problems which we had with our UI library of choice - PrimeReact. We love Remix very much, thanks everyone for such a great framework, from Russia with love, Andrey. |
Beta Was this translation helpful? Give feedback.
-
Is there a technical limitation that causes I think there should be an option to make these return a warning instead of an error. |
Beta Was this translation helpful? Give feedback.
-
Remix SPA
While a React Router SPA and Remix feel very similar, there's still a decent gap between them from a developer ergonomics perspective. This proposal closes that gap allowing Remix to function as a Single Page App.
Additionally, React Router apps don't have a fluid migration path to Remix today. Every loader and action needs to suddenly start working on the server, file system routes need to be figured out from whatever the app was doing before, etc. Along with the #7632 proposal, and the #7634 proposal, this proposal creates a fluid migration path from React Router to Remix. Developers can add a JavaScript backend to their Remix app without changing application code outside of the client entry point.
Proposal
In the vite config, a flag changes the mode to "spa" from the default "ssr".
The remix plugin will now only generate client bundles, and normal vite behavior will create the index.html entry point to the app.
It will use the same file conventions for
entry.client.tsx
,root.tsx
, and file system routes.The route module API remains the same, but the
loader
andaction
exports will be ignored, and only theclientLoader
andclientAction
exports will be used.Imports still come from
@remix-run/react
notreact-router-dom
Entry points
The HTML entry point for vite is defined at
app/entry.html
with a script pointing toentry.client.tsx
:The app
entry.client.tsx
will need to look a little different than ssr Remix by rendering into a root element instead of hydrating a full document:Migrating from SPA to SSR targets
To switch to a full stack Remix app with the Remix app server, you simply change the target, but everything else remains the same:
To switch to a custom server, apps will also need to add a server entry file and adapter to the vite config. That setup is discussed in #7632 proposal.
Beta Was this translation helpful? Give feedback.
All reactions