opral / inlang-paraglide-js

Tree-shakable i18n library build on the inlang ecosystem.
https://inlang.com/m/gerre34r/library-inlang-paraglideJs
33 stars 0 forks source link

[bug] Paraglide SvelteKit Adapter Reroutes fail Server-Side on Vercel #32

Closed feavel1 closed 4 days ago

feavel1 commented 6 months ago

Problem

After I upload the project to vercel, the issue occurs.

I can't visit pages like https://feavel.com/zh or https://feavel.com/zh/services.

But everything works locally. Also the local build has no issues. Maybe something with vercel cache? I don't know.

Expected behavior

I can use the lang switcher to change the language and everything works as expected. Even in local development no issues occur, no matter if it's dev or build preview. But after I upload the build to vercel, the issue occurs. I can't visit pages like https://feavel.com/zh or https://feavel.com/zh/services .

Reproduction

Go to pages like https://feavel.com/zh or https://feavel.com/zh/services

Try to switch language, and everything works again. But reloading doesn't.

Other information

Safari

macOS

Screenshot 2024-02-21 at 20 26 24

Screenshot 2024-02-21 at 20 26 16

feavel1 commented 6 months ago

Fun fact, local development has no issue. Been banging my head for a day now. Maybe someone has had same problem ?

My code repository is here https://github.com/feavel1/feavel

Should add a scope:

scope: inlang/paraglide-js

LorisSigrist commented 6 months ago

The odd thing is that it seems to work when you start out on https://feavel.com and then switch the language to zh. To me this suggests that this might be an issue with @svelte/adapter-vercel. It may not be playing nice with the reroute hook added in SvelteKit 2.3

LorisSigrist commented 6 months ago

I checked out you repo locally & built it. If you inspect .vercel/output/config.json you can see the path definitions that will be used by vercel. The reroute hook isn't being considered. This is a bug in the Vercel Adapter, I'll open an issue

feavel1 commented 6 months ago

The odd thing is that it seems to work when you start out on https://feavel.com and then switch the language to zh. To me this suggests that this might be an issue with @svelte/adapter-vercel. It may not be playing nice with the reroute hook added in SvelteKit 2.3

I am using svelte-adapter-auto svelte.config.js,maybe something with the build steps that doesn't tell Vercel that there is /{lang} that can be used...

The hook is also setup the way docs tell to. Strange

LorisSigrist commented 6 months ago

@sveltejs/adapter-auto will magically turn into @sveltejs/adapter-vercel when the build is being run inside vercel's pipeline.

I can confirm that you did set up everything correctly. This is a bug in @sveltejs/adapter-vercel & not your fault. I'll be opening an Issue in the sveltejs/kit repo about this.

In the mean time you could:

LorisSigrist commented 6 months ago

It seems to be a bit more nuanced actually. The reroute hook works on vercel, until your app starts reaching a certain bundle size. At some point the Adapter will start creating multiple Vercel Serverless functions instead of just one for the entire app. At that point it breaks

linear[bot] commented 5 months ago

PARJS-35 [bug] Paraglide SvelteKit Adapter Reroutes fail Server-Side on Vercel

feavel1 commented 6 months ago

Serverless

Thank you for testing the code and finding out what's going on. I am wondering if it is possible to rewrite the "reroute" hook so it can be used? Or maybe find a function that can be used to pre-render the page that needs to be loaded?

Wired with Vercel but here is the docs for svelte function universal-hooks-reroute

LorisSigrist commented 6 months ago

Side-stepping the reroute hooks could maybe be possible if you aren't using any translated pathnames. Try removing the reroute hook & instead adding an optional [[lang]] parameter at the base of your routes. Maybe that could work.

feavel1 commented 6 months ago

instead

Man of culture, this day was very long. Maybe the next day will shine brighter. Wish me best luck of figuring out how to solve this mysterious technology.

I have to say that taking the time to run the code and figuring out what the issue is, also suggesting what the solution is just ... very nice of you. Hope I will solve the problem.

But even if I don't , it is great to see you. Wish you all the best 🔆☀️🌞

LorisSigrist commented 3 months ago

Being worked on in https://github.com/sveltejs/kit/pull/12296

holc7 commented 1 month ago

instead

Man of culture, this day was very long. Maybe the next day will shine brighter. Wish me best luck of figuring out how to solve this mysterious technology.

I have to say that taking the time to run the code and figuring out what the issue is, also suggesting what the solution is just ... very nice of you. Hope I will solve the problem.

But even if I don't , it is great to see you. Wish you all the best 🔆☀️🌞

Have you found the solution? I have exact same problem. Once I refresh it will show 404 and it's annoying.

EDIT: I had export const prerender = true;. I removed it and now everything works.

samuelstroschein commented 4 days ago

Closing as stale.