zdenham / next-static-utils

Tooling to host Next.js websites with app router statically
12 stars 0 forks source link

Working with CAPACITOR JS #3

Closed alanxp closed 6 days ago

alanxp commented 1 week ago

Got it working, however when using cpaacitor js where we use the exported "out" directory into webview, i ran into this error in xcode

[error] - Failed to fetch RSC payload for capacitor://localhost/admin/regions/65d2cd8d281b553da132e9be.

image

zdenham commented 1 week ago

Are you able to isolate this issue to something with next-static-utils? I'm not very familiar with capacitor, but would like to understand your use case a bit more

alanxp commented 1 week ago

Are you able to isolate this issue to something with next-static-utils? I'm not very familiar with capacitor, but would like to understand your use case a bit more

image

I believe because it is expecting to have the page 65d2cd8d..html

The use case is simply export all static html site into a webview that capacitor has to show it as an "app" for android/ios. All it needs is the static html for it to work.

I can do it with Sveltekit Static Export, but can't seem to get it with Next.JS

zdenham commented 1 week ago

Are you using the useDynamicParams hook? or getStaticParams on your pages? We don't support using getStaticParams. Not sure I can help without more information unfortunately. If you are able to share a repo / steps to reproduce I can look into it

alanxp commented 1 week ago

Are you using the useDynamicParams hook? or getStaticParams on your pages? We don't support using getStaticParams

App Router... using useDynamicParams ofc. What capacitor does is if the link is a href="/regions/randomObjectIdHere123.html" it expects a randomObjectIdHere123.html, it could "simulate" the route next-static-fallback at least.

zdenham commented 1 week ago

Ah I see. So this seems like a capacitor specific issue that is incompatible with our approach.

We generate a "fallback" page and fetch data client side. If capacitor enforces that all pages need to exist, you'll need to either

  1. Generate all of your pages at build time using next.js generateStaticParams or
  2. If capacitor supports it, pass data as a query param e.g. /regions?objectId=[yourId]

I'd recommend option 2 if possible, because in a webview pretty urls aren't as important.

zdenham commented 6 days ago

going to close this issue for now, as we likely won't be able to support capacitor with our current approach--please lmk if you end up getting this resolved

alanxp commented 6 days ago

As far as i know Sveltekit exports only 1 index.html and the rest of routes and pages are with javascript. So its basicly a SPA. I wonder if its possible to make a version that could change the hrefs to the fallback page so i wont get like the 404 error and fetched data thro the fallback (client side)