playwright/tests/components/ct-react-vite
Max Schmitt 9fa06be49e
fix(ct): throw error if inline component is getting mounted (#32531)
What was happening?
- When we use CT, we go over the test files, look at the imports using
`tsxTransform.ts` and store them inside a map, these we feed into the
import registry which we build using Vite and have access inside the
browser
- In case of an inline component in the same file as where the test file
is, this is not happening.
- jsx-runtime via babel kicks in, transforms every JSX component in
something like that:

```
{
  __pw_type: 'jsx',
  type: [Function: MyInlineComponent],
  props: { value: 'Max' },
  key: undefined
}
```

this then gets passed into `wrapObject` which maps any function from the
Node.js side into expose function calls so they work inside the browser.
The assumption for `wrapObject` was to do it mostly for callbacks. So it
does for `type` - which is actually our component. We then pass this to
the React render function, which calls back the exposed function but we
never return anything, so it mounts `undefined`.

---

While there have been experiments from certain vendors to get the
'client only' code inside a server side file, we should throw for now to
not confuse users. We might revisit this in the future since Babel / TSX
doesn't support it outside of the box.

Fixes https://github.com/microsoft/playwright/issues/32167
2024-09-10 11:15:20 +02:00
..
playwright feat(ct): before mount hook wrapper (#18616) 2022-12-27 14:26:17 -08:00
src chore(ui): enable react/recommended lint rules (#32214) 2024-08-20 14:16:28 +02:00
tests fix(ct): throw error if inline component is getting mounted (#32531) 2024-09-10 11:15:20 +02:00
.gitignore fix(debug): do not pause on internal calls, update ct docs (#14018) 2022-05-07 19:56:25 -07:00
index.html fix(ct): render attributes (#17991) 2022-10-18 13:02:53 -07:00
package.json feat(ct): experimental route fixture (#31554) 2024-07-06 09:35:20 -07:00
playwright.config.ts fix(chromium): continue requests paused for the second time (#27429) 2023-10-04 11:18:06 -07:00
tsconfig.json chore: make @playwright/test depend on playwright (#26946) 2023-09-08 14:23:35 -07:00
tsconfig.node.json chore: group tests under tests/ (2) (#13082) 2022-03-25 23:09:02 -07:00
vite.config.ts chore: group tests under tests/ (2) (#13082) 2022-03-25 23:09:02 -07:00