PD-439-add pagination to requests on build #99
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Pagination Support for API Data Fetching
Problem
Hapi has been experiencing OOM (out of memory) crashes several times a day due to SEO data requests from SSG deployments. To protect hapi and provide stable service for customer traffic, a hard limit was imposed on the number of entities returned from all
/seoroutes (https://github.com/holidayextras/hapi/pull/10190).This has caused build failures in SSGs where hapi now returns only a limited subset of the data, breaking deployments.
Related Links:
Solution
This PR adds automatic pagination support to the main data fetcher in
pageData.js. The SSG will now automatically fetch all pages of data from APIs that return paginated responses, ensuring all required data is retrieved despite the new limits.Key Changes
Core Implementation (
src/components/pageData.js)New Helper Methods
getPaginationLimit()- Centralized limit calculation (config → env → default 100)getDataArrayLength()- Safely gets array length accounting for repeater fieldhasMorePages()- Determines if more data needs to be fetchedfetchAllPages()- Recursively fetches all pages of datafetchSinglePage()- Legacy single-request behavior (when pagination disabled)Modified
callAPI()MethodEnhanced
prepareRequest()Method?offset=0&limit=100pagination parametersUpdated
getDataForPage()MethodDocumentation (
README.md)SSG_PAGINATION_LIMITenvironment variableFeatures
✅ Enabled by default - No markdown file changes required
✅ Offset-based pagination - Uses
?offset=0&limit=100matching hapi's standard✅ Recursive fetching - Automatically retrieves all pages until complete
✅ Progress logging - Console output shows pagination progress during builds
✅ Backward compatible - Can be disabled per-file with
pagination.enabled: false✅ Environment testing -
SSG_PAGINATION_LIMITvariable for testing with small page sizes✅ No assumptions - Works with any API response structure
Usage
Default Behaviour (No Changes Needed)
Existing markdown files work as-is:
The SSG automatically adds
?offset=0&limit=100,?offset=100&limit=100, etc.Custom Limit
Testing with Small Pages
Console output will show:
Technical Details
offsetandlimit(hardcoded to match hapi standard)Breaking Changes
None - fully backward compatible.
Testing
ssg-hx-ukstructureDeployment Plan
Future Enhancements
If other APIs require different pagination styles:
skip/take,start/count, etc.)?page=1)meta.totalresponse fields for optimisation