Skip to content

Commit 6e0a456

Browse files
author
dasathyakuma
committed
fix everything
1 parent 3ca9e94 commit 6e0a456

File tree

16 files changed

+183
-103
lines changed

16 files changed

+183
-103
lines changed

examples/marko/dynamic/vite.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ import { defineConfig } from 'vite'
22
import marko from '@marko/run/vite'
33

44
export default defineConfig({
5-
plugins: [marko()],
6-
})
5+
// Cast to any: @marko/run/vite types are built against Vite 6 but this
6+
// workspace uses Vite 5. The plugin works correctly at runtime.
7+
plugins: [marko() as any],
8+
})

examples/marko/fixed/src/routes/+page.marko

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
<p>Fixed sizes — every item's dimensions are hard-coded to the same value and never change.</p>
2828

2929
<let/mounted = false/>
30-
<script() { mounted = true }/>
30+
<script>
31+
// @ts-expect-error — Marko LS types <let> as read-only; assignment is valid Marko 6
32+
mounted = true
33+
</script>
3134

3235
<section>
3336
<h2>Rows</h2>

examples/marko/fixed/vite.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ import { defineConfig } from 'vite'
22
import marko from '@marko/run/vite'
33

44
export default defineConfig({
5-
plugins: [marko()],
6-
})
5+
// Cast to any: @marko/run/vite types are built against Vite 6 but this
6+
// workspace uses Vite 5. The plugin works correctly at runtime.
7+
plugins: [marko() as any],
8+
})

examples/marko/grid/vite.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ import { defineConfig } from 'vite'
22
import marko from '@marko/run/vite'
33

44
export default defineConfig({
5-
plugins: [marko()],
6-
})
5+
// Cast to any: @marko/run/vite types are built against Vite 6 but this
6+
// workspace uses Vite 5. The plugin works correctly at runtime.
7+
plugins: [marko() as any],
8+
})

examples/marko/infinite-scroll/vite.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ import { defineConfig } from 'vite'
22
import marko from '@marko/run/vite'
33

44
export default defineConfig({
5-
plugins: [marko()],
6-
})
5+
// Cast to any: @marko/run/vite types are built against Vite 6 but this
6+
// workspace uses Vite 5. The plugin works correctly at runtime.
7+
plugins: [marko() as any],
8+
})

examples/marko/smooth-scroll/vite.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ import { defineConfig } from 'vite'
22
import marko from '@marko/run/vite'
33

44
export default defineConfig({
5-
plugins: [marko()],
6-
})
5+
// Cast to any: @marko/run/vite types are built against Vite 6 but this
6+
// workspace uses Vite 5. The plugin works correctly at runtime.
7+
plugins: [marko() as any],
8+
})

examples/marko/variable/vite.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ import { defineConfig } from 'vite'
22
import marko from '@marko/run/vite'
33

44
export default defineConfig({
5-
plugins: [marko()],
6-
})
5+
// Cast to any: @marko/run/vite types are built against Vite 6 but this
6+
// workspace uses Vite 5. The plugin works correctly at runtime.
7+
plugins: [marko() as any],
8+
})

examples/marko/window/vite.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ import { defineConfig } from 'vite'
22
import marko from '@marko/run/vite'
33

44
export default defineConfig({
5-
plugins: [marko()],
6-
})
5+
// Cast to any: @marko/run/vite types are built against Vite 6 but this
6+
// workspace uses Vite 5. The plugin works correctly at runtime.
7+
plugins: [marko() as any],
8+
})
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Ambient type declaration for .marko template imports.
2+
// @marko/vite compiles .marko files to browser templates exposing mount().
3+
// The full Marko.Template type is available via the marko package but
4+
// requires the Marko language toolchain. For test imports we declare the
5+
// minimal shape we actually use.
6+
declare module "*.marko" {
7+
const template: {
8+
mount(
9+
input: Record<string, unknown>,
10+
container: Element | DocumentFragment,
11+
): { destroy(): void }
12+
}
13+
export default template
14+
}
15+
16+
// Type declaration for @marko/vite plugin.
17+
// The actual package may ship its own types; this is a fallback.
18+
declare module "@marko/vite" {
19+
import type { Plugin } from "vite"
20+
function marko(options?: Record<string, unknown>): Plugin
21+
export default marko
22+
}

