Skip to content

Fallback on Group for unknown Views #1482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9b68dbe
Swift 6 language mode
carson-katri Oct 17, 2024
1ef0156
Exclude navigationViewStyle and disclosureGroupStyle
carson-katri Oct 17, 2024
29f922f
Remove AnyNavigationViewStyle
carson-katri Oct 17, 2024
cedd12b
Initial changes for using uniffi bindings
simlay Mar 2, 2024
1a56ba6
Fix tests
simlay Mar 14, 2024
d83e886
Updates to fix change closure
simlay Apr 12, 2024
6546c07
Fix build after rebase
simlay Apr 12, 2024
1a35424
Update for LVN Core `0.4.0-alpha-4`, remove Fragment handling
carson-katri Sep 4, 2024
a3623aa
Working LiveSocket/LiveChannel usage
carson-katri Sep 10, 2024
c4d2beb
Update to include stylesheet and dead render
carson-katri Sep 11, 2024
7edef27
Use LiveChannel.document and add LiveViewCoordinator.disconnect
carson-katri Sep 12, 2024
ff5ed19
Add JsonEncoder to convert Encodable to LiveViewNativeCore.Json
carson-katri Sep 12, 2024
344eb59
Add `JsonDecoder` to convert `Json` back into a `Decodable` type
carson-katri Sep 12, 2024
8c1424c
Add status listener
carson-katri Sep 17, 2024
427be76
Working navigation (with server-side error on phx_leave)
carson-katri Sep 19, 2024
fafef8e
Live reload
carson-katri Oct 17, 2024
92544bd
Update to alpha 11 of lvn-core
carson-katri Oct 17, 2024
9b1249a
Fix build issues after rebase
carson-katri Oct 17, 2024
6a932e4
Fix build for Swift 6
carson-katri Oct 22, 2024
d38f9d9
Surface connection errors
carson-katri Oct 22, 2024
c17e7c0
Close live reload channel before socket disconnects
carson-katri Oct 23, 2024
337fa49
Add `fileImporter` support
carson-katri Oct 23, 2024
3114d78
Pass mime type to fix file validation
carson-katri Oct 23, 2024
83b304a
Apply reply payload from file validation
carson-katri Oct 23, 2024
b9e4d43
Add public API for file uploads on FormModel
carson-katri Oct 29, 2024
984537a
Fix memory leaks
carson-katri Oct 31, 2024
7d75ab0
Fix Swift frontend crash
carson-katri Oct 31, 2024
23c5ad0
Cancel tasks on deinit
carson-katri Nov 5, 2024
9c44410
Use Group for unknown views
carson-katri Nov 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down Expand Up @@ -26,13 +26,13 @@ let package = Package(
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/scinfu/SwiftSoup.git", from: "2.3.2"),
.package(url: "https://github.com/davidstump/SwiftPhoenixClient.git", .upToNextMinor(from: "5.3.2")),
.package(url: "https://github.com/apple/swift-async-algorithms", from: "0.1.0"),
.package(url: "https://github.com/liveview-native/liveview-native-core-swift.git", exact: "0.2.1"),
.package(url: "https://github.com/apple/swift-async-algorithms", from: "1.0.0"),
.package(url: "https://github.com/liveview-native/liveview-native-core", exact: "0.4.0-alpha-11"),

.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.2"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
.package(url: "https://github.com/swiftlang/swift-markdown.git", from: "0.2.0"),

.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "509.0.2"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "600.0.1"),

