Skip to content

Commit

Permalink
use vite define to access fine grained config
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti committed Nov 30, 2023
1 parent 56b50d5 commit d72cac9
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 19 deletions.
8 changes: 6 additions & 2 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ 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_EMBEDDED__: kit.embedded ? 'true' : 'false',
__SVELTEKIT_ENABLE_FINE_GRAINED_PARAMS_INVALIDATION__:
kit.fineGrainedSearchParamsInvalidation ? 'true' : 'false'
};

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

// These Kit dependencies are packaged as CommonJS, which means they must always be externalized.
Expand Down
5 changes: 2 additions & 3 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ function native_navigation(url) {
/**
* @param {import('./types.js').SvelteKitApp} app
* @param {HTMLElement} target
* @param {boolean} fine_grained_search_params_invalidation
* @returns {import('./types.js').Client}
*/
export function create_client(app, target, fine_grained_search_params_invalidation) {
export function create_client(app, target) {
const routes = parse(app);

const default_layout_loader = app.nodes[0];
Expand Down Expand Up @@ -486,7 +485,7 @@ export function create_client(app, target, fine_grained_search_params_invalidati
uses.url = true;
},
(search_param) => {
if (fine_grained_search_params_invalidation) {
if (__SVELTEKIT_ENABLE_FINE_GRAINED_PARAMS_INVALIDATION__) {
uses.search_params.add(search_param);
} else {
uses.url = true;
Expand Down
5 changes: 2 additions & 3 deletions packages/kit/src/runtime/client/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import { init } from './singletons.js';
/**
* @param {import('./types.js').SvelteKitApp} app
* @param {HTMLElement} target
* @param {boolean} fine_grained_search_params_invalidation
* @param {Parameters<import('./types.js').Client['_hydrate']>[0]} [hydrate]
*/
export async function start(app, target, fine_grained_search_params_invalidation, hydrate) {
export async function start(app, target, hydrate) {
if (DEV && target === document.body) {
console.warn(
'Placing %sveltekit.body% directly inside <body> is not recommended, as your app may break for users who have certain browser extensions installed.\n\nConsider wrapping it in an element:\n\n<div style="display: contents">\n %sveltekit.body%\n</div>'
);
}

const client = create_client(app, target, fine_grained_search_params_invalidation);
const client = create_client(app, target);

init({ client });

Expand Down
3 changes: 1 addition & 2 deletions packages/kit/src/runtime/server/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ export async function render_data(
}
return data;
},
track_server_fetches: options.track_server_fetches,
fine_grained_search_params_invalidation: options.fine_grained_search_params_invalidation
track_server_fetches: options.track_server_fetches
});
} catch (e) {
aborted = true;
Expand Down
3 changes: 1 addition & 2 deletions packages/kit/src/runtime/server/page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ export async function render_page(event, page, options, manifest, state, resolve
}
return data;
},
track_server_fetches: options.track_server_fetches,
fine_grained_search_params_invalidation: options.fine_grained_search_params_invalidation
track_server_fetches: options.track_server_fetches
});
} catch (e) {
load_error = /** @type {Error} */ (e);
Expand Down
6 changes: 2 additions & 4 deletions packages/kit/src/runtime/server/page/load_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { validate_depends } from '../../shared.js';
* node: import('types').SSRNode | undefined;
* parent: () => Promise<Record<string, any>>;
* track_server_fetches: boolean;
* fine_grained_search_params_invalidation: boolean | undefined;
* }} opts
* @returns {Promise<import('types').ServerDataNode | null>}
*/
Expand All @@ -21,8 +20,7 @@ export async function load_server_data({
node,
parent,
// TODO 2.0: Remove this
track_server_fetches,
fine_grained_search_params_invalidation
track_server_fetches
}) {
if (!node?.server) return null;

Expand Down Expand Up @@ -54,7 +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 (fine_grained_search_params_invalidation) {
if (__SVELTEKIT_ENABLE_FINE_GRAINED_PARAMS_INVALIDATION__) {
uses.search_params.add(search_params);
} else {
uses.url = true;
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/page/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export async function render_response({
${properties.join(',\n\t\t\t\t\t\t')}
};`);

const args = ['app', 'element', `${options.fine_grained_search_params_invalidation}`];
const args = ['app', 'element'];

blocks.push('const element = document.currentScript.parentElement;');

Expand Down
3 changes: 1 addition & 2 deletions packages/kit/src/runtime/server/page/respond_with_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export async function respond_with_error({
state,
node: default_layout,
parent: async () => ({}),
track_server_fetches: options.track_server_fetches,
fine_grained_search_params_invalidation: options.fine_grained_search_params_invalidation
track_server_fetches: options.track_server_fetches
});

const server_data = await server_data_promise;
Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/types/ambient-private.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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

0 comments on commit d72cac9

Please sign in to comment.