Skip to content

Commit

Permalink
move config.kit.hydrate and config.kit.router to config.kit.browser (#…
Browse files Browse the repository at this point in the history
…3578)

* move config.kit.hydrate and config.kit.router to config.kit.browser

* changeset
  • Loading branch information
Rich-Harris committed Jan 29, 2022
1 parent 69124d8 commit 9e1386e
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-dots-hang.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Move config.kit.hydrate and config.kit.router to config.kit.browser
2 changes: 1 addition & 1 deletion packages/kit/src/core/build/build_client.js
Expand Up @@ -87,7 +87,7 @@ export async function build_client({
extensions: config.extensions,
emitCss: !config.kit.amp,
compilerOptions: {
hydratable: !!config.kit.hydrate
hydratable: !!config.kit.browser.hydrate
}
})
]
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/core/build/build_server.js
Expand Up @@ -79,7 +79,7 @@ export class App {
error.stack = this.options.get_stack(error);
},
hooks,
hydrate: ${s(config.kit.hydrate)},
hydrate: ${s(config.kit.browser.hydrate)},
manifest,
method_override: ${s(config.kit.methodOverride)},
paths: { base, assets },
Expand All @@ -88,7 +88,7 @@ export class App {
read,
root,
service_worker: ${has_service_worker ? "base + '/service-worker.js'" : 'null'},
router: ${s(config.kit.router)},
router: ${s(config.kit.browser.router)},
target: ${s(config.kit.target)},
template,
template_contains_nonce: ${template.includes('%svelte.nonce%')},
Expand Down Expand Up @@ -217,7 +217,7 @@ export async function build_server(
svelte({
extensions: config.extensions,
compilerOptions: {
hydratable: !!config.kit.hydrate
hydratable: !!config.kit.browser.hydrate
}
})
],
Expand Down
10 changes: 7 additions & 3 deletions packages/kit/src/core/config/index.spec.js
Expand Up @@ -14,6 +14,10 @@ const get_defaults = (prefix = '') => ({
adapter: null,
amp: false,
appDir: '_app',
browser: {
hydrate: true,
router: true
},
csp: {
mode: 'auto',
directives: {
Expand Down Expand Up @@ -61,7 +65,7 @@ const get_defaults = (prefix = '') => ({
floc: false,
headers: undefined,
host: undefined,
hydrate: true,
hydrate: undefined,
inlineStyleThreshold: 0,
methodOverride: {
parameter: '_method',
Expand All @@ -88,8 +92,8 @@ const get_defaults = (prefix = '') => ({
pages: undefined
},
protocol: undefined,
router: true,
ssr: null,
router: undefined,
ssr: undefined,
target: null,
trailingSlash: 'never'
}
Expand Down
70 changes: 35 additions & 35 deletions packages/kit/src/core/config/options.js
Expand Up @@ -57,6 +57,11 @@ const options = object(
return input;
}),

browser: object({
hydrate: boolean(true),
router: boolean(true)
}),

csp: object({
mode: list(['auto', 'hash', 'nonce']),
directives: object({
Expand Down Expand Up @@ -106,24 +111,19 @@ const options = object(
floc: boolean(false),

// TODO: remove this for the 1.0 release
headers: validate(undefined, (input, keypath) => {
if (typeof input !== undefined) {
throw new Error(
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
);
}
}),
headers: error(
(keypath) =>
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
),

// TODO: remove this for the 1.0 release
host: validate(undefined, (input, keypath) => {
if (typeof input !== undefined) {
throw new Error(
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
);
}
}),
host: error(
(keypath) =>
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
),

hydrate: boolean(true),
// TODO remove for 1.0
hydrate: error((keypath) => `${keypath} has been moved to config.kit.browser.hydrate`),

inlineStyleThreshold: number(0),

Expand Down Expand Up @@ -225,23 +225,17 @@ const options = object(
}),

// TODO: remove this for the 1.0 release
pages: validate(undefined, (input, keypath) => {
if (typeof input !== undefined) {
throw new Error(`${keypath} has been renamed to \`entries\`.`);
}
})
pages: error((keypath) => `${keypath} has been renamed to \`entries\`.`)
}),

// TODO: remove this for the 1.0 release
protocol: validate(undefined, (input, keypath) => {
if (typeof input !== undefined) {
throw new Error(
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
);
}
}),
protocol: error(
(keypath) =>
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
),

router: boolean(true),
// TODO remove for 1.0
router: error((keypath) => `${keypath} has been moved to config.kit.browser.router`),

routes: fun((filepath) => !/(?:(?:^_|\/_)|(?:^\.|\/\.)(?!well-known))/.test(filepath)),

Expand All @@ -251,13 +245,10 @@ const options = object(
}),

// TODO remove this for 1.0
ssr: validate(null, (input) => {
if (input !== undefined) {
throw new Error(
'config.kit.ssr has been removed — use the handle hook instead: https://kit.svelte.dev/docs#hooks-handle'
);
}
}),
ssr: error(
(keypath) =>
`${keypath} has been removed — use the handle hook instead: https://kit.svelte.dev/docs#hooks-handle'`
),

target: string(null),

Expand Down Expand Up @@ -436,4 +427,13 @@ function assert_string(input, keypath) {
}
}

/** @param {(keypath?: string) => string} fn */
function error(fn) {
return validate(undefined, (input, keypath) => {
if (input !== undefined) {
throw new Error(fn(keypath));
}
});
}

export default options;
2 changes: 1 addition & 1 deletion packages/kit/src/core/dev/index.js
Expand Up @@ -63,7 +63,7 @@ export async function dev({ cwd, port, host, https, config }) {
extensions: config.extensions,
emitCss: !config.kit.amp,
compilerOptions: {
hydratable: !!config.kit.hydrate
hydratable: !!config.kit.browser.hydrate
}
}),
await create_plugin(config, cwd)
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/core/dev/plugin.js
Expand Up @@ -245,7 +245,7 @@ export async function create_plugin(config, cwd) {
});
},
hooks,
hydrate: config.kit.hydrate,
hydrate: config.kit.browser.hydrate,
manifest,
method_override: config.kit.methodOverride,
paths: {
Expand All @@ -256,7 +256,7 @@ export async function create_plugin(config, cwd) {
prerender: config.kit.prerender.enabled,
read: (file) => fs.readFileSync(path.join(config.kit.files.assets, file)),
root,
router: config.kit.router,
router: config.kit.browser.router,
target: config.kit.target,
template: ({ head, body, assets, nonce }) => {
return (
Expand Down
6 changes: 4 additions & 2 deletions packages/kit/types/config.d.ts
Expand Up @@ -118,6 +118,10 @@ export interface Config {
adapter?: Adapter;
amp?: boolean;
appDir?: string;
browser?: {
hydrate?: boolean;
router?: boolean;
};
csp?: {
mode?: 'hash' | 'nonce' | 'auto';
directives?: CspDirectives;
Expand All @@ -131,7 +135,6 @@ export interface Config {
template?: string;
};
floc?: boolean;
hydrate?: boolean;
inlineStyleThreshold?: number;
methodOverride?: {
parameter?: string;
Expand All @@ -154,7 +157,6 @@ export interface Config {
entries?: string[];
onError?: PrerenderOnErrorValue;
};
router?: boolean;
routes?: (filepath: string) => boolean;
serviceWorker?: {
register?: boolean;
Expand Down

0 comments on commit 9e1386e

Please sign in to comment.