Perform Document rendering in reversed order to defer Head rendering#806
Conversation
|
Thank you for the contribution @TomaszLizer. I do like suggestion 3 however, but as you mentioned this would incur a significant increase in scope for this PR. I'll convene with the team to see exactly what direction we want to take, and if you're still up for it by then, we will definitely appreciate your contributions. We'll keep you posted right here! cc. @JPToroDev |
|
First off, excellent debugging work, @TomaszLizer! @MrSkwiggs I understand your hesitation about using That approach assumes This is actually a bug that has been revealed via this PR that we can fix. @TomaszLizer I like the first option you suggest, where we find But let's move this behavior to Then we can safely use your How that sounds, everyone? |
|
Adding additional handling in For now I have came up with split of components using reduce and using last public static func buildBlock(_ components: any DocumentElement...) -> some HTML {
Document {
let (header, components) = components.reduce(
into: (header: Head, components: [any DocumentElement])(Head(), [])
) { partialResult, element in
if let header = element as? Head {
// In case multiple headers were provided only last one will be used
partialResult.header = header
} else {
partialResult.components.append(element)
}
}
header
// Add all provided components
for component in components {
component
}
}
}WDYT @MrSkwiggs @JPToroDev ? |
|
Excellent catch! We'd also need to check for multiple I like your approach of using the last one, but we'd also need to add a build warning like:
That said, in SwiftUI, when there are multiple We should likely do the same. Alternatively, we could simply add a That seems a little extreme, but perhaps not since this is more fundamental than a settings screen. Overall thoughts? |
|
I am back after too many rounds of sałatka jarzynowa 😅 In the meantime I was considering different solutions to the above problem and I only found more doubts. Few suggestions that came to my mind to tackle this:
I have no real strong opitions here since I am not WEB dev (this is why I came here to use Ignite and not write html :D) FYI: @JPToroDev @MrSkwiggs [EDIT]: clearly too much sałatka jarzynowa... CLosed PR by accident 😄 |
|
You continue to do truly exceptional work—thank you! You're absolutely right: currently folks can conform types to In fact, since I've done that in the v0.6-beta branch. Now Take a look at that branch, and let me know if it gives you a clear direction from what you've outlined above. I believe your original solution should work as is now. |
|
What you have in the beta branch is basically how I imageined it to be best case scenario- just hold body and head directly. Then rendering becomes trivial, we just do that for body first. |
|
Excellent!
That'd be great! |
Fixes issue where code highlighting was not working for first render path (eg home page)
d152c35 to
133931a
Compare
|
@JPToroDev Rebased on beta branch and updated to accomodate for latest changes. [Edit]: Ofc validated still works as expected :D |
|
Beautiful! Thanks for the great work on this 🙌🏼 |
While tinkering with Ignite I noticed one bug with regards to CodeBlock rendering. It is supposed to automatically pick up Code language and highlight it when using Ignition DSL. This was not working though for the first page with CodeBlock element.
After some debugging I have noticed that we update
PublishingContextwith language of the code block and based on that correct header is to be rendered. Unfortunatelly at that timeHeadof that page is already rendered, hence this update to the context is not reflected.I have considered different approaches:
Documentto haveHeadelement - getting its index (though I believe it should always be 0?) and deferring its rendering phase "manually"PublishingContextSitedefinition?Attaching video with issue reproduced:
Screen.Recording.2025-04-16.at.22.27.29.mov
Issue can be reproduced by having site with homePage having such body:
Alternatively it can be reproduced with https://github.com/twostraws/IgniteSamples when commenting out
syntaxHighlighterConfigurationinSitedefinition.