Skip to content

Commit

Permalink
Add workaround for Leaf bug.
Browse files Browse the repository at this point in the history
See vapor/leaf#235 for details.
  • Loading branch information
grantjbutler committed Oct 28, 2024
1 parent 726c187 commit 0a999d2
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions Sources/SwiftVite/ViteTag.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if canImport(Leaf)
import Leaf
import Vapor

enum ViteTagError: Error {
case invalidResourceParameter
Expand Down Expand Up @@ -37,12 +38,30 @@ struct ViteTag: UnsafeUnescapedLeafTag {
}

private extension LeafContext {
// This is to work around this bug in Leaf:
// https://github.com/vapor/leaf/pull/235
private var _application: Application? {
guard let value = userInfo["application"] else {
return nil
}

if let app = value as? Application {
return app
}

if let leaf = value as? Application.Leaf {
return leaf.application
}

return nil
}

var viteManifest: ViteManifest {
return application?.vite.withManifest({ $0 }) ?? [:]
return _application?.vite.withManifest({ $0 }) ?? [:]
}

var viteEnvironment: Vite.Environment {
return application?.environment == .production
return _application?.environment == .production
? .production
: .development
}
Expand Down

0 comments on commit 0a999d2

Please sign in to comment.