Skip to content

Commit

Permalink
remove config since will be on the 2.0 milestone
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti committed Dec 1, 2023
1 parent d72cac9 commit ff8b4bb
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 34 deletions.
4 changes: 2 additions & 2 deletions documentation/docs/20-core-concepts/20-load.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ A `load` function that calls `await parent()` will also rerun if a parent `load`

Dependency tracking does not apply _after_ the `load` function has returned — for example, accessing `params.x` inside a nested [promise](#streaming-with-promises) will not cause the function to rerun when `params.x` changes. (Don't worry, you'll get a warning in development if you accidentally do this.) Instead, access the parameter in the main body of your `load` function.

When setting the `kit.fineGrainedSearchParamsInvalidation` option in your `svelte.config.js` to `true`, accessing a query parameter is tracked independently from the rest of the url. For example, accessing `event.url.searchParams.get("query")` inside a `load` function will make that `load` function rerun only when the `query` search param changes: Navigating from `/search?query=svelte&page=1` to `/search?query=svelte&page=2` will not rerun the load function.
Accessing a query parameter is tracked independently from the rest of the url. For example, accessing `event.url.searchParams.get("query")` inside a `load` function will make that `load` function rerun only when the `query` search param changes: Navigating from `/search?query=svelte&page=1` to `/search?query=svelte&page=2` will not rerun the load function.

### Manual invalidation

Expand Down Expand Up @@ -599,7 +599,7 @@ To summarize, a `load` function will rerun in the following situations:

- It references a property of `params` whose value has changed
- It references a property of `url` (such as `url.pathname` or `url.search`) whose value has changed. Properties in `request.url` are _not_ tracked
- It calls `url.searchParams.get`, `url.searchParams.getAll` or `url.searchParams.has` and the specific search param passed to those functions changes. Accessing other properties of searchParams will have the same effect as accessing `url.search`. When `fineGrainedSearchParamsInvalidation` is `false`, accessing _any_ search param will cause the load function to rerun.
- It calls `url.searchParams.get`, `url.searchParams.getAll` or `url.searchParams.has` and the specific search param passed to those functions changes. Accessing other properties of searchParams will have the same effect as accessing `url.search`.
- It calls `await parent()` and a parent `load` function reran
- It declared a dependency on a specific URL via [`fetch`](#making-fetch-requests) (universal load only) or [`depends`](types#public-types-loadevent), and that URL was marked invalid with [`invalidate(url)`](modules#$app-navigation-invalidate)
- All active `load` functions were forcibly rerun with [`invalidateAll()`](modules#$app-navigation-invalidateall)
Expand Down
3 changes: 1 addition & 2 deletions packages/kit/src/core/config/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ const get_defaults = (prefix = '') => ({
version: {
name: Date.now().toString(),
pollInterval: 0
},
fineGrainedSearchParamsInvalidation: false
}
}
});

Expand Down
4 changes: 1 addition & 3 deletions packages/kit/src/core/config/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,7 @@ const options = object(
version: object({
name: string(Date.now().toString()),
pollInterval: number(0)
}),
// TODO v2: remove this option (always true)
fineGrainedSearchParamsInvalidation: boolean(false)
})
})
},
true
Expand Down
1 change: 0 additions & 1 deletion packages/kit/src/core/sync/write_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { set_private_env, set_public_env } from '${runtime_directory}/shared-ser
export const options = {
app_template_contains_nonce: ${template.includes('%sveltekit.nonce%')},
csp: ${s(config.kit.csp)},
fine_grained_search_params_invalidation: ${config.kit.fineGrainedSearchParamsInvalidation},
csrf_check_origin: ${s(config.kit.csrf.checkOrigin)},
track_server_fetches: ${s(config.kit.dangerZone.trackServerFetches)},
embedded: ${config.kit.embedded},
Expand Down
6 changes: 0 additions & 6 deletions packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,6 @@ export interface KitConfig {
*/
pollInterval?: number;
};
/**
* When set to `true`, accessing `searchParams` on the `url` object tracks just that specific searchParam and not the whole URL, resulting in less load function reruns.
* This option will be removed and always be `true` in SvelteKit version 2.
* @default false
*/
fineGrainedSearchParamsInvalidation?: boolean;
}

/**
Expand Down
8 changes: 2 additions & 6 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ function kit({ svelte_config }) {
__SVELTEKIT_APP_VERSION_FILE__: s(`${kit.appDir}/version.json`),
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: s(kit.version.pollInterval),
__SVELTEKIT_DEV__: 'false',
__SVELTEKIT_EMBEDDED__: kit.embedded ? 'true' : 'false',
__SVELTEKIT_ENABLE_FINE_GRAINED_PARAMS_INVALIDATION__:
kit.fineGrainedSearchParamsInvalidation ? 'true' : 'false'
__SVELTEKIT_EMBEDDED__: kit.embedded ? 'true' : 'false'
};

if (!secondary_build_started) {
Expand All @@ -303,9 +301,7 @@ function kit({ svelte_config }) {
new_config.define = {
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0',
__SVELTEKIT_DEV__: 'true',
__SVELTEKIT_EMBEDDED__: kit.embedded ? 'true' : 'false',
__SVELTEKIT_ENABLE_FINE_GRAINED_PARAMS_INVALIDATION__:
kit.fineGrainedSearchParamsInvalidation ? 'true' : 'false'
__SVELTEKIT_EMBEDDED__: kit.embedded ? 'true' : 'false'
};

// These Kit dependencies are packaged as CommonJS, which means they must always be externalized.
Expand Down
6 changes: 1 addition & 5 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,7 @@ export function create_client(app, target) {
uses.url = true;
},
(search_param) => {
if (__SVELTEKIT_ENABLE_FINE_GRAINED_PARAMS_INVALIDATION__) {
uses.search_params.add(search_param);
} else {
uses.url = true;
}
uses.search_params.add(search_param);
}
),
async fetch(resource, init) {
Expand Down
6 changes: 1 addition & 5 deletions packages/kit/src/runtime/server/page/load_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ export async function load_server_data({
`${node.server_id}: Accessing URL properties in a promise handler after \`load(...)\` has returned will not cause the function to re-run when the URL changes`
);
}
if (__SVELTEKIT_ENABLE_FINE_GRAINED_PARAMS_INVALIDATION__) {
uses.search_params.add(search_params);
} else {
uses.url = true;
}
uses.search_params.add(search_params);
}
);

Expand Down
1 change: 0 additions & 1 deletion packages/kit/src/types/ambient-private.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ declare global {
const __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: number;
const __SVELTEKIT_DEV__: boolean;
const __SVELTEKIT_EMBEDDED__: boolean;
const __SVELTEKIT_ENABLE_FINE_GRAINED_PARAMS_INVALIDATION__: boolean;
var Bun: object;
var Deno: object;
}
Expand Down
1 change: 0 additions & 1 deletion packages/kit/src/types/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ export type SSRNodeLoader = () => Promise<SSRNode>;
export interface SSROptions {
app_template_contains_nonce: boolean;
csp: ValidatedConfig['kit']['csp'];
fine_grained_search_params_invalidation?: boolean;
csrf_check_origin: boolean;
track_server_fetches: boolean;
embedded: boolean;
Expand Down
3 changes: 1 addition & 2 deletions packages/kit/test/apps/basics/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const config = {

version: {
name: 'TEST_VERSION'
},
fineGrainedSearchParamsInvalidation: true
}
}
};

Expand Down

0 comments on commit ff8b4bb

Please sign in to comment.