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

Use vite-plugin-ssr #56

Open
brillout opened this issue Mar 12, 2021 · 7 comments
Open

Use vite-plugin-ssr #56

brillout opened this issue Mar 12, 2021 · 7 comments

Comments

@brillout
Copy link

brillout commented Mar 12, 2021

We briefly talked about it at the vite-plugin-mdx repo; AFAICT vite-plugin-ssr would actually fit your project well.

Thoughts?

@thelinuxlich
Copy link
Owner

I tried adapting the starter to use it, but didn't had knowledge enough so the build was breaking, some tasks weren't working

@thelinuxlich
Copy link
Owner

Oh and I got a bit confused about the filesystem autorouting, how to automatically add /resource/:id pages for example

@brillout
Copy link
Author

The build currently doesn't work because of vitejs/vite#2390. I'm going to wait to see what Evan replies. If the bug is not fixed soon I'll simply use fast-glob instead of import.meta.glob() for building. A workaround right now is to link vite-plugin-ssr and Vite will pick up vite-plugin-ssr's import.meta.glob().

how to automatically add /resource/:id pages

Defining the parameter of a route in its filename is breaking the convention of not using special characters in filenames which may result in problems for certain deployment environments. It's too little of a benefit and doesn't justify breaking conventions.

About whether to use vite-plugin-ssr or not.

Using vite-plugin-ssr provides you with an SSR architecture without limiting you in any way. The problem with SSR frameworks such as Next.js is that they take away too much control from you. The most problematic part being rendering. It is notoriously difficult to integrate tools with Next.js precisely because you don't control how your pages are rendered. With vite-plugin-ssr integrating tools is simply a matter of following the official documentation of the tool you want to integrate.

While vite-plugin-ssr comes with a default routing (SSR and routing are inherently intertwined), you can actually use vite-plugin-ssr with with React Router. But the default routing should work for the vast majority of cases (and is actually simpler than React Router; thanks to SSR we can radically simplify routing).

Also, vite-plugin-ssr is a mere 1.3k LOC Vite plugin (that's a lot less than Next.js).

some tasks weren't working

There are still some rough edges here and there but I'm working on smoothing them out.

@thelinuxlich
Copy link
Owner

But if you use React Router with vite-plugin-ssr you miss the autorouting, right?

@brillout
Copy link
Author

You can use React Router and vite-plugin-ssr's routing together. For example, if you have a page with tabs and you want the tabs to have their own URL, then you can use React Router for that page. Example: https://github.com/brillout/vite-plugin-ssr/tree/master/examples/react-router

Or, you can have a single page index.page.js and use React Router for everything. That works too (although you loose code splitting).

But, in general, using React Router for an SSR app doesn't bring much value. SSR with simple route strings (e.g. /resource/:id) is mostly enough and just much simpler.

Note that Next.js doesn't support React Router which shows that route strings are mostly enough.

@thelinuxlich
Copy link
Owner

well, let's wait the Vite fix, maybe I can try again

@brillout
Copy link
Author

The latest vite-plugin-ssr version includes a fix. Build should now work.

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

No branches or pull requests

2 participants