Skip to content

Commit

Permalink
Merge branch 'canary' into feedthejim/dev-server-restart
Browse files Browse the repository at this point in the history
  • Loading branch information
feedthejim committed Dec 12, 2022
2 parents cc4468c + dcad00d commit d57f46e
Show file tree
Hide file tree
Showing 15 changed files with 328 additions and 71 deletions.
24 changes: 24 additions & 0 deletions .vscode/extensions.json
@@ -0,0 +1,24 @@
{
"recommendations": [
// Linting / Formatting
"rust-lang.rust-analyzer",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"usernamehw.errorlens",

// Testing
"orta.vscode-jest",

// PR management / Reviewing
"github.vscode-pull-request-github",

// Showing todo comments
"gruntfuggly.todo-tree",

// Collaborating
"ms-vsliveshare.vsliveshare",

// Debugging
"ms-vscode.vscode-js-profile-flame"
]
}
47 changes: 43 additions & 4 deletions .vscode/settings.json
@@ -1,15 +1,54 @@
{
// Formatting using Prettier by default for all languages
"editor.defaultFormatter": "esbenp.prettier-vscode",
// Formatting using Prettier for JavaScript, overrides VSCode default.
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
// Formatting using Rust-Analyzer for Rust.
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
},
// Linting using ESLint.
"eslint.validate": [
"javascript",
"javascriptreact",
{ "language": "typescript", "autoFix": true },
{ "language": "typescriptreact", "autoFix": true }
"typescript",
"typescriptreact"
],
"debug.javascript.unmapMissingSources": true,
// Disable Jest autoRun as otherwise it will start running all tests the first time.
"jest.autoRun": "off",

// Debugging.
"debug.javascript.unmapMissingSources": true,

"files.exclude": {
"**/node_modules": false,
"node_modules": true,
"*[!test]**/node_modules": true
}
},

// Ensure enough terminal history is preserved when running tests.
"terminal.integrated.scrollback": 10000,

// Configure todo-tree to exclude node_modules, dist, and compiled.
"todo-tree.filtering.excludeGlobs": [
"**/node_modules",
"**/dist",
"**/compiled"
],
// Match TODO-APP in addition to other TODOs.
"todo-tree.general.tags": [
"BUG",
"HACK",
"FIXME",
"TODO",
"XXX",
"[ ]",
"[x]",
"TODO-APP"
],

// Disable TypeScript surveys.
"typescript.surveys.enabled": false
}
19 changes: 19 additions & 0 deletions packages/next/client/components/bailout-to-client-rendering.ts
@@ -0,0 +1,19 @@
import { suspense } from '../../shared/lib/dynamic-no-ssr'
import { staticGenerationAsyncStorage } from './static-generation-async-storage'

export function bailoutToClientRendering(): boolean | never {
const staticGenerationStore =
staticGenerationAsyncStorage && 'getStore' in staticGenerationAsyncStorage
? staticGenerationAsyncStorage?.getStore()
: staticGenerationAsyncStorage

if (staticGenerationStore?.forceStatic) {
return true
}

if (staticGenerationStore?.isStaticGeneration) {
suspense()
}

return false
}
5 changes: 3 additions & 2 deletions packages/next/client/components/navigation.ts
Expand Up @@ -12,7 +12,7 @@ import {
PathnameContext,
// LayoutSegmentsContext,
} from '../../shared/lib/hooks-client-context'
import { staticGenerationBailout } from './static-generation-bailout'
import { bailoutToClientRendering } from './bailout-to-client-rendering'

const INTERNAL_URLSEARCHPARAMS_INSTANCE = Symbol(
'internal for urlsearchparams readonly'
Expand Down Expand Up @@ -76,7 +76,8 @@ export function useSearchParams() {
return new ReadonlyURLSearchParams(searchParams || new URLSearchParams())
}, [searchParams])

if (staticGenerationBailout('useSearchParams')) {
if (bailoutToClientRendering()) {
// TODO-APP: handle dynamic = 'force-static' here and on the client
return readonlySearchParams
}

Expand Down
Expand Up @@ -348,6 +348,13 @@ function processMessage(
dispatcher.onRefresh()
})

if (process.env.__NEXT_TEST_MODE) {
if (self.__NEXT_HMR_CB) {
self.__NEXT_HMR_CB()
self.__NEXT_HMR_CB = null
}
}

return
}
case 'reloadPage': {
Expand Down
Expand Up @@ -75,10 +75,10 @@ class ReactDevOverlay extends React.PureComponent<
/>
) : hasBuildError ? (
<BuildError message={state.buildError!} />
) : hasRuntimeErrors ? (
<Errors initialDisplayState="minimized" errors={state.errors} />
) : reactError ? (
<Errors initialDisplayState="fullscreen" errors={[reactError]} />
) : hasRuntimeErrors ? (
<Errors initialDisplayState="minimized" errors={state.errors} />
) : undefined}
</ShadowPortal>
) : undefined}
Expand Down
4 changes: 3 additions & 1 deletion packages/next/client/components/static-generation-bailout.ts
@@ -1,7 +1,7 @@
import { DynamicServerError } from './hooks-server-context'
import { staticGenerationAsyncStorage } from './static-generation-async-storage'

export function staticGenerationBailout(reason: string) {
export function staticGenerationBailout(reason: string): boolean | never {
const staticGenerationStore =
staticGenerationAsyncStorage && 'getStore' in staticGenerationAsyncStorage
? staticGenerationAsyncStorage?.getStore()
Expand All @@ -17,4 +17,6 @@ export function staticGenerationBailout(reason: string) {
}
throw new DynamicServerError(reason)
}

return false
}
48 changes: 48 additions & 0 deletions test/development/acceptance-app/ReactRefreshLogBox.test.ts
Expand Up @@ -1221,4 +1221,52 @@ describe('ReactRefreshLogBox app', () => {

await cleanup()
})

test('Server component errors should open up in fullscreen', async () => {
const { session, browser, cleanup } = await sandbox(
next,
new Map([
// Start with error
[
'app/page.js',
`
export default function Page() {
throw new Error('Server component error')
return <p id="text">Hello world</p>
}
`,
],
])
)
expect(await session.hasRedbox(true)).toBe(true)

// Remove error
await session.patch(
'app/page.js',
`
export default function Page() {
return <p id="text">Hello world</p>
}
`
)
expect(await browser.waitForElementByCss('#text').text()).toBe(
'Hello world'
)
expect(await session.hasRedbox()).toBe(false)

// Re-add error
await session.patch(
'app/page.js',
`
export default function Page() {
throw new Error('Server component error!')
return <p id="text">Hello world</p>
}
`
)

expect(await session.hasRedbox(true)).toBe(true)

await cleanup()
})
})

0 comments on commit d57f46e

Please sign in to comment.