- 
                Notifications
    You must be signed in to change notification settings 
- Fork 29.7k
fix: detect loop in client error page #26567
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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      cdc2669
              
                fix: detect loop in client error page
              
              
                huozhi e2cc5fc
              
                transpile client files as ESM
              
              
                sokra 9124d74
              
                omit propsal-dynamic-import
              
              
                huozhi a2c7e29
              
                fix test
              
              
                huozhi 0b47b7a
              
                fix test
              
              
                huozhi 1cbf9c4
              
                Merge branch 'canary' into fix/error-loop
              
              
                huozhi 722b614
              
                Merge branch 'canary' into fix/error-loop
              
              
                timneutkens 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
    
  
  
    
              
        
          
          
            12 changes: 12 additions & 0 deletions
          
          12 
        
  test/integration/custom-error-page-exception/pages/_error.js
  
  
      
      
   
        
      
      
    
  
    
      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,12 @@ | ||
| /* eslint-disable no-unused-expressions, no-undef */ | ||
| let renderCount = 0 | ||
|  | ||
| export default function Error() { | ||
| renderCount++ | ||
|  | ||
| // Guard to avoid endless loop crashing the browser tab. | ||
| if (typeof window !== 'undefined' && renderCount < 3) { | ||
| throw new Error('crash') | ||
| } | ||
| return `error threw ${renderCount} times` | ||
| } | 
        
          
          
            20 changes: 20 additions & 0 deletions
          
          20 
        
  test/integration/custom-error-page-exception/pages/index.js
  
  
      
      
   
        
      
      
    
  
    
      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,20 @@ | ||
| /* eslint-disable no-unused-expressions, no-unused-vars */ | ||
| import React from 'react' | ||
| import Link from 'next/link' | ||
|  | ||
| function page() { | ||
| return ( | ||
| <Link href="/"> | ||
| <a id="nav">Client side nav</a> | ||
| </Link> | ||
| ) | ||
| } | ||
|  | ||
| page.getInitialProps = () => { | ||
| if (typeof window !== 'undefined') { | ||
| throw new Error('Oops from Home') | ||
| } | ||
| return {} | ||
| } | ||
|  | ||
| export default page | 
        
          
          
            26 changes: 26 additions & 0 deletions
          
          26 
        
  test/integration/custom-error-page-exception/test/index.test.js
  
  
      
      
   
        
      
      
    
  
    
      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,26 @@ | ||
| /* eslint-env jest */ | ||
|  | ||
| import { join } from 'path' | ||
| import webdriver from 'next-webdriver' | ||
| import { nextBuild, nextStart, findPort, killApp } from 'next-test-utils' | ||
|  | ||
| jest.setTimeout(1000 * 60 * 1) | ||
|  | ||
| const appDir = join(__dirname, '..') | ||
| const navSel = '#nav' | ||
| const errorMessage = 'Application error: a client-side exception has occurred' | ||
|  | ||
| describe('Custom error page exception', () => { | ||
| it('should handle errors from _error render', async () => { | ||
| const { code } = await nextBuild(appDir) | ||
| const appPort = await findPort() | ||
| const app = await nextStart(appDir, appPort) | ||
| const browser = await webdriver(appPort, '/') | ||
| await browser.waitForElementByCss(navSel).elementByCss(navSel).click() | ||
| const text = await (await browser.elementByCss('#__next')).text() | ||
| killApp(app) | ||
|  | ||
| expect(code).toBe(0) | ||
| expect(text).toMatch(errorMessage) | ||
| }) | ||
| }) | 
  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.