packages/marko-virtual/src/tags/virtualizer/index.marko

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ import {
44
observeElementOffset,
55
elementScroll,
66
} from "@tanstack/virtual-core"
7-
import type {
8-
VirtualItem,
9-
ScrollToIndexOptions,
10-
ScrollToOffsetOptions,
11-
} from "@tanstack/virtual-core"
7+
import type { VirtualItem, ScrollToOptions } from "@tanstack/virtual-core"
8+
import { setInstance, getInstance, deleteInstance } from "./store"
129

1310
export interface Input {
1411
count: number
@@ -23,32 +20,26 @@ export interface Input {
2320
gap?: number
2421
lanes?: number
2522
initialOffset?: number | (() => number)
26-
// Tag parameters — the body content receives virtualItems, totalSize, etc.
2723
content: Marko.Body<[{
2824
virtualItems: VirtualItem[]
2925
totalSize: number
3026
measureElement: ((el: Element | null) => void) | undefined
31-
scrollToIndex: (index: number, options?: ScrollToIndexOptions) => void
32-
scrollToOffset: (offset: number, options?: ScrollToOffsetOptions) => void
27+
scrollToIndex: (index: number, options?: ScrollToOptions) => void
28+
scrollToOffset: (offset: number, options?: ScrollToOptions) => void
3329
}]>
3430
}
3531

36-
// Module-level Map — class instances never stored in reactive signals
37-
static const _instances = new Map<string, Virtualizer<Element, Element>>()
38-
static const _cleanups = new Map<string, () => void>()
39-
static let _nextId = 0
40-
41-
<let/id = (`v${++_nextId}`)/>
32+
<let/id = (Math.random().toString(36).slice(2))/>
4233
<let/items = ([] as VirtualItem[])/>
4334
<let/size = 0/>
4435

4536
<lifecycle<{}>
4637
onMount() {
4738
const notify = () => {
48-
const v = _instances.get(id)
49-
if (!v) return
50-
items = v.getVirtualItems()
51-
size = v.getTotalSize()
39+
const entry = getInstance(id)
40+
if (!entry) return
41+
items = entry.v.getVirtualItems()
42+
size = entry.v.getTotalSize()
5243
}
5344
5445
const v = new Virtualizer<Element, Element>({
@@ -70,14 +61,14 @@ static let _nextId = 0
7061
onChange: notify,
7162
})
7263
73-
_instances.set(id, v)
74-
_cleanups.set(id, v._didMount())
64+
setInstance(id, { v, cleanup: v._didMount() })
7565
v._willUpdate()
7666
}
7767

7868
onUpdate() {
79-
const v = _instances.get(id)
80-
if (!v) return
69+
const entry = getInstance(id)
70+
if (!entry) return
71+
const { v } = entry
8172
8273
const notify = () => {
8374
items = v.getVirtualItems()
@@ -102,21 +93,22 @@ static let _nextId = 0
10293
})
10394
10495
v._willUpdate()
96+
notify()
10597
}
10698

10799
onDestroy() {
108-
_cleanups.get(id)?.()
109-
_instances.delete(id)
110-
_cleanups.delete(id)
100+
const entry = getInstance(id)
101+
if (entry) {
102+
entry.cleanup()
103+
deleteInstance(id)
104+
}
111105
}
112106
/>
113107

114-
// Render the body content with virtual items passed as tag parameters.
115-
// When items/size signals change, this re-renders with updated values.
116108
<${input.content}
117109
virtualItems=items
118110
totalSize=size
119-
measureElement=_instances.get(id)?.measureElement
120-
scrollToIndex=(index: number, options?: ScrollToIndexOptions) => _instances.get(id)?.scrollToIndex(index, options)
121-
scrollToOffset=(offset: number, options?: ScrollToOffsetOptions) => _instances.get(id)?.scrollToOffset(offset, options)
111+
measureElement=getInstance(id)?.v?.measureElement
112+
scrollToIndex=(index: number, options?: ScrollToOptions) => getInstance(id)?.v?.scrollToIndex(index, options)
113+
scrollToOffset=(offset: number, options?: ScrollToOptions) => getInstance(id)?.v?.scrollToOffset(offset, options)
122114
/>

0 commit comments

Comments
 (0)