-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
vite-plugin-vercel #222
Comments
Got is started if someone wants to pick it up: Requires Node 16
|
Neat. Let me know if you are up for creating a little Vite plugin wrapping this. We'll discuss the high-level design of it. |
I have a bit too much on my plate at the moment to work on this, but will
let you know if I get some spare time. I guess we will be refining the
deployment process anyway before going to production.
…On Thu, Dec 02, 2021 at 10:02 PM, Rom Brillout ***@***.***> wrote:
Neat.
Let me know if you are up for creating a little Vite plugin wrapping this.
We'll discuss the high-level design of it.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#222 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJBUMS2QBAY42XIY3GJPXN3UO7NGTANCNFSM5JEIKW7A>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
👍 |
I'm currently beginning to work on this subject, mostly because I need this for ISR. Should we have a underlying package not tied to
Should
And regarding new ISR feature:
|
I agree and There is already some prior work to deploy vps with Vercel's FS api: https://github.com/brillout/vite-plugin-ssr/blob/master/examples/vercel/vercel/deploy.sh. As for the rest, sounds good. I'm very much looking forward to this. Feel free to show me a draft. |
I realise that export default defineConfig({
plugins: [ssr({
prerender: true
})],
});
|
Yes |
Here is the repo with the first working tests. What does it do for now (or don't):
Deployed at https://test-vite-vercel-plugin.vercel.app/ |
Hey @magne4000 that repo seems to be private ;) |
oups 🤭. Fixed |
How about this? // vite.config.js
export default {
// These settings can be set by the user or by another plugin such as vps
vercel: {
isr: {
initialRevalidateSeconds: 30,
prerender: /* prerender function called by vite-plugin-vercel */,
},
apiEndpoints: ['./api/foo.js'],
}
} vps can set some of these settings on behalf of the user, such as:
This allows vpc to be decoupled from vps. It also enables decoupled development: what we can do is to first work on an example where these settings are all set by the user's Thoughts? Also thoughts about vitejs/vite#5936? I gave you full privilege for https://www.npmjs.com/package/vite-plugin-vercel. |
Using
👍
I like the idea! We'll have to dig a little further, like how can I add specific behaviour (like redirect behaviour, setcookie, custom headers, etc. based on pageContext)? (Writing this I realize that in the handler, the only thing I want to customize are HTTP responses)
We should even be able to easily share logic between dev (e.g. express) and prod (e.g. vercel)
I'll probably have time next week to try that
Yep, It would be easier to write this plugin if we had a single process, that's sure
🙇 |
The thin wrapper around vps's // /pages/product.page.js
// Overrides the default
export const initialRevalidateSeconds = 10
// The usual stuff
export { Page }
// ...
@cyco130 is actually working on that (https://github.com/hattipjs/hattip — there isn't any documentation yet). |
Prerendering code uses both |
Yes. Ideally, and I think it's possible, everything would just work without the user having to do anything.
I agree. For the current prototyping phase, if you want for the sake of dev speed, we can store this prerender function at |
This sounds very exciting. Thanks for everyone who's helping out with this, and we look forward to supporting y'all and Vite from our side. |
@rauchg Much appreciated 👍. We actually have some question over there vercel/vercel#7573. |
I made some good progress:
Updated live demo with SSR/SSG/ISR: https://test-vite-vercel-plugin.vercel.app/ TODOFor a beta version
After beta
|
Neat 👌.
Little typo here https://github.com/magne4000/test-vite-vercel-plugin/blob/41af424c620b14c61697ea838404dfc952992474/packages/vercel/src/types.ts#L117 ( You are using vps internals which is fine but we should add an integration test, like we already have for Cloudflare Workers (e.g. https://github.com/brillout/vite-plugin-ssr/blob/master/examples/cloudflare-workers/.test-wrangler.spec.ts). Is there a way to try a Vercel deploy locally without actually publishing the app? |
Sadly no. What I was thinking of doing is test the content of output generated files. Not the ideal test scenario, but it would ensure good regression tests at least. |
My thinking is that a user that does only SSG wouldn't use Vercel in the first place. So it seems to me that prerendering is always tied to ISR? And, on the flip side, if the user doesn't define a prerender function then he doesn't do ISR. Ok, and yes, regression tests should be enough for now. |
I can see use cases where you have a mix of SSG and SSR but not necessarily ISR. And for those cases you'll need a prerender function. It assumes less about user's intententions to put the prerender function in something more generic than
Correct, that's handled with the help of meaningful assert calls right now. It's in fact not that clear in Vercel's doc that you actually need to prerender a file for it to also be ISR capable |
Makes sense. How about flattening then? I.e. defining |
Indeed. Simpler I don't see drawbacks as the configuration is quite minimal, this is probably the way to go 👍 |
We need to define the behavior when using Route functions are called on every request:
We could call route functions only when a route does not match any other (fallback route):
We could throw an error when using route functions with
|
Yes and no. They are called for every URL in order to determine the And, yes, on the server-side they are also called for every request, but only to determine So I don't think route functions are any problem for ISR. Note that route functions can be used today with SSG (by using the |
And this is actually only the case for SSR. For SSG, there is no server-side JavaScript execution.
|
Ok thanks, I still need some fallback rule then I guess |
AFAICT, the only logic here is: is this a URL of a static asset? Then serve that static asset, otherwise do SSR. So you somehow need to probe whether the URL was already pre-rendered. |
That's indeed what the fallback rule is for, ignore |
You can check all use cases I could think of https://test-vite-vercel-plugin.vercel.app/ |
I don't see why route functions need special treatment. I don't see a difference between a route string |
I see what you mean. I was mislead by the fact I had trouble having a working catch-all rule through |
I have another ISR specific use case. Lets say I have the following prerender function: export function prerender() {
return ['/product/a', '/product/b']
} If I access those, statically generated files are served, and potentially they are also updated on the background if But what happens if I access For that, I need a way to guess which URLs need to be ISR at build time, even when not prerendered (in this case I could leverage
We could also have some new exported value just for ISR routes
Relevant for this use case |
I assume that the page would be SSR'd before being added to the ISR cache. In that case a custom export should do the trick: // product.page.js
export const isr = true You can then read |
While the |
Yes, but I need to generate a route regex at build time that describes all possible ISR routes. I can't just tell Vervel to cache a page during SSR rendering |
I'd suggest requiring the user to not use route functions when using ISR. Anyways, route functions are usually used for dynamically determining which page should be rendered (e.g. auth header cookie) which doesn't make sense with ISR. |
Agreed. So to be sure we're on the same page, here's how I see all of this working: ISR enabled if:
|
Agreed. One small nitpick:
How about if |
I think it would be better to remove the default |
The use case I've in mind for ISR is Stack Overflow or Reddit. Having millions of pages that cannot be pre-rendered at build-time. For these websites I can see a default value to make sense and |
Good point, let's go for |
|
Done https://github.com/magne4000/vite-plugin-vercel by @magne4000 💯. It even supports ISR. |
vite-plugin-ssr already supports Vercel https://vite-plugin-ssr.com/vercel but it would be lovely to have a
vite-plugin-vercel
so that the entire Vite ecosystem can benefit.Discussoin about this: https://discord.com/channels/815937377888632913/815937377888632916/915547793987350548
I've secured the npm package and I'm happy to give it away.
The text was updated successfully, but these errors were encountered: