Skip to content

SPA mode#1181

Merged
Rich-Harris merged 18 commits intomasterfrom
gh-754
Apr 23, 2021
Merged

SPA mode#1181
Rich-Harris merged 18 commits intomasterfrom
gh-754

Conversation

@Rich-Harris
Copy link
Copy Markdown
Member

Closes #754.

With this, we can specify a fallback page when using adapter-static. This page contains no content, but will load the SvelteKit app and invoke the router, making it suitable as a 200.html with e.g. Surge, or an index.html with sirv with opts.single.

If a fallback is specified, adapter-static won't forcibly prerender every page, just the ones with prerender = true.

I added a test suite to adapter-static.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts

Copy link
Copy Markdown
Member

@benmccann benmccann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to make lots of people super happy! Big announcement for the Summit 😄

Do you think it's worth filing an issue about force disabling SSR as well? #754 (comment)


return adapter;
};
import commonjs from './index.cjs';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be worth adding a comment here explaining why we need to use CommonJS with an ESM wrapper

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realised there's actually no benefit to this file — removed

"format": "prettier --write . --config ../../.prettierrc --ignore-path .gitignore",
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore"
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
"test": "rm -rf test/apps/*/build && uvu test test.js"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1183 this change can make test work in windows

@Rich-Harris
Copy link
Copy Markdown
Member Author

Do you think it's worth filing an issue about force disabling SSR as well?

I'd rather wait for that to come up organically — I would rather we investigate alternatives (like static analysis) before providing an 'eject' button that is likely to be misused. People will just forcibly disable SSR as soon as they run into the smallest SSR problem if the option is available to them, rather than working through the problem and preserving SSR-ability where possible. That would be bad stewardship on our part.

@Rich-Harris Rich-Harris merged commit 4131467 into master Apr 23, 2021
@Rich-Harris Rich-Harris deleted the gh-754 branch April 23, 2021 12:11
@@ -1,4 +1,4 @@
module.exports = function ({ pages = 'build', assets = 'build' } = {}) {
module.exports = function ({ pages = 'build', assets = pages, fallback = null } = {}) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this file need to be renamed to .cjs?

Copy link
Copy Markdown
Contributor

@ivoreis ivoreis Apr 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@btakita
Copy link
Copy Markdown

btakita commented Jul 16, 2021

I have a requirement package an app using the file:// protocol, meaning there is no web server. I would love svelte kit to have SSR-less SPA capability. I could use Routify & Sapper but would rather use Svelte Kit to have both a PWA & a file:// based SPA.

@benmccann
Copy link
Copy Markdown
Member

@btakita the issue to track that is #907

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

True SPA mode

6 participants