Navigation Menu

Skip to content
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

Missing DocC sidebar content #2036

Closed
mattmassicotte opened this issue Sep 19, 2022 · 45 comments
Closed

Missing DocC sidebar content #2036

mattmassicotte opened this issue Sep 19, 2022 · 45 comments
Labels
bug Something isn't working

Comments

@mattmassicotte
Copy link
Sponsor

I've been working on my docs for https://swiftpackageindex.com/ChimeHQ/ChimeKit. I was surprised to see the sidebar was empty, showing just the target name and "No data available."

In Xcode's doc viewer, I see this:

Screenshot 2022-09-19 at 7 04 55 AM

I'm pretty new to docc, so I could definitely be doing something wrong. I also cannot quite figure out how to generate local static web content, but I'm working on it...

@mattmassicotte mattmassicotte added the bug Something isn't working label Sep 19, 2022
@mattmassicotte
Copy link
Sponsor Author

I just looked at a few other packages, and they don't seem to have this issue. Something is special about mine, but I don't understand what yet...

@daveverwer
Copy link
Member

daveverwer commented Sep 19, 2022

Do you have an example of a package we're generating with 5.7 docs that doesn't have this issue? It'll save me a little time finding one!

@mattmassicotte
Copy link
Sponsor Author

@daveverwer
Copy link
Member

Thanks, Matt! We'll look into this.

@mattmassicotte
Copy link
Sponsor Author

Ok and here's another one of mine with no sidebar at all! Obviously this is my issue somehow...

https://swiftpackageindex.com/ChimeHQ/ConcurrencyPlus/0.3.1/documentation/concurrencyplus

@finestructure
Copy link
Member

This one hasn't been built with 5.7 - that's why it doesn't have one: https://swiftpackageindex.com/ChimeHQ/ConcurrencyPlus/builds

You can see that the 5.7 builds are still pending. It should update once those go through.

@finestructure
Copy link
Member

ChimeKit has data for the second target: https://swiftpackageindex.com/ChimeHQ/ChimeKit/main/documentation/chimelspadapter

Is there perhaps some difference between the two?

I'll check the detailed builds logs.

@finestructure
Copy link
Member

It looks like that's the only target that had docs generated:

Generating documentation for 'ChimeLSPAdapter'...
Converting documentation...
Conversion complete! (0.17s)
Generated DocC archive at '/Users/builder/builds/ogLoW6xX/2/finestructure/swiftpackageindex-builder/spi-builder-workspace/.docs/chimehq/chimekit/main'
========================================
SyncDocs
========================================
Syncing directory: spi-builder-workspace/.docs/chimehq/chimekit/main
13	spi-builder-workspace/.docs/chimehq/chimekit/main

https://swiftpackageindex.com/builds/43CE99B2-3FB2-468D-97A2-0E3607B21C9C

@finestructure
Copy link
Member

Ah no, the first target is being processed but there are some warnings which perhaps cause issues?

Generating documentation for 'ChimeExtensionInterface'...
Converting documentation...
/Users/builder/builds/ogLoW6xX/2/finestructure/swiftpackageindex-builder/spi-builder-workspace/Sources/ChimeExtensionInterface/ChimeExtensionInterface.docc/Tutorials/BuildingExtension.tutorial:6:5: warning: 'Chapter' directive requires exactly one 'Image' child directive
/Users/builder/builds/ogLoW6xX/2/finestructure/swiftpackageindex-builder/spi-builder-workspace/Sources/ChimeExtensionInterface/Scenes.swift:16:5: warning: Topic reference 'doc:Extensions' couldn't be resolved. No local documentation matches this reference.
/Users/builder/builds/ogLoW6xX/2/finestructure/swiftpackageindex-builder/spi-builder-workspace/Sources/ChimeExtensionInterface/Scenes.swift:34:5: warning: Topic reference 'doc:Extensions' couldn't be resolved. No local documentation matches this reference.
/Users/builder/builds/ogLoW6xX/2/finestructure/swiftpackageindex-builder/spi-builder-workspace/Sources/ChimeExtensionInterface/Scenes.swift:9:5: warning: Topic reference 'doc:Extensions' couldn't be resolved. No local documentation matches this reference.
/Users/builder/builds/ogLoW6xX/2/finestructure/swiftpackageindex-builder/spi-builder-workspace/Sources/ChimeExtensionInterface/Scenes.swift:59:5: warning: Topic reference 'doc:Extensions' couldn't be resolved. No local documentation matches this reference.

@mattmassicotte
Copy link
Sponsor Author

Hmm, so yes, ChimeKit has multiple targets. But I can see the documentation for the one I'm talking about right here:

