|
1 | 1 | import { nextTestSetup } from 'e2e-utils'
|
2 | 2 | import { retry } from 'next-test-utils'
|
3 | 3 |
|
| 4 | +const isCacheComponentsEnabled = |
| 5 | + process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' |
| 6 | + |
4 | 7 | describe('source-mapping', () => {
|
5 |
| - const { next } = nextTestSetup({ |
| 8 | + const { isTurbopack, next } = nextTestSetup({ |
6 | 9 | files: __dirname,
|
7 | 10 | })
|
8 | 11 |
|
@@ -165,4 +168,41 @@ describe('source-mapping', () => {
|
165 | 168 | )
|
166 | 169 | })
|
167 | 170 | })
|
| 171 | + |
| 172 | + it('should show an error when client functions are called from server components', async () => { |
| 173 | + const browser = await next.browser('/server-client') |
| 174 | + |
| 175 | + // TODO(veil): Top stack should be ignore-listed |
| 176 | + if (isTurbopack) { |
| 177 | + await expect(browser).toDisplayRedbox(` |
| 178 | + { |
| 179 | + "description": "Attempted to call useClient() from the server but useClient is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.", |
| 180 | + "environmentLabel": "${isCacheComponentsEnabled ? 'Prerender' : 'Server'}", |
| 181 | + "label": "Runtime Error", |
| 182 | + "source": "app/server-client/client.js/proxy.mjs (3:24) @ <anonymous> |
| 183 | + > 3 | function() { throw new Error("Attempted to call useClient() from the server but useClient is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component."); }, |
| 184 | + | ^", |
| 185 | + "stack": [ |
| 186 | + "<anonymous> app/server-client/client.js/proxy.mjs (3:24)", |
| 187 | + "Component app/server-client/page.js (5:12)", |
| 188 | + ], |
| 189 | + } |
| 190 | + `) |
| 191 | + } else { |
| 192 | + await expect(browser).toDisplayRedbox(` |
| 193 | + { |
| 194 | + "description": "Attempted to call useClient() from the server but useClient is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.", |
| 195 | + "environmentLabel": "${isCacheComponentsEnabled ? 'Prerender' : 'Server'}", |
| 196 | + "label": "Runtime Error", |
| 197 | + "source": "app/server-client/page.js (5:12) @ Component |
| 198 | + > 5 | useClient() |
| 199 | + | ^", |
| 200 | + "stack": [ |
| 201 | + "<FIXME-file-protocol>", |
| 202 | + "Component app/server-client/page.js (5:12)", |
| 203 | + ], |
| 204 | + } |
| 205 | + `) |
| 206 | + } |
| 207 | + }) |
168 | 208 | })
|
0 commit comments