-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
merge resolve
options when using sequence
#6401
Conversation
🦋 Changeset detectedLatest commit: c7081b7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
resolve
options when using sequence
are there docs that should be updated or added to? |
had a crack at that in 3862c84 |
How about https://kit.svelte.dev/docs/modules#sveltejs-kit-hooks ? I was guessing it would need to be updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels weird to me that transformPageChunk
is not called in order (last is first instead of last). Is there a reason to do it like this?
Ah, dangit — I thought adding the description to the source code would update the docs, forgot I needed to update
It's analogous to calling |
Yes, but because it's an array I read this left-to-right/top-to-bottom, not the other way around. Is there a situation where switching this behavior is strange/wrong? |
Is c7081b7 not clear enough? I'm not sure what more we can do.
I mean... yeah! You'd literally be changing the semantics to // src/hooks.js
async function increment({ event, resolve }) {
const response = await resolve(event, {
transformPageChunk: ({ html }) => {
return html.replace(/number: (\d+)/g, (_match, n) => `number: ${+n + 1}`);
}
});
const number = response.headers.get('x-number');
response.headers.set('x-number', String(+number + 1));
return response;
}
async function double({ event, resolve }) {
const response = await resolve(event, {
transformPageChunk: ({ html }) => {
return html.replace(/number: (\d+)/g, (_match, n) => `number: ${+n * 2}`);
}
});
const number = response.headers.get('x-number');
response.headers.set('x-number', String(+number * 2));
return response;
}
export const handle = sequence(increment, double); // src/routes/+page.js
export function load({ setHeaders }) {
const number = 100;
setHeaders({ 'x-number': String(number) });
return { number };
} <!-- src/routes/+page.svelte -->
<script>
export let data;
</script>
<h1>number: {data.number}</h1> The way it's currently implemented, If we reversed the order in which Unless, that is, we reversed the order altogether and did this... const handle = sequence(
function a({ event, resolve }) {
console.log('i am called last');
return resolve(event); // calls SvelteKit
},
function b({ event, resolve }) {
console.log('i am called in the middle');
return resolve(event); // calls 'a'
},
function c({ event, resolve }) {
console.log('i am called first');
return resolve(event); // calls 'b'
}
); ...but that seems deeply unintuitive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see - yes this makes sense that way then. Thanks!
Closes #4051.
After this change, a
transformPageChunk
option passed to the firsthandle
in a sequence will be respected by later calls toresolve
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0