.package(url: "https://github.com/pointfreeco/swift-parsing", from: "0.13.0"),
],
Expand All @@ -45,7 +45,7 @@ let package = Package(
"SwiftSoup",
"SwiftPhoenixClient",
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
.product(name: "LiveViewNativeCore", package: "liveview-native-core-swift"),
.product(name: "LiveViewNativeCore", package: "liveview-native-core"),
"LiveViewNativeMacros",
"LiveViewNativeStylesheet"
],
Expand Down Expand Up @@ -146,7 +146,7 @@ let package = Package(
name: "LiveViewNativeStylesheet",
dependencies: [
"LiveViewNativeStylesheetMacros",
.product(name: "LiveViewNativeCore", package: "liveview-native-core-swift"),
.product(name: "LiveViewNativeCore", package: "liveview-native-core"),
.product(name: "Parsing", package: "swift-parsing"),
]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,36 @@ import Foundation
@main
struct BuiltinRegistryGeneratorPlugin: BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
guard let target = target as? SourceModuleTarget else { return [] }
guard let target = target as? SwiftSourceModuleTarget else { return [] }
let tool = try context.tool(named: "BuiltinRegistryGenerator")
let output = context.pluginWorkDirectory.appending("BuiltinRegistry+Views.swift")
let output = context.pluginWorkDirectoryURL.appending(path: "BuiltinRegistry+Views.swift")
let viewFiles = target.sourceFiles
.filter({ $0.path.string.starts(with: target.directory.appending("Views").string) })
.filter({ $0.url.pathComponents.starts(with: target.directoryURL.appending(path: "Views").pathComponents) })
.filter({ $0.type == .source })
.map(\.path)
.map(\.url)
let modifierFiles = target.sourceFiles
.filter({ $0.path.string.hasSuffix("_GeneratedModifiers.swift") })
.filter({ $0.url.lastPathComponent == "_GeneratedModifiers.swift" })
.filter({ $0.type == .source })
.map(\.path)
.map(\.url)
let arguments: [String] = [target.directoryURL.path(percentEncoded: false), output.path(percentEncoded: false)] +
viewFiles
.reduce(into: [String]()) { partialResult, url in
partialResult.append("--view")
partialResult.append(url.path(percentEncoded: false))
}
+ modifierFiles
.reduce(into: [String]()) { partialResult, url in
partialResult.append("--modifier")
partialResult.append(url.path(percentEncoded: false))
}
print(viewFiles)
print(modifierFiles)
print(arguments)
return [
.buildCommand(
displayName: tool.name,
executable: tool.path,
arguments: [target.directory.string, output.string] +
viewFiles
.reduce(into: [String]()) { partialResult, path in
partialResult.append("--view")
partialResult.append(path.string)
}
+ modifierFiles
.reduce(into: [String]()) { partialResult, path in
partialResult.append("--modifier")
partialResult.append(path.string)
},
executable: tool.url,
arguments: arguments,
environment: [:],
inputFiles: viewFiles + modifierFiles,
outputFiles: [output]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import Foundation
struct DocumentationExtensionGeneratorPlugin: CommandPlugin {
func performCommand(context: PluginContext, arguments: [String]) throws {
let process = Process()
process.executableURL = URL(fileURLWithPath: try context.tool(named: "DocumentationExtensionGenerator").path.string)
process.executableURL = try context.tool(named: "DocumentationExtensionGenerator").url

let target = context.package.targets.first(where: { $0.name == "LiveViewNative" })! as! SourceModuleTarget
let target = context.package.targets.first(where: { $0.name == "LiveViewNative" })! as! SwiftSourceModuleTarget
let viewFiles = target.sourceFiles
.filter({ $0.path.string.starts(with: target.directory.appending("Views").string) })
.filter({ $0.url.pathComponents.starts(with: target.directoryURL.appending(path: "Views").pathComponents) })
.filter({ $0.type == .source })
.map(\.path)
.map(\.url)

process.arguments = arguments
+ viewFiles
.reduce(into: [String]()) { partialResult, path in
.reduce(into: [String]()) { partialResult, url in
partialResult.append("--view")
partialResult.append(path.string)
partialResult.append(url.path())
}

try process.run()
Expand Down
10 changes: 8 additions & 2 deletions Sources/BuiltinRegistryGenerator/BuiltinRegistryGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ struct BuiltinRegistryGenerator: ParsableCommand {
"RoundedRectangle": "Shape<R, RoundedRectangle>(shape: RoundedRectangle(from: element))",
"Color": "ColorView<R>()",
"Image": "ImageView<R>()",
"phx-main": "PhxMain<R>()"

// FIXME: The server should send a platform-specific tag name, or core should have the ability to split the dead render from the main app.
"div": "PhxMain<R>()"
]

var platformFamilyName: String? {
Expand All @@ -66,6 +68,9 @@ struct BuiltinRegistryGenerator: ParsableCommand {
let generated = """
import SwiftUI
import LiveViewNativeStylesheet
import OSLog

private let logger = Logger(subsystem: "LiveViewNative", category: "BuiltinRegistry")

// This switch can't be inlined into BuiltinRegistry.lookup because it results in that method's return type
// being a massive pile of nested _ConditionalContents. Instead, lift it out into a separate View type
Expand All @@ -80,7 +85,8 @@ struct BuiltinRegistryGenerator: ParsableCommand {
\(Self.additionalViews.map(additionalViewCase(name:initializer:)).joined(separator: "\n"))
default:
// log here that view type cannot be found
EmptyView()
let _ = logger.error("'<\\(name)>' is not a known element.")
Group<R>()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/LiveViewNative/BuiltinRegistry+applyBinding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum _EventBinding: String {
}

extension BuiltinRegistry {
@MainActor
@ViewBuilder
static func applyBinding(
_ binding: _EventBinding,
Expand Down
4 changes: 2 additions & 2 deletions Sources/LiveViewNative/Coordinators/LiveConnectionError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
import SwiftPhoenixClient
@preconcurrency import SwiftPhoenixClient

/// An error that occurred when connecting to a live view.
public enum LiveConnectionError: Error, LocalizedError {
Expand Down Expand Up @@ -43,7 +43,7 @@ public enum LiveConnectionError: Error, LocalizedError {
}
}

public enum InitialParseComponent: CustomStringConvertible {
public enum InitialParseComponent: CustomStringConvertible, Sendable {
case document
case csrfToken
case phxMain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public struct LiveSessionConfiguration {
self.reconnectBehavior = reconnectBehavior
}

public struct ReconnectBehavior {
let delay: ((_ tries: Int) -> TimeInterval)?
public struct ReconnectBehavior: Sendable {
let delay: (@Sendable (_ tries: Int) -> TimeInterval)?

public init(_ delay: @escaping (_ tries: Int) -> TimeInterval) {
public init(_ delay: @escaping @Sendable (_ tries: Int) -> TimeInterval) {
self.delay = delay
}

Expand Down
Loading
Loading