Skip to content

Commit

Permalink
use enumerable: false for temporary no-longer-exists getters (#6105)
Browse files Browse the repository at this point in the history
* use enumerable: false for temporary no-longer-exists getters

* add changeset

* typo
  • Loading branch information
Conduitry authored Aug 20, 2022
1 parent ddd69c4 commit b335f38
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 36 deletions.
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

0 comments on commit b335f38

Please sign in to comment.