This repository was archived by the owner on Jan 28, 2025. It is now read-only.
  
  
  - 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 458
 
Incremental static regeneration #1028
          
     Merged
      
      
    
  
     Merged
                    Changes from 41 commits
      Commits
    
    
            Show all changes
          
          
            61 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      31f313c
              
                wip: initial proof-of-concept incremental static regeneration
              
              
                kirkness 35cf5ff
              
                fix: dont ts build the regeneration handler
              
              
                kirkness 65ba637
              
                fix: dynamic paths should regenerate
              
              
                kirkness 0ee2f55
              
                add Expires header to the regenerated S3 objects
              
              
                kirkness 6f1ce93
              
                Merge branch 'master' into feature/incremental-static-regeneration
              
              
                kirkness fc8bd38
              
                use expires header rather than last-modified and a small code tidy
              
              
                kirkness 8a0d5ff
              
                revalidation relies on the expires header
              
              
                kirkness 67cda68
              
                fix fallback isr fallback behaviour
              
              
                kirkness 16fe62b
              
                Merge branch 'master' into feature/incremental-static-regeneration
              
              
                kirkness 26ed898
              
                update cdk snapshot
              
              
                kirkness ef7d03b
              
                remove sqs and use lambda async invocation
              
              
                kirkness f4548b3
              
                adds e2e test and serverless infrastructure
              
              
                kirkness b52d762
              
                remove uneeded isNaN check
              
              
                kirkness 3dc480f
              
                remove prerenderManifest variable from handler
              
              
                kirkness 127698b
              
                add e2e test for isr page with getStaticPaths
              
              
                kirkness 7eb5bb4
              
                revert serverless change
              
              
                kirkness a3eb635
              
                add tests to regeneration handler
              
              
                kirkness 30d0e51
              
                add tests for getStaticRegenerationResponse
              
              
                kirkness c03105f
              
                create the regeneration lambd ain the same region as the bucket
              
              
                kirkness 6adf890
              
                revery async lambda changes and use SQS
              
              
                kirkness 9dbfb27
              
                add sqs creation to serverless components
              
              
                kirkness f0650f2
              
                fix conflicts
              
              
                kirkness 57b403b
              
                update snapshot andd mocks
              
              
                kirkness 43f064a
              
                fix regeneration  tests with sqs event
              
              
                kirkness db31e75
              
                Merge branch 'master' into feature/incremental-static-regeneration
              
              
                kirkness 6f0f45c
              
                minor test fixes
              
              
                kirkness 26c8449
              
                Merge branch 'feature/incremental-static-regeneration' of https://git…
              
              
                kirkness f397f50
              
                fix all tests
              
              
                kirkness 631d8c0
              
                add cache-control header tests to default-handler
              
              
                kirkness 5fc9807
              
                add tests for triggerStaticRegeneration
              
              
                kirkness b8cb485
              
                remove removeHeader call
              
              
                kirkness 99ec48c
              
                remove only  test
              
              
                kirkness 93a0826
              
                add tests for sqs component
              
              
                kirkness 10f9f67
              
                add tests to unhappy-paths in triggerStaticRegeneration
              
              
                kirkness cb5ad0b
              
                add extra test cases to sqs component
              
              
                kirkness f9806d2
              
                add case for sqs delete
              
              
                kirkness 3552751
              
                check assertions against sdk api calls
              
              
                kirkness 09f739f
              
                Merge branch 'master' into feature/incremental-static-regeneration
              
              
                kirkness 41202f3
              
                regenerate yarn lock files
              
              
                kirkness d9417b8
              
                Merge branch 'feature/incremental-static-regeneration' of https://git…
              
              
                kirkness 1f757d1
              
                chore: resolve conflicts
              
              
                kirkness fbe017e
              
                docs: add ISR related deployment permissions
              
              
                kirkness 027e9c1
              
                fix: update all yarn lock files in all e2e packages
              
              
                kirkness 855fc88
              
                fix: include ready checks in e2e tests for isr
              
              
                kirkness 436b584
              
                fix: redirect test in trailing slash e2e tests
              
              
                kirkness 90ce486
              
                fix: include isr e2e path checks in test-utils
              
              
                kirkness d546e02
              
                Merge branch 'master' into feature/incremental-static-regeneration
              
              
                dphang a3c3e36
              
                fix: dont deploy a queue if we dont need one
              
              
                kirkness 738335e
              
                fix: merge conflicts
              
              
                kirkness bf8038a
              
                fix: revert normalise uri call
              
              
                kirkness e49eac4
              
                fix: update snapshot
              
              
                kirkness b13cb05
              
                fix: update regeneration fallback test
              
              
                kirkness aaa0916
              
                fix: convert secs to millis
              
              
                kirkness f104d19
              
                fix: revert 404 case
              
              
                kirkness bf6ceed
              
                fix: revert 308 case
              
              
                kirkness 200f195
              
                fix: revert 404 case
              
              
                kirkness e2cae31
              
                fix: set cache folder for more reliability(??)
              
              
                kirkness f4e5218
              
                fix: 404 redirect test, update post cypress bump
              
              
                kirkness 2cde26b
              
                fix: resolve conflits
              
              
                kirkness 3c37c3f
              
                fix: merge conflict
              
              
                kirkness 7586260
              
                Merge branch 'master' into feature/incremental-static-regeneration
              
              
                dphang File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -42,7 +42,7 @@ describe("Redirects Tests", () => { | |
| { | ||
| path: "//example.com/", | ||
| expectedPath: "/example.com", | ||
| expectedStatus: 404 | ||
| expectedStatus: 308 | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was not passing after the update to cypress - the 308 is returned initially and the 404 is the status code of the subsequent request.  | 
||
| } | ||
| ].forEach(({ path, expectedPath, expectedStatus }) => { | ||
| it(`does not redirect page ${path}`, () => { | ||
| 
          
            
          
           | 
    ||
        
          
          
            54 changes: 54 additions & 0 deletions
          
          54 
        
  packages/e2e-tests/next-app/cypress/integration/static-regeneration.test.ts
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| describe("ISR Tests", () => { | ||
| before(() => { | ||
| cy.ensureAllRoutesNotErrored(); | ||
| }); | ||
| 
     | 
||
| // We don't want this test to retry as the cache will not be expired between | ||
| // runs | ||
| describe("SSG page", { retries: 0 }, () => { | ||
| [ | ||
| "/revalidated-ssg-page", | ||
| // Pre-rendered ISR page | ||
| "/revalidated-ssg-pages/101", | ||
| // Blocking dynamic generated page | ||
| "/revalidated-ssg-pages/105" | ||
| ].forEach((path) => { | ||
| it(`serves the cached re-rendered page "${path}" after 2 reloads`, () => { | ||
| // The initial load will have expired in the cache | ||
| cy.ensureRouteNotCached(path); | ||
| cy.visit(path); | ||
| cy.location("pathname").should("eq", path); | ||
| 
     | 
||
| cy.get("[data-cy=date-text]") | ||
| .invoke("text") | ||
| .then((text1) => { | ||
| // When we reload again the page still should not be cached as this | ||
| // should be the first time its being served from the origin | ||
| cy.ensureRouteNotCached(path); | ||
| cy.reload(); | ||
| cy.get("[data-cy=date-text]") | ||
| .invoke("text") | ||
| .then((text2) => { | ||
| // Check that the date text has changed since the initial page | ||
| // load | ||
| expect(text1).not.to.be.eq(text2); | ||
| // The new date should be greater than the original | ||
| expect(new Date(text2).getTime()).to.be.greaterThan( | ||
| new Date(text1).getTime() | ||
| ); | ||
| // Make sure the next load is cached | ||
| cy.ensureRouteCached(path); | ||
| // Be sure that the regeneration has run and uploaded the file | ||
| cy.wait(2000); | ||
| cy.reload(); | ||
| }); | ||
| }); | ||
| 
     | 
||
| // Wait for the cache to expire after the 10s | ||
| cy.wait(8000); | ||
| cy.ensureRouteNotCached(path); | ||
| cy.reload(); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            27 changes: 27 additions & 0 deletions
          
          27 
        
  packages/e2e-tests/next-app/pages/revalidated-ssg-page.tsx
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import React from "react"; | ||
| import { GetStaticPropsResult } from "next"; | ||
| 
     | 
||
| type SSGPageProps = { | ||
| date: string; | ||
| }; | ||
| 
     | 
||
| export default function RevalidatedSSGPage(props: SSGPageProps): JSX.Element { | ||
| return ( | ||
| <React.Fragment> | ||
| <div> | ||
| <p data-cy="date-text">{props.date}</p> | ||
| </div> | ||
| </React.Fragment> | ||
| ); | ||
| } | ||
| 
     | 
||
| export async function getStaticProps(): Promise< | ||
| GetStaticPropsResult<SSGPageProps> | ||
| > { | ||
| return { | ||
| revalidate: 10, | ||
| props: { | ||
| date: new Date().toJSON() | ||
| } | ||
| }; | ||
| } | 
        
          
          
            62 changes: 62 additions & 0 deletions
          
          62 
        
  packages/e2e-tests/next-app/pages/revalidated-ssg-pages/[id].tsx
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import React from "react"; | ||
| import { | ||
| GetStaticPaths, | ||
| GetStaticPropsContext, | ||
| GetStaticPropsResult | ||
| } from "next"; | ||
| 
     | 
||
| const sampleUserData = [ | ||
| { id: 101, name: "Alice" }, | ||
| { id: 102, name: "Bob" }, | ||
| { id: 103, name: "Caroline" }, | ||
| { id: 104, name: "Dave" } | ||
| ]; | ||
| 
     | 
||
| const newUser = { id: 105, name: "Henry" }; | ||
| 
     | 
||
| type SSGPageProps = { | ||
| date: string; | ||
| user?: typeof sampleUserData[number]; | ||
| }; | ||
| 
     | 
||
| export default function RevalidatedSSGPage(props: SSGPageProps): JSX.Element { | ||
| return ( | ||
| <React.Fragment> | ||
| <div> | ||
| <p data-cy="date-text">{props.date}</p> | ||
| <p data-cy="user-id-text">{props.user?.id ?? "No user found"}</p> | ||
| </div> | ||
| </React.Fragment> | ||
| ); | ||
| } | ||
| 
     | 
||
| export const getStaticPaths: GetStaticPaths = async () => { | ||
| // To simulate new data becoming available in a data source we only make the | ||
| // `newUser` available when rendering on AWS, rather than at build time. | ||
| const runningOnAws = !!process.env.AWS_LAMBDA_FUNCTION_NAME; | ||
| const paths = sampleUserData.map((user) => ({ | ||
| params: { id: user.id.toString() } | ||
| })); | ||
| 
     | 
||
| if (runningOnAws) { | ||
| paths.push({ params: { id: newUser.id.toString() } }); | ||
| } | ||
| 
     | 
||
| return { paths, fallback: "blocking" }; | ||
| }; | ||
| 
     | 
||
| export async function getStaticProps( | ||
| context: GetStaticPropsContext<{ id: string }> | ||
| ): Promise<GetStaticPropsResult<SSGPageProps>> { | ||
| const users = [...sampleUserData, newUser]; | ||
| const user = users.find( | ||
| ({ id }) => context.params?.id.toString() === id.toString() | ||
| ); | ||
| return { | ||
| revalidate: 10, | ||
| props: { | ||
| date: new Date().toJSON(), | ||
| user | ||
| } | ||
| }; | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.