@@ -150,7 +150,17 @@ export async function respond(request, options, state = {}) {
150150 event . url = new URL ( event . url . origin + normalized + event . url . search ) ;
151151 }
152152
153+ // `key` will be set if this request came from a client-side navigation
154+ // to a page with a matching endpoint
155+ const key = request . headers . get ( 'x-sveltekit-load' ) ;
156+
153157 for ( const route of options . manifest . _ . routes ) {
158+ if ( key ) {
159+ // client is requesting data for a specific endpoint
160+ if ( route . type !== 'page' ) continue ;
161+ if ( route . key !== key ) continue ;
162+ }
163+
154164 const match = route . pattern . exec ( decoded ) ;
155165 if ( ! match ) continue ;
156166
@@ -163,7 +173,7 @@ export async function respond(request, options, state = {}) {
163173 response = await render_endpoint ( event , await route . shadow ( ) ) ;
164174
165175 // loading data for a client-side transition is a special case
166- if ( request . headers . get ( 'x-sveltekit-load' ) === 'true' ) {
176+ if ( key ) {
167177 if ( response ) {
168178 // since redirects are opaque to the browser, we need to repackage
169179 // 3xx responses as 200s with a custom header
@@ -180,9 +190,9 @@ export async function respond(request, options, state = {}) {
180190 }
181191 }
182192 } else {
183- // TODO ideally, the client wouldn't request this data
184- // in the first place (at least in production)
185- response = new Response ( '{}' , {
193+ // fallthrough
194+ response = new Response ( undefined , {
195+ status : 204 ,
186196 headers : {
187197 'content-type' : 'application/json'
188198 }
0 commit comments