bug: `Fragment` is undefined in .tsx files without Stencil decorators
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
Research direction
Start with stencilVitestPlugin() and the rule that decides which .tsx files go through the Stencil compiler. The repro is a helper module that imports Fragment and h from @stencil/core with no decorators, and it fails because the public entry does not export Fragment at runtime. Done means a *.unit.tsx test that renders <Pair /> from such a helper shows both spans, without the vi.mock workaround in the issue.
Written by the indexing model from the issue text.
Description
Prerequisites
- I have searched for existing issues that already report this problem, without success.
Package Version
@stencil/vitest 1.16.1 (plugin/source mode, stencilVitestPlugin())
Stencil Version
@stencil/core 4.44.1
Vitest Version
vitest 5.0.3, environment stencil, domEnvironment mock-doc
Reproduction URL
N/A
Describe the Bug
In plugin mode, only .tsx files with Stencil decorators (@Component etc.) go through the Stencil
compiler. Helper modules that only export functional components using <Fragment>
(import { Fragment, h } from '@stencil/core') are left to esbuild. The public @stencil/core entry
does not export Fragment at runtime (the compiler normally rewrites the import), so Fragment is
undefined and rendering fails.
Workaround
// vitest setup file
vi.mock('@stencil/core', async importOriginal => {
const { Fragment } = await import('@stencil/core/internal/client');
return { ...(await importOriginal<object>()), Fragment };
});
Suggested fix
Transform every .tsx that imports from @stencil/core, not only decorated ones, or resolve
@stencil/core to a runtime entry that exports Fragment (and h, Host).
Steps to Reproduce
util.tsx:import { Fragment, h } from '@stencil/core'; export const Pair = () => <Fragment><span>a</span><span>b</span></Fragment>;- A
@Componentthat renders<Pair />. - A
*.unit.tsxtest:await render(<my-cmp />)withstencilVitestPlugin().
Expected Behavior
Expected: both spans render, as with stencil build.
Actual: Fragment is undefined in util.tsx.
Logs
- Dominant language
- TypeScript
- Stars
- 6
- Forks
- 6
- Avg merge
- 8d 19h
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stenciljs/vitest
All issues in stenciljs/vitest
Similar issues
-
bug zoo
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
software-mansion/runntime#151 ·
Maintainers usually reply within 4 days
-
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
sidebandstudio/clawtrate#728 ·
Maintainers usually reply within 1 day
-
enhancement github_actions help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
tranquilo-art/tranquilo-app#254 ·
Maintainers usually reply within 1 day
-
docs good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 87/100
DojoCodingLabs/hermit#73 ·
Maintainers usually reply within 1 day
-
documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Tfoucher5/fuzzy-toolkit#44 ·
Maintainers usually reply within 1 day