metafizzy / metafizzy/infinite-scroll
"Last" event does not work with an 204 status response
- Dominant language
- HTML
- Stars
- 7.5k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
Hello!
The last event does not work with HTTP 204 status response. You can see in https://conocien.do/hallstatt/actividades the loading text remains visible.
Checking the source code the problem seems to be in the block:
```
let fetchPromise = fetch( path, fetchOptions )
.then( ( response ) => {
if ( !response.ok ) {
let error = new Error( response.statusText );
this.onPageError( error, path, response );
return { response };
}
return response[ responseBody ]().then( ( body ) => {
console.log(body);
let canDomParse = responseBody == 'text' && domParseResponse;
if ( canDomParse ) {
body = domParser.parseFromString( body, 'text/html' );
}
if ( response.status == 204 ) {
this.lastPageReached( body, path );
return { body, response };
} else {
return this.onPageLoad( body, path, response );
}
} );
} )
.catch( ( error ) => {
console.log(error);
this.onPageError( error, path );
} );
```
A status 204 never returns content, it's an empty body response, so the code never enters into "response[ responseBody ]().then" and it's catched with the error "SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data"
Can you check this bug, please?
Thank you!
Contributor guide
Research direction
Start with the fetchPromise block shown in the issue and reproduce the linked page's loading behavior with an HTTP 204 response. Trace the response-body handling and confirm that an empty 204 response reaches the last-event path without a parsing error; done means the loading text no longer remains visible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100