solidjs / solid-start

SolidStart, the Solid app framework
https://start.solidjs.com
MIT License
5.2k stars 373 forks source link

[Bug] Netlify/Vercel deploy crashes on directly going to any route other than / in SPA mode #303

Closed vanillacode314 closed 11 months ago

vanillacode314 commented 2 years ago

Error

TypeError: event.env.getStaticHTML is not a function
    at /var/task/netlify/functions/index.js:13920:30
    at /var/task/netlify/functions/index.js:14386:29
    at /var/task/netlify/functions/index.js:14141:18
    at /var/task/netlify/functions/index.js:14406:7
    at Runtime.handler (/var/task/netlify/functions/index.js:14417:24)
    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1028:29)

Route: https://solidjs--redditlattice.netlify.app/r/wallpapers Source Code: https://github.com/vanillacode314/redditlattice/tree/solidjs

Repro: Just visit the route

Going to / and then going to any other route works but not when visiting the route directly

vanillacode314 commented 2 years ago

Currently, this is the only thing stopping me from publishing my app to prod :(

nksaraf commented 2 years ago

Thanks for reporting.. yeah feels like a bug from our side

vanillacode314 commented 2 years ago

same thing with vercel too.

vanillacode314 commented 2 years ago

I did some digging apparently its the renderAsync function it expects a getStaticHTML function but only edge mode provides that, tried edge mode but it has other problems.

vanillacode314 commented 2 years ago

I tried monkey patching the getStaticHTML to return index.html but it didn't work, reason is above my area of knowledge. Hope this might help

nksaraf commented 2 years ago

yeah that's close to the solution... I need to figure out how to get the HTML page during a request for a non-html route, im assuming this is the ssr: false mode. Maybe you can try the normal netlify adapter with ssr until we fix this, like not SPA mode.

vanillacode314 commented 2 years ago

well wouldn't for an spa index.html should be served regardless of the route?

vanillacode314 commented 2 years ago

other frameworks usually don't use serverless functions in spa mode and only serves /index.html as a static file. The user is required to redirect all 404s to /index.html to handle spa mode. usually this is as simple as copying index.html to 404.html and most hosting services pick this up

vanillacode314 commented 2 years ago

managed to find a workaround which I believe is pretty close to the solution. I added these redirect rules to my netlify site

/trpc/* /.netlify/functions/index 200
/* /index.html 200

I know the trpc one is specific to my case but I presume that solid-start would be able to generate these redirects at build time for api routes automatically

vanillacode314 commented 1 year ago

fixed

vanillacode314 commented 1 year ago

issue reappeared on updating solid-start

  "dependencies": {
    "@motionone/solid": "^10.15.5",
    "@solid-primitives/connectivity": "^0.3.10",
    "@solid-primitives/event-listener": "^2.2.8",
    "@solid-primitives/keyed": "^1.1.8",
    "@solid-primitives/map": "^0.4.2",
    "@solid-primitives/media": "^2.1.4",
    "@solid-primitives/set": "^0.4.2",
    "@solid-primitives/storage": "^1.3.7",
    "@solidjs/meta": "^0.28.2",
    "@solidjs/router": "^0.8.0",
    "@trpc/client": "10.16.0",
    "@trpc/server": "10.16.0",
    "@unocss/reset": "^0.50.4",
    "@use-gesture/vanilla": "^10.2.24",
    "api": "workspace:*",
    "clsx": "^1.2.1",
    "devalue": "^4.3.0",
    "idb-keyval": "^6.2.0",
    "motion": "^10.15.5",
    "screenfull": "^6.0.2",
    "solid-js": "1.6.14",
    "solid-start": "0.2.23",
    "solid-start-netlify": "0.2.23",
    "solid-start-node": "0.2.23",
    "ui": "workspace:*",
    "undici": "^5.21.0",
    "xstate": "^4.37.0",
    "zod": "^3.21.4",
    "zod-fetch": "^0.1.0"
  },
  "devDependencies": {
    "@babel/core": "^7.21.3",
    "@iconify-json/mdi": "^1.1.50",
    "@types/lodash-es": "^4.17.7",
    "@types/node": "^18.15.3",
    "@types/web": "^0.0.97",
    "@types/workbox-sw": "^4.3.3",
    "@unocss/preset-attributify": "^0.50.4",
    "@unocss/vite": "^0.50.4",
    "eslint": "8.36.0",
    "eslint-config-custom": "workspace:*",
    "lodash-es": "^4.17.21",
    "solid-devtools": "^0.26.0",
    "tsconfig": "workspace:*",
    "typescript": "^4.9.5",
    "unocss": "^0.50.4",
    "unplugin-auto-import": "^0.15.1",
    "vite": "^4.1.4",
    "workbox-build": "^6.5.4",
    "workbox-cli": "^6.5.4"
  }
ryansolid commented 1 year ago

I agree that we probably shouldn't be handling this and that the provider redirects should which are adapter specific and would require knowledge of ssr: false.. which we do have but how to do so without conflicting with others is interesting. I'm not sure if we can just automate this. So I'd recommend manual redirects.

In any case with manual redirects I'm a bit surprised this is an issue still. Can you confirm?

vanillacode314 commented 1 year ago

Repo: https://github.com/vanillacode314/solid-start-repro-issue-303 Deploy without manual redirects: https://dashing-croquembouche-63b3bb.netlify.app Deploy with manual redirects: https://manual-redirect--dashing-croquembouche-63b3bb.netlify.app/

Context:

The reason solid-start should be able to handle this without manual redirects is because it deploy a serverless function even in spa mode which means it can serve index.html directly from the function if the route requested is not an API route.

Another way to move forward is to drop the serverless functions completely in ssr: false which would shift the burden to the user and would act as static adapter and not support API routes (this is the approach sveltekit takes)

ryansolid commented 1 year ago

Yeah I'm pretty tempted to drop server in ssr: false. This idea of doing both was something that Nikhil thought of, but it has made things really complicated.

ryansolid commented 11 months ago

In setting up for SolidStarts next Beta Phase built on Nitro and Vinxi we are closing all PRs/Issues that will not be merged due to the system changing. If you feel your issue was closed in mistake. Feel free to re-open it after updating/testing against 0.4.x release. Thank you for your patience.

See https://github.com/solidjs/solid-start/pull/1139 for more details.