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

Throw an error (or warn?) if using adapter-static with invalid routes #4287

Closed
Rich-Harris opened this issue Mar 10, 2022 · 5 comments
Closed
Labels
feature request New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc.
Milestone

Comments

@Rich-Harris
Copy link
Member

Describe the problem

adapter-static is a source of confusion for people who believe that it allows you to somehow publish an app with dynamic server rendering and/or endpoints with POST/PATCH/DELETE/etc handlers to GitHub pages.

Describe the proposed solution

I haven't thought deeply about the implementation, beyond this:

  • If pages are left unprerendered, adapter-static should throw an error unless fallback was specified.
  • If an endpoint has non-GET handlers, adapter-static should throw an error regardless of whether fallback was specified.

Alternatives considered

More complete documentation, and spending more time dealing with issues

Importance

would make my life easier

Additional Information

No response

@Mlocik97
Copy link
Contributor

I'm for warn, but not error... Sometimes I want to have implemented endpoints with post/patch/delete or hooks and other dynamic server stuff, and use adapter-static for example if you want to implement website (using node resp. adapter-node or some server-less one), but at the same time use same source codes to generate static assets for for example electron/neutralino app, or nativescript mobile app. Then I have two adapters in config, and two build commands that build for website or app based on for example process.env. So error would "break" this. But there should be warn definitelly.

@Rich-Harris
Copy link
Member Author

Prerendering happens automatically, regardless of what adapter you're using. In the rare case that an adapter doesn't specify where the prerendered output should be copied to, it's accessible at .svelte-kit/output/prerendered, so I'm not sure there's I understand why there's a reason to run adapter-static alongside a separate adapter.

@benmccann benmccann added this to the 1.0 milestone Mar 13, 2022
@benmccann benmccann added p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. feature request New feature or request labels Mar 16, 2022
@Spenhouet
Copy link

I'm a bit confused about what's supposed to work and what not.

I'm using the page routing (via slugs in file names), matchers and page endpoints (only GET). It's working when starting the dev environment but not when building it with adapter-static and deploying it to gh-pages.
Which of these three features should generally work with adapter-static? Are there any caveats?

Not going into any specifics here. If you say all three features generally should work, I will dig deeper and eventually open an issue to sort it out.

@Spenhouet
Copy link

Spenhouet commented Jun 9, 2022

Okay, I can give some answers to that myself. All three functions also work with adapter-static.

For page routing and page endpoints one just needs to use prerender.entries in the svelte.config.js.

For example for items/[id].svelte and items/[id].js:

kit: {
  prerender: {
	  default: true,
	  entries: ['*', '/items/1'],
  },
}

The list of entries to prerender can actually be generated similar to how it's done in this blog post: https://reecemay.me/articles/tip_sveltekit_static_pages_with_prismic/

For the matcher one needs to add a fallback for pages not matching the matcher and a fallback for slugs which match but have no prerendered page.
To make a fallback for slugs not matching the matcher, one can define a items/[...nomatch].svelte page.
To make a fallback for none existing slugs I needed todefine a items/__error.svelte page and set fallback: '404.html' in svelte.config.js for adapter-static. With fallback: null it does not seem to work (might be a bug?).

It would definitely help to mention these details in the docs on routing with respect to adapter-static.

@Mlocik97
Copy link
Contributor

Mlocik97 commented Jun 9, 2022

Prerendering happens automatically, regardless of what adapter you're using. In the rare case that an adapter doesn't specify where the prerendered output should be copied to, it's accessible at .svelte-kit/output/prerendered, so I'm not sure there's I understand why there's a reason to run adapter-static alongside a separate adapter.

sometimes I have reason to not prerender (for adapter-node), mainly if it shows different content to different users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc.
Projects
None yet
Development

No branches or pull requests

4 participants