Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow server-only load functions to return more than JSON #6318

Merged
merged 25 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use DATA_SUFFIX constant
  • Loading branch information
Rich-Harris committed Aug 28, 2022
commit 358d0ceb323f9c53a2bfc6ef1acd9f742eadf1b5
3 changes: 2 additions & 1 deletion packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Root from '__GENERATED__/root.svelte';
import { nodes, dictionary, matchers } from '__GENERATED__/client-manifest.js';
import { HttpError, Redirect } from '../control.js';
import { stores } from './singletons.js';
import { DATA_SUFFIX } from '../../constants.js';

const SCROLL_KEY = 'sveltekit:scroll';
const INDEX_KEY = 'sveltekit:index';
Expand Down Expand Up @@ -1364,7 +1365,7 @@ let data_id = 1;
*/
async function load_data(url, invalid) {
const data_url = new URL(url);
data_url.pathname += `${url.pathname.endsWith('/') ? '' : '/'}__data.js`;
data_url.pathname = url.pathname.replace(/\/$/, '') + DATA_SUFFIX;
data_url.searchParams.set('__invalid', invalid.map((x) => (x ? 'y' : 'n')).join(''));
data_url.searchParams.set('__id', String(data_id++));

Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/runtime/server/page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { error, json } from '../../../exports/index.js';
import { compact } from '../../../utils/array.js';
import { normalize_error } from '../../../utils/error.js';
import { load_data, load_server_data } from './load_data.js';
import { DATA_SUFFIX } from '../../../constants.js';

/**
* @typedef {import('./types.js').Loaded} Loaded
Expand Down Expand Up @@ -103,7 +104,7 @@ export async function render_page(event, route, page, options, state, resolve_op
}

const should_prerender_data = nodes.some((node) => node?.server);
const data_pathname = `${event.url.pathname.replace(/\/$/, '')}/__data.js`;
const data_pathname = event.url.pathname.replace(/\/$/, '') + DATA_SUFFIX;

// it's crucial that we do this before returning the non-SSR response, otherwise
// SvelteKit will erroneously believe that the path has been prerendered,
Expand Down