playwright/tests/components
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
..
ct-react-vite fix(ct): throw error if inline component is getting mounted (#32531) 2024-09-10 11:15:20 +02:00
ct-react17 fix(ct): mount then unmount then mount (#30657) 2024-05-14 11:03:46 -07:00
ct-solid fix(ct): mount then unmount then mount (#30657) 2024-05-14 11:03:46 -07:00
ct-svelte test(svelte): migrate svelte-navigator to custom minimal router (#30225) 2024-04-04 16:01:08 +02:00
ct-svelte-vite fix(ct): mount then unmount then mount (#30657) 2024-05-14 11:03:46 -07:00
ct-vue-cli chore: fix typos (#30645) 2024-05-08 19:40:03 +01:00
ct-vue-vite test: fix ct-vue-vite tests (#31406) 2024-06-22 00:50:10 +02:00
ct-vue2-cli fix(ct): mount then unmount then mount (#30657) 2024-05-14 11:03:46 -07:00
.gitignore Revert "chore: use plugins for component testing again (#13977)" (#13998) 2022-05-06 12:02:07 -07:00
test-all.spec.js chore(ct): type check (#18208) 2022-10-20 13:33:25 -07:00