Skip to content

Commit 32b5434

Browse files
committed
Work around vitejs/vite#18582
After that issue is fixed, this commit should be reverted.
1 parent 73cebd7 commit 32b5434

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/location.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <reference types="vite/client" />
12
import type { RefWithScroll, ScrollName } from './ref.ts'
23

34
type AppleSauce = {
@@ -8,9 +9,16 @@ type AppleSauce = {
89
type TOC = Record<string, Record<string, Record<string, AppleSauce>>>
910

1011
export async function loadScroll(name: ScrollName) {
11-
const toc = await import(`./data/tables-of-contents/${name}.json`, {
12-
with: { type: 'json' },
13-
})
12+
// TODO(https://github.com/vitejs/vite/issues/18582): Delete this workaround.
13+
let toc
14+
if (import.meta.env?.MODE)
15+
// Vite dynamic imports doesn't support the second parameter
16+
toc = await import(`./data/tables-of-contents/${name}.json`)
17+
else
18+
toc = await import(`./data/tables-of-contents/${name}.json`, {
19+
// Node.js requires the second parameter.
20+
with: { type: 'json' },
21+
})
1422
return new ScrollResolver(name, toc.default)
1523
}
1624

src/view-model/scroll-view-model.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,24 @@ export abstract class ScrollViewModel {
198198
if (typeof pageNumber === 'object') return pageNumber
199199
if (!pageNumber || pageNumber <= 0) return null
200200

201-
const page: LineType[] = (
202-
await import(
201+
202+
let page: { default: LineType[] }
203+
if (import.meta.env?.MODE)
204+
// Vite dynamic imports doesn't support the second parameter
205+
page = await import(
206+
`../data/pages/${this.relevantRuns[0].scroll}/${pageNumber}.json`
207+
)
208+
else
209+
page = await import(
203210
`../data/pages/${this.relevantRuns[0].scroll}/${pageNumber}.json`,
211+
// Node.js requires the second parameter.
204212
{ with: { type: 'json' } }
205213
)
206-
).default
207214

208215
let run: LeiningRun | undefined
209216
let aliyot: LeiningAliyah[] = []
210217
const labeller = new AliyahLabeller()
211-
const lines: RenderedLineInfo[] = page.map((rawLine) => {
218+
const lines: RenderedLineInfo[] = page.default.map((rawLine) => {
212219
const verses = rawLine.verses.map(toRef)
213220

214221
if (verses.length) [run, aliyot] = this.findContainingAliyot(verses, run)

0 commit comments

Comments
 (0)