rsnext/test
Hannes Bornö a9b56610e1
Send correct stats in hot reloader sync event (#46150)
If there's a build error on initial page load, the error is sometimes displayed as a server error instead of a build error:
![image](https://user-images.githubusercontent.com/25056922/220099125-5f538551-342f-4bca-a670-a04d8428de2d.png)

When the hot reloader sends the `sync` event to the client, it always picks the latest compilation. The problem occurs if only the server has errors and the client is the latest. In that case the server errors are ignored and the client stats are sent instead.

This PR makes it check if the server compilation has errors, if that's the case we use those stats. `built` events acts the same, new client builds are [ignored if the server has errors](https://github.com/vercel/next.js/blob/canary/packages/next/src/server/dev/hot-middleware.ts#L123.): 
```ts
onClientDone = (statsResult: webpack.Stats) => {
  this.clientLatestStats = { ts: Date.now(), stats: statsResult }
  if (this.closed || this.serverLatestStats?.stats.hasErrors()) return
  this.publishStats('built', statsResult)
}
```

Fixes NEXT-403

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-20 12:55:29 +00:00
..
.stats-app Remove serverComponents from next.conf.js because it's unused (#43805) 2022-12-07 15:57:03 +01:00
__mocks__ Update Edge Runtime (#38862) 2022-07-21 18:29:19 +00:00
development Send correct stats in hot reloader sync event (#46150) 2023-02-20 12:55:29 +00:00
e2e Detect invalid metadata exports errors in next-swc (#46077) 2023-02-19 08:36:50 +01:00
integration chore: Rename internal Webpack plugin (#46088) 2023-02-18 19:12:20 +00:00
lib test(integration): emits successful test output for continue on error (#46008) 2023-02-16 15:44:38 -08:00
production Add next/font import (#45891) 2023-02-16 15:33:39 +01:00
unit chore(deps): use external @edge-runtime/cookies (#42736) 2023-02-17 15:10:09 +01:00
.gitignore Fix server html insertion target (#42591) 2022-11-07 18:16:13 +01:00
jest-setup-after-env.ts Adds tests to ensure eslint-plugin-next's available rules are properly exported and recommended rules are correctly defined. (#38183) 2022-06-30 11:31:33 -05:00
jest.d.ts Adds tests to ensure eslint-plugin-next's available rules are properly exported and recommended rules are correctly defined. (#38183) 2022-06-30 11:31:33 -05:00
readme.md refactor: split up CONTRIBUTING.md (#40515) 2022-09-16 14:54:58 -07:00
test-file.txt

See Testing for more information on how you can run/write/debug tests for Next.js.