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

use enumerable: false for temporary no-longer-exists getters #6105

Merged
merged 3 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/ninety-walls-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

use `enumerable: false` on "[x] no longer exists" getters so that they are not triggered by spreading
36 changes: 23 additions & 13 deletions packages/kit/src/runtime/app/stores.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,37 @@ export function stores() {
export const getStores = () => {
const stores = getContext('__svelte__');

return {
const readonly_stores = {
page: {
subscribe: stores.page.subscribe
},
navigating: {
subscribe: stores.navigating.subscribe
},
// TODO remove this (for 1.0? after 1.0?)
// @ts-expect-error - deprecated, not part of type definitions, but still callable
get preloading() {
console.error('stores.preloading is deprecated; use stores.navigating instead');
return {
subscribe: stores.navigating.subscribe
};
},
get session() {
removed_session();
return {};
},
updated: stores.updated
};

// TODO remove this for 1.0
Object.defineProperties(readonly_stores, {
preloading: {
get() {
console.error('stores.preloading is deprecated; use stores.navigating instead');
return {
subscribe: stores.navigating.subscribe
};
},
enumerable: false
},
session: {
get() {
removed_session();
return {};
},
enumerable: false
}
});

return readonly_stores;
};

/** @type {typeof import('$app/stores').page} */
Expand Down
43 changes: 27 additions & 16 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,25 +583,36 @@ export function create_client({ target, base, trailing_slash }) {
// does await parent() inside an if branch which wasn't executed yet.
uses.parent = true;
return parent;
}
};

// TODO remove this for 1.0
Object.defineProperties(load_input, {
props: {
get() {
throw new Error(
'@migration task: Replace `props` with `data` stuff https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292693'
);
},
enumerable: false
},
// @ts-expect-error
get props() {
throw new Error(
'@migration task: Replace `props` with `data` stuff https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292693'
);
},
get session() {
// TODO remove this for 1.0
throw new Error(
'session is no longer available. See https://github.com/sveltejs/kit/discussions/5883'
);
session: {
get() {
throw new Error(
'session is no longer available. See https://github.com/sveltejs/kit/discussions/5883'
);
},
enumerable: false
},
get stuff() {
throw new Error(
'@migration task: Remove stuff https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292693'
);
stuff: {
get() {
throw new Error(
'@migration task: Remove stuff https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292693'
);
},
enumerable: false
}
};
});

if (import.meta.env.DEV) {
try {
Expand Down
22 changes: 15 additions & 7 deletions packages/kit/src/runtime/server/page/load_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,31 @@ export async function load_data({ event, fetcher, node, parent, server_data_prom
return server_data;
}

const data = await node.shared.load.call(null, {
const load_input = {
url: state.prerendering ? new PrerenderingURL(event.url) : new LoadURL(event.url),
params: event.params,
data: server_data,
routeId: event.routeId,
get session() {
// TODO remove for 1.0
throw new Error(
'session is no longer available. See https://github.com/sveltejs/kit/discussions/5883'
);
},
fetch: fetcher,
setHeaders: event.setHeaders,
depends: () => {},
parent
};

// TODO remove this for 1.0
Object.defineProperties(load_input, {
session: {
get() {
throw new Error(
'session is no longer available. See https://github.com/sveltejs/kit/discussions/5883'
);
},
enumerable: false
}
});

const data = await node.shared.load.call(null, load_input);

return data ? unwrap_promises(data) : null;
}

Expand Down