https://swiftpackageindex.com/ChimeHQ/ChimeKit/main/documentation/chimeextensioninterface

And as for ConcurrencyPlus, why would the version of Swift influence the docs web configuration?

@finestructure
Copy link
Member

And as for ConcurrencyPlus, why would the version of Swift influence the docs web configuration?

Because we're now building docs with 5.7 but we've not deleted 5.6 generated docs. So only once the 5.7 job goes through will it update the docs to the sidebar version (which is the 5.7 version).

@finestructure
Copy link
Member

To clarify: we're only generating docs for one platform/Swift version combination out of the 24 combos we're building. Before 5.7 that was macos-spm/5.6 (or ios/5.6 if so configured by the author). This is now macos-spm/5.7 (or ios/5.7).

@mattmassicotte
Copy link
Sponsor Author

mattmassicotte commented Sep 19, 2022

Ah no, the first target is being processed but there are some warnings which perhaps cause issues?

Yes, I know about those. Some I just resolved some, but I had assumed since they were warnings and Xcode was doing what I wanted, the web version would as well.

I also didn't realize that the sidebar was a Swift 5.7 thing. Very interesting!

While I have no idea what's special about my docs, I don't yet have any reason to blame SPI. I'm going to try to get the web version working locally and then I'll blame you 😉

@mattmassicotte
Copy link
Sponsor Author

Ok, so local version has sidebar content...
Screenshot 2022-09-19 at 12 40 11 PM

@mattmassicotte
Copy link
Sponsor Author

So I was just poking around at the site, and I noticed three resources that are unable to load:

https://swiftpackageindex.com/chimehq/chimekit/main/index/index.json
https://swiftpackageindex.com/chimehq/chimekit/main/data/documentation/chimeextensioninterface.json
https://swiftpackageindex.com/chimehq/chimekit/main/theme-settings.json

Could this be related? I do seem to have these files locally.

@finestructure
Copy link
Member

finestructure commented Sep 19, 2022

Mmmm, all three files exist in S3:

❯ curl -Is https://spi-prod-docs.s3.us-east-2.amazonaws.com/chimehq/chimekit/main/index/index.json
HTTP/1.1 200 OK
x-amz-id-2: bto1oH26BAUB9aJSuc3SLP/Xy0IxzlosLmmzwABIJYj6sx5PvQtlznnLzolG2iqPVoultacuBp0=
x-amz-request-id: NA3HM30XGX9WNQ1X
Date: Mon, 19 Sep 2022 17:42:59 GMT
Last-Modified: Sun, 18 Sep 2022 23:52:27 GMT
ETag: "27c00b71e4710d206c05eeccbfa058b7"
Content-Encoding:
Accept-Ranges: bytes
Content-Type: application/octet-stream
Server: AmazonS3
Content-Length: 40277

~/P/S/spi-builder on main
❯ curl -Is https://spi-prod-docs.s3.us-east-2.amazonaws.com/chimehq/chimekit/main/data/documentation/chimeextensioninterface.json
HTTP/1.1 200 OK
x-amz-id-2: z+maf5cYjiMo6SUwYNvIBZxbuFNqE1WCrA3YoNlDFU910CRs7qyUTeDAGFu0xDRDnre+VhRal7E=
x-amz-request-id: 8RYVQ785NST4PTXD
Date: Mon, 19 Sep 2022 17:43:02 GMT
Last-Modified: Sun, 18 Sep 2022 23:52:35 GMT
ETag: "2462d0e41e1e0b5ac02a19675fc01469"
Content-Encoding:
Accept-Ranges: bytes
Content-Type: application/octet-stream
Server: AmazonS3
Content-Length: 10706

~/P/S/spi-builder on main
❯ curl -Is https://spi-prod-docs.s3.us-east-2.amazonaws.com/chimehq/chimekit/main/theme-settings.json
HTTP/1.1 200 OK
x-amz-id-2: llQcijcy4q9pYlwL07YPpO1P9guGri/5gg9Ued5jp3RKstvb8FwYpu6nQonRnwoZOh+F0t0bevY=
x-amz-request-id: BXP8RZ1W0ZDV1G3C
Date: Mon, 19 Sep 2022 17:43:05 GMT
Last-Modified: Sun, 18 Sep 2022 23:52:27 GMT
ETag: "c32c89edc3e90d958bc64aa22538c9ff"
Content-Encoding:
Accept-Ranges: bytes
Content-Type: application/octet-stream
Server: AmazonS3
Content-Length: 1089

Are you getting any 404s in the browser console?

I'm not, FWIW.

