Skip to content

Commit 0a999d2

Browse files
committed
Add workaround for Leaf bug.
See vapor/leaf#235 for details.
1 parent 726c187 commit 0a999d2

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Sources/SwiftVite/ViteTag.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#if canImport(Leaf)
22
import Leaf
3+
import Vapor
34

45
enum ViteTagError: Error {
56
case invalidResourceParameter
@@ -37,12 +38,30 @@ struct ViteTag: UnsafeUnescapedLeafTag {
3738
}
3839

3940
private extension LeafContext {
41+
// This is to work around this bug in Leaf:
42+
// https://github.com/vapor/leaf/pull/235
43+
private var _application: Application? {
44+
guard let value = userInfo["application"] else {
45+
return nil
46+
}
47+
48+
if let app = value as? Application {
49+
return app
50+
}
51+
52+
if let leaf = value as? Application.Leaf {
53+
return leaf.application
54+
}
55+
56+
return nil
57+
}
58+
4059
var viteManifest: ViteManifest {
41-
return application?.vite.withManifest({ $0 }) ?? [:]
60+
return _application?.vite.withManifest({ $0 }) ?? [:]
4261
}
4362

4463
var viteEnvironment: Vite.Environment {
45-
return application?.environment == .production
64+
return _application?.environment == .production
4665
? .production
4766
: .development
4867
}

0 commit comments

Comments
 (0)