Skip to content

Commit 1e22df1

Browse files
committed
Add option to disable client-side rendering
1 parent 6b7ad47 commit 1e22df1

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

packages/kit/src/api/build/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ export async function build(config) {
340340
amp: ${config.amp},
341341
only_prerender,
342342
app_dir: ${s(config.appDir)},
343+
rendering: this.config.rendering,
343344
host: ${s(config.host)},
344345
host_header: ${s(config.hostHeader)},
345346
get_stack: error => error.stack,

packages/kit/src/api/dev/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ class Watcher extends EventEmitter {
246246
only_prerender: false,
247247
start_global: this.config.startGlobal,
248248
app_dir: this.config.appDir,
249+
rendering: this.config.rendering,
249250
host: this.config.host,
250251
host_header: this.config.hostHeader,
251252
get_stack: (error) =>

packages/kit/src/api/load_config/index.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ test('fills in defaults', () => {
2727
force: false,
2828
pages: ['*']
2929
},
30+
rendering: {
31+
client: true
32+
},
3033
target: null,
3134
startGlobal: null
3235
});
@@ -85,6 +88,9 @@ test('fills in partial blanks', () => {
8588
force: false,
8689
pages: ['*']
8790
},
91+
rendering: {
92+
client: true
93+
},
8894
startGlobal: null,
8995
target: null
9096
});

packages/kit/src/api/load_config/options.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export default {
6464
}
6565
},
6666

67+
rendering: {
68+
default: {
69+
client: expect_boolean(true)
70+
}
71+
},
72+
6773
// used for testing
6874
startGlobal: expect_string(null),
6975

packages/kit/src/renderer/page.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,14 @@ async function get_response({ request, options, $session, route, status = 200, e
267267
...css_deps.map((dep) => `<link rel="stylesheet" href="${dep}">`)
268268
].join('\n\t\t\t');
269269

270-
const init = options.amp
271-
? `
270+
let init = '';
271+
if (options.amp) {
272+
init = `
272273
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
273274
<noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
274-
<script async src="https://cdn.ampproject.org/v0.js"></script>`
275-
: `
275+
<script async src="https://cdn.ampproject.org/v0.js"></script>`;
276+
} else if (options.rendering.client) {
277+
init = `
276278
<script type="module">
277279
import { start } from '${options.paths.assets}/${options.app_dir}/${options.entry}';
278280
${options.start_global ? `window.${options.start_global} = () => ` : ''}start({
@@ -284,12 +286,14 @@ async function get_response({ request, options, $session, route, status = 200, e
284286
session: ${serialized_session}
285287
});
286288
</script>`;
289+
}
287290

288291
const head = [rendered.head, links, init].join('\n\n');
289292

290-
const body = options.amp
291-
? rendered.html
292-
: `${rendered.html}
293+
const body =
294+
options.amp || !options.rendering.client
295+
? rendered.html
296+
: `${rendered.html}
293297
294298
${serialized_data
295299
.map(({ url, payload }) => `<script type="svelte-data" url="${url}">${payload}</script>`)

0 commit comments

Comments
 (0)