Can you reproduce the broken sidebar if you remove the files locally?

@finestructure
Copy link
Member

Also, and this shouldn't make a difference but 🤷‍♂️, are you getting the same result if you build and preview the docs via SPM (like we do)?

swift package --disable-sandbox preview-documentation --target ChimeExtensionInterface

For this to work, you'll need to add the docc plugin to your package's dependencies temporarily:

        .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),

@mattmassicotte
Copy link
Sponsor Author

Ok, I think the problems loading the files is user error on my part. I can load them if I just put the URL in - it seems Safari's resource inspector was just unhappy...

@mattmassicotte
Copy link
Sponsor Author

mattmassicotte commented Sep 19, 2022

Just tried out the SPM-based preview. Sidebar has expected content.

@finestructure
Copy link
Member

If you could try this, please? (I edited the message after posting, sorry!)

Can you reproduce the broken sidebar if you remove the files locally?

I'll try running this in the debugger locally tomorrow but it'd be really helpful to know which file exactly is not being proxied. It's going to be super hard to know what to look for otherwise 😅

One other (unlikely) thing that could be happening is that Cloudflare "cached" something as unavailable and it'll just take a while to be available on retry. I believe the TTL is 4h, so this might already be ruled out depending on when you first observed this.

@mattmassicotte
Copy link
Sponsor Author

I thought I might have found something. Was noticing resources that differ by case. But, it looks like a package whose sidebar works right also has the same thing.

Screenshot 2022-09-19 at 1 54 30 PM

@mattmassicotte
Copy link
Sponsor Author

I suspected caching too.

I've been looking more closely at the code, and I can only see two things that are special about this package: it has multiple documentation targets and it can only be built with Swift 5.7.

@finestructure
Copy link
Member

Let's try this: I've attached a zip with the content of the chimekit bucket in S3. The problem must be in the diff of this and your working local copy. I'll add the command to generate the docs for hosting in a moment.

chimekit.zip

@finestructure
Copy link
Member

This should be the equivalent of what we're doing builder-side:

#!/bin/bash

set -eu

OWNER="$1"
REPO="$2"
TARGET="$3"

[ ! -d "$OWNER" ] && mkdir "$OWNER"

export DOCC_JSON_PRETTYPRINT="YES"

swift package \
	--allow-writing-to-directory "$OWNER" \
	generate-documentation \
    --disable-indexing \
    --transform-for-static-hosting \
    --output-path "$OWNER"/"$REPO" \
	--hosting-base-path "$OWNER"/"$REPO" \
	--target "$TARGET"

@mattmassicotte
Copy link
Sponsor Author

I've been starting up a local webserver in the exported directory, and then navigating to the pages in safari. When I do this with my exported copy, it works. I'm not able to use the same technique to load the copy you sent me. I am sometimes (but no always) getting errors in the server console:

::1 - - [19/Sep/2022:14:24:39 EDT] "GET /documentation/ HTTP/1.1" 200 1225
- -> /documentation/
[2022-09-19 14:24:43] ERROR `/chimehq/chimekit/main/css/index.12bb178a.css' not found.
::1 - - [19/Sep/2022:14:24:43 EDT] "GET /chimehq/chimekit/main/css/index.12bb178a.css HTTP/1.1" 404 314
http://localhost:4567/documentation/chimeextensioninterface/ -> /chimehq/chimekit/main/css/index.12bb178a.css
[2022-09-19 14:24:43] ERROR `/chimehq/chimekit/main/js/chunk-vendors.b24b7aaa.js' not found.
[2022-09-19 14:24:43] ERROR `/chimehq/chimekit/main/js/index.58e30ec4.js' not found.

These never happen with my locally-generated copy.

@mattmassicotte
Copy link
Sponsor Author

Oh wait, I think understand what's wrong...

@mattmassicotte
Copy link
Sponsor Author

Yes, has to be rooted with the same path. Ok, "success"! I've loaded your copy and it indeed is missing a sidebar!

@mattmassicotte
Copy link
Sponsor Author

From your copy, some missing files:

chimehq/chimekit/main/index/availability.index
chimehq/chimekit/main/index/data.mdb
chimehq/chimekit/main/index/navigator.index

I moved my local copies in, thinking for sure that would fix it, but it did not!

@finestructure
Copy link
Member

Not sure these are relevant - ParseSwift doesn't have them but shows a sidebar:

CleanShot 2022-09-20 at 09 21 59@2x

@finestructure
Copy link
Member

finestructure commented Sep 20, 2022

I have the suspicion that this is happening because of a work-around we've had to employ to make multi-target docs work.

As far as I know, there's no way to process all targets at once. So what we're doing is looping over configured documentation targets and generating docs for each in turn. The problem is that DocC clobbers the output directory on each run. To work around that we copy the output to a staging directory for upload after each target.

My suspicion is that there's an aggregate file for the sidebar and what we're seeing is "last file wins". That's why it works for the second target ChimeLSPAdapter. One easy way to test this would be to swap the targets around.

This would also explain why it works fine for ParseSwift - it has only one target.

@icanzilb is the DocC expert - could this be what's happening? Do you know which files drive the sidebar?

@finestructure
Copy link
Member

It's the index/index.json file. If I copy that over from our multi-target version to a local preview generated via:

swift package --disable-sandbox plugin preview-documentation --output-path ".docs/chimehq/chimekit/main" --target ChimeExtensionInterface

I get

CleanShot 2022-09-20 at 10 24 05@2x

That seems to confirm that we're clobbering the first target with the second target's index.json file.

I'm not sure how we're going to generate multi-target docs unless there's a built-in way to pass in multiple targets to the generator.

@finestructure
Copy link
Member

I'll write something up for the Swift forums to ask for help.

@finestructure
Copy link
Member

finestructure commented Sep 20, 2022

Ok, I've done something horrible - and it works 😬

The index.json file has a pretty simple structure and it looks as follows for the two targets:

CleanShot 2022-09-20 at 11 54 04@2x

CleanShot 2022-09-20 at 11 54 12@2x

They're easily mergeable:

struct Index: Codable {
    var interfaceLanguages: Language
    var schemaVersion: Version

    struct Language: Codable {
        var swift: [Child]

        struct Child: Codable {
            var children: [Child]?
            var path: String?
            var title: String
            var type: String
        }
    }

    struct Version: Codable {
        var major: Int
        var minor: Int
        var patch: Int
    }
}

let data1 = try Data(contentsOf: URL(fileURLWithPath: file1))
let index1 = try JSONDecoder().decode(Index.self, from: data1)

let data2 = try Data(contentsOf: URL(fileURLWithPath: file2))
let index2 = try JSONDecoder().decode(Index.self, from: data2)

let merged = Index.init(
    interfaceLanguages: .init(swift: index1.interfaceLanguages.swift + index2.interfaceLanguages.swift),
    schemaVersion: index1.schemaVersion
)

let mergedData = try JSONEncoder().encode(merged)
try mergedData.write(to: URL(fileURLWithPath: mergedFile))

We could just do that for now until there's a better solution. It's hacky but it's not like we could break it any further.

I've uploaded the index.json I've merged to S3 and you can see that the docs are working now.

@mattmassicotte
Copy link
Sponsor Author

Wow, fantastic work.

Is your plan to leave this in place until you find a more official solution?

@finestructure
Copy link
Member

I think unless I hear otherwise from the docc folks I'll add this workaround to the builder for now, yes. Note that the current docs are manually patched for that repo and will break again once you push a change.

I'll update this issue once I've added the workaround!

@icanzilb
Copy link
Collaborator

@finestructure the sidebar release is after my time, I know how I'd build it myself but no idea how it's actually working in the release

@finestructure
Copy link
Member

No worries, thanks for the info @icanzilb !

@finestructure
Copy link
Member

Just to update this issue: DocC's sidebar currently does not support multiple targets. Our workaround above should be ok for now and there's currently not really any other way to achieve this.

@finestructure
Copy link
Member

finestructure commented Sep 21, 2022

@finestructure
Copy link
Member

This is deployed and it's fixed last night's re-run with the broken sidebar. (NB: make sure to reset your local browser cache to refresh this properly. Mine was showing a broken sidebar initially.)

@mattmassicotte
Copy link
Sponsor Author

Thank you so, so much! Really amazing how quickly you got this understood and fixed.

@Mordil
Copy link
Collaborator

Mordil commented Sep 25, 2022

I'm seeing this with RediStack https://swiftpackageindex.com/Mordil/RediStack/master/documentation/redistack

Is there something in particular that has to be done to make the package be built with 5.7, or is it just a batch job y'all limit & control which packages goes into which batch?

@finestructure
Copy link
Member

I see you’ve pushed to master 30 mins ago and before that the last commit was on Aug 21. Once the current master has been processed (within the next 24h), it should correct itself.

(The reason you see 5.7 generated docs at all is because we processed the package when catching up with 5.7 builds but that pass must have run without the fix for this.)

@Mordil
Copy link
Collaborator

Mordil commented Sep 25, 2022

Oh, got it. I don’t know why that didn’t occur to me. Thanks Sven!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants