Astro version v2.10.14
Package manager npm
Platform linux
Architecture x64
Adapter Couldn't determine.
Integrations @astrojs/react
What browser are you using?
stackblitz
Usecase
I'm making a Map<string, AstroComponent> which i use to switch between multiple implementations of a single component based on an enum, something like:
---
export type Props = {
type?: 'view1' | 'view2' | 'view3'
}
---
<div data-type={Astro.props.type}><slot /></div>
<script>
import view1 from './view1.ts'
import view2 from './view2.ts'
import view3 from './view3.ts'
const behaviors = { view1, view2, view3 }
document.querySelectorAll<HTMLElement>(div['data-type'])
.forEach(view => {
const type = view.getAttribute('data-type')!
behaviors[type](view)
})
</script>
→ bundles it all but at least execution is regulated from userland code.
→ DOM of different view1/view2/view3 cannot be separated, or must be in a ternary
What's the expected result?
We should only have the Githubissues.
Githubissues is a development platform for aggregating issues.
Astro info
What browser are you using?
stackblitz
Usecase
I'm making a
Map<string, AstroComponent>
which i use to switch between multiple implementations of a single component based on an enum, something like:...which ends up switching between
<StandardView />
,<StaticView />
and<LoopView />
components.Describe the Bug
I have found that when doing something such as:
...the
<script>
tags ofView1
View2
andView3
are inserted in the page, even tho only the html corresponding to the switch/case is actually rendered.Non working workarounds
I have tried different syntax as workaround but they don't work.
In template switch/case
→ still bundle the js of the 3 versions
Dynamic import
bundle it all
→ bundles it all but at least execution is regulated from userland code. → DOM of different view1/view2/view3 cannot be separated, or must be in a ternary
What's the expected result?
We should only have the Githubissues.