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

Images appear as broken in preview pane in AsciiDoc 3.1.8 #819

Closed
RoxvilleRooster opened this issue Nov 10, 2023 · 22 comments · Fixed by #825
Closed

Images appear as broken in preview pane in AsciiDoc 3.1.8 #819

RoxvilleRooster opened this issue Nov 10, 2023 · 22 comments · Fixed by #825
Labels
🐞 bug ⬜ windows Issues related to Microsoft's Windows

Comments

@RoxvilleRooster
Copy link

RoxvilleRooster commented Nov 10, 2023

Original discussion is in https://asciidoctor.zulipchat.com/#narrow/stream/406819-users.2Fasciidoctor-vscode/topic/images.20missing.20in.20preview

Please provide details about:

  • In the preview pane, view the referenced images as I did with AsciiDoc 3.1.5 and previous releases
  • When I use AsciiDoc 3.1.6 and AsciiDoc 3.1.7, in the preview pane, referenced images show appear as broken
  • In the preview pane, referenced images should be rendered correctly (as they were with AsciiDoc 3.1.5 and previous releases)

Please share relevant sample content. Or better yet, provide a link to a minimal reproducible example.

vscode details:

Version: 1.84.2 (user setup)
Commit: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e
Date: 2023-11-09T10:51:52.184Z
Electron: 25.9.2
ElectronBuildId: 24603566
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.19045

I am specifying no extension properties for asciidoctor (I want to stick to the defaults for this troubleshooting).

Here is the preview pane when I used AsciiDoc 3.1.7
asciidoc_3_1_7

Here is the preview pane when I used AsciiDoc 3.1.5
asciidoc_3_1_5

Attached is very simple project to illustrate:
simple_project_image_preview_issue.zip

This is the text of test.adoc

= Image preview test
:imagesdir: ../images

[qanda]
Is the use of the doc attribute `+:imagesdir: ../images+` a problem?::
This usage was not a problem in the Asciidoctor extension (i.e., AsciiDoc 3.1.5 or previous). 
Does the image resolve in the preview pane when you use the Asciidoctor extension?::
If you use AsciiDoc 3.1.6 or 3.1.7, I do not expect that it will.
If you use AsciiDoc 3.1.5 or earlier, I expect that it will.

.This is a test image - does it resolve in the preview pane?
image::datamart_transaction_data_flow.jpg[]

Install AsciiDoc 3.1.7.
Does the image appear as expected (i.e., not broken) in the preview pane? I expect that the image will appear as broken.

Install AsciiDoc 3.1.5 and reload.
Does the image appear as expected (i.e., not broken) in the preview pane? I expect that the image will appear rendered correctly in the preview pane.

@mojavelinux
Copy link
Member

When I try it using AsciiDoc 3.1.7, I see the image in the preview pane.

@ggrossetie
Copy link
Member

Please note that you don't need to use :imagesdir: ../images if Antora support is enabled.

@ggrossetie
Copy link
Member

When I try it using AsciiDoc 3.1.7, I see the image in the preview pane.

Same here (on Windows) 🤔

@cunka
Copy link

cunka commented Nov 13, 2023

I'm on the new AsciiDoc 3.1.8 - Windows10 - and I can see the image in the preview pane.

I also see the original bug was posted where VSCode is using its native preview, I tested that as well and it all came out fine.

@RoxvilleRooster
Copy link
Author

@ggrossetie
Here is the output from the console if the Developer Tools".

This is what I get with AsciiDoc 3.1.5

WARN Via 'product.json#extensionEnabledApiProposals' extension 'ms-dotnettools.dotnet-interactive-vscode' wants API proposal 'languageConfigurationAutoClosingPairs' but that proposal DOES NOT EXIST. Likely, the proposal has been finalized (check 'vscode.d.ts') or was abandoned.
workbench.desktop.main.js:sourcemap:645  INFO [perf] Render performance baseline is 83ms
workbench.desktop.main.js:sourcemap:1184 An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can escape its sandboxing.
mountTo @ workbench.desktop.main.js:sourcemap:1184
M @ workbench.desktop.main.js:sourcemap:1149
claim @ workbench.desktop.main.js:sourcemap:1149
Db @ workbench.desktop.main.js:sourcemap:2629
workbench.desktop.main.js:sourcemap:1184 An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can escape its sandboxing.
mountTo @ workbench.desktop.main.js:sourcemap:1184
M @ workbench.desktop.main.js:sourcemap:1149
claim @ workbench.desktop.main.js:sourcemap:1149
ib @ workbench.desktop.main.js:sourcemap:1580
setInput @ workbench.desktop.main.js:sourcemap:1580

This is what I see with AsciiDoc 3.1.8

 WARN Via 'product.json#extensionEnabledApiProposals' extension 'ms-dotnettools.dotnet-interactive-vscode' wants API proposal 'languageConfigurationAutoClosingPairs' but that proposal DOES NOT EXIST. Likely, the proposal has been finalized (check 'vscode.d.ts') or was abandoned.
workbench.desktop.main.js:sourcemap:645  INFO [perf] Render performance baseline is 92ms
workbench.desktop.main.js:sourcemap:1184 An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can escape its sandboxing.
mountTo @ workbench.desktop.main.js:sourcemap:1184
2workbench.desktop.main.js:sourcemap:645  WARN Settings pattern "application.*" doesn't match any settings
workbench.desktop.main.js:sourcemap:1184 An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can escape its sandboxing.
mountTo @ workbench.desktop.main.js:sourcemap:1184
workbench.desktop.main.js:sourcemap:1184 An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can escape its sandboxing.
mountTo @ workbench.desktop.main.js:sourcemap:1184
workbench.desktop.main.js:sourcemap:1184 An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can escape its sandboxing.
mountTo @ workbench.desktop.main.js:sourcemap:1184
M @ workbench.desktop.main.js:sourcemap:1149
claim @ workbench.desktop.main.js:sourcemap:1149
ib @ workbench.desktop.main.js:sourcemap:1580
setInput @ workbench.desktop.main.js:sourcemap:1580
datamart_transaction_data_flow.jpg:1     Failed to load resource: the server responded with a status of 401 ()

That Failed to load resource: the server responded with a status of 401 () indicates an error on my end (that did not exist in 3.1.5).

@kodermho
Copy link

I have what appears to be the same issue. Mine appears to be related to case in the path. I have images in same folder as .adoc file
c:\a\test.adoc works fine
c:\A\test.adoc image rendering is broken

AsciiDoc v3.1.8

Version: 1.84.2 (user setup)
Commit: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e
Date: 2023-11-09T10:51:52.184Z
Electron: 25.9.2
ElectronBuildId: 24603566
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.22621

@ggrossetie
Copy link
Member

I have what appears to be the same issue. Mine appears to be related to case in the path. I have images in same folder as .adoc file
c:\a\test.adoc works fine
c:\A\test.adoc image rendering is broken

Are you using an absolute path? Could you please share the content of test.adoc ?

@ggrossetie
Copy link
Member

@RoxvilleRooster looks like a workspace permission issue. Could you please open the network tab and inspect the request that returns a 401.

The URI should be something like:

https://file+.vscode-resource.vscode-cdn.net/path/to/datamart_transaction_data_flow.jpg

Also, do you open your AsciiDoc file in a workspace?

@kodermho
Copy link

kodermho commented Nov 13, 2023

I have what appears to be the same issue. Mine appears to be related to case in the path. I have images in same folder as .adoc file
c:\a\test.adoc works fine
c:\A\test.adoc image rendering is broken

Are you using an absolute path? Could you please share the content of test.adoc ?

Entire adoc

image::test_image.png[]

System:

* Version: 1.84.2 (user setup)
* Commit: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e
* Date: 2023-11-09T10:51:52.184Z
* Electron: 25.9.2
* ElectronBuildId: 24603566
* Chromium: 114.0.5735.289
* Node.js: 18.15.0
* V8: 11.4.183.29-electron.0
* OS: Windows_NT x64 10.0.22621

@kodermho
Copy link

kodermho commented Nov 13, 2023

in a folder
Request URL: https://file+.vscode-resource.vscode-cdn.net/c%3A/a/test_image.png
return 200

in A folder
Request URL: https://file+.vscode-resource.vscode-cdn.net/c%3A/A/test_image.png
return 401(from service worker)

Also, do you open your AsciiDoc file in a workspace?

Not sure. I right click (empty area) in folder > Open with Code

@kodermho
Copy link

kodermho commented Nov 13, 2023

In Console for A I get the error below. In a there is no error.

index.html?id=ad7083…2F%2Fvscode-app:999 
 GET https://file+.vscode-resource.vscode-cdn.net/c%3A/A/test_image.png 401
(anonymous)	@	index.html?id=ad7083…2F%2Fvscode-app:999
setTimeout (async)		
onFrameLoaded	@	index.html?id=ad7083…2F%2Fvscode-app:997
(anonymous)	@	index.html?id=ad7083…F%2Fvscode-app:102

@RoxvilleRooster
Copy link
Author

RoxvilleRooster commented Nov 13, 2023

@RoxvilleRooster looks like a workspace permission issue. Could you please open the network tab and inspect the request that returns a 401.

The URI should be something like:

https://file+.vscode-resource.vscode-cdn.net/path/to/datamart_transaction_data_flow.jpg

Also, do you open your AsciiDoc file in a workspace?

I am using GitHub Desktop and VSCode, So when I edit the docs in a repo, I assume that means I am operating in the workspace. If I save extension settings to the workspace, the settings.json file gets saved in the repo/workspace in .vscode/settings.json).
It is interesting this is may be a workspace permissions issue.
I have no AsciiDoc extension settings specified for the workspace - but maybe that is the problem?

I am not 100% sure that I am doing the right thing but in the Network tab in Developer Tools, I see this (which does not appear new info):

WARN Via 'product.json#extensionEnabledApiProposals' extension 'ms-dotnettools.dotnet-interactive-vscode' wants API proposal 'languageConfigurationAutoClosingPairs' but that proposal DOES NOT EXIST. Likely, the proposal has been finalized (check 'vscode.d.ts') or was abandoned.
log.ts:421  INFO [perf] Render performance baseline is 104ms
webviewElement.ts:512 An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can escape its sandboxing.
mountTo @ webviewElement.ts:512
datamart_transaction_data_flow.jpg:1     Failed to load resource: the server responded with a status of 401 ()

@ggrossetie
Copy link
Member

@RoxvilleRooster could you please take a screenshot of your network tab?

Here's an example where you can see the request that loads the web-console.png image:

image

@kodermho As far as I know, Windows is case insensitive. Do you use WSL? How do you open your test.adoc from either the folder A or a?

@ggrossetie ggrossetie added the ⬜ windows Issues related to Microsoft's Windows label Nov 14, 2023
@kodermho
Copy link

kodermho commented Nov 14, 2023

As far as I know, Windows is case insensitive.

I agree. I not sure how to test that but if I put "c:\a" into run it will open c:\A folder

...Do you use WSL?...

Yes, I use it.

... How do you open your test.adoc from either the folder A or a?

  • I have windows 11.
  1. open a windows explorere window
  2. navigate to c:\A
  3. right click in empty space in folder to get contextual menu
  4. click "open with code"
  5. VScode opens
  6. in the side menu it has sheets of paper with a folded corner icon that open explorer
    1. explorer shows the 2 files in the folder

I am renaming c:\A->a->A->...

@lutopastialis
Copy link

lutopastialis commented Nov 14, 2023

I'm also encountering this issue. By playing around I found that it does have something to do from where I start vscode.

code --version
1.84.2
x64
code --list-extensions --show-versions
asciidoctor.asciidoctor-vscode@3.1.8

I usually launch vscode from the command line in the repository root directory: code ., which then causes this issue.
However, if I launch vscode from the start menu and then manually open the folder, I don't encounter this issue and images are loaded correctly (request OK with 200).

I've also completely reset my entire vscode/asciidoc tool chain during troubleshooting this (uninstalled and deleted all remaining folders, reinstalled). I have the latest stable versions from official sources of all tools involved (vscode user install, asciidoc extension, ruby and asciidoctor gem). Except Windows, unfortunately (Windows 10 Enterprise, 22H2, build 19045.3570).

gem list
asciidoctor (2.0.20)
choco list
Chocolatey v2.2.2
ruby 3.1.3.1

Hope this helps.

@kodermho
Copy link

kodermho commented Nov 14, 2023

Opening just the file in vscode renders image in preview

Edited prcoess from above

  1. open a windows explorere window
  2. navigate to c:\A
  3. right click in empty space in folder on test.adoc to get contextual menu
  4. click "open with code"
  5. VScode opens
  6. Ctrl + Shift + V to view preview works

@ggrossetie
Copy link
Member

@lutopastialis I was able to reproduce this issue by launching VS code from the command line. Interestingly, the Markdown extension is using the exact same request:

Markdown extension

Request URL: https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/gross/Documents/A/mountain.jpeg
Request Method: GET
Status Code: 200 (from service worker)
Referrer Policy: strict-origin-when-cross-origin

AsciiDoc extension

Request URL: https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/gross/Documents/A/mountain.jpeg
Request Method: GET
Status Code: 401 (from service worker)
Referrer Policy: strict-origin-when-cross-origin

It seems like a limitation/bug in VS code... you should open a new issue upstream: https://github.com/microsoft/vscode

@ggrossetie ggrossetie changed the title Images appear as broken in preview pane in AsciiDoc 3.1.6 and AsciiDoc 3.1.7 Images appear as broken in preview pane in AsciiDoc 3.1.8 Nov 16, 2023
@ggrossetie
Copy link
Member

Found a similar issue: microsoft/vscode#197103

@lutopastialis
Copy link

@ggrossetie you beat me to it :) Thank you for adding your comment in the vscode issue thread #197103, I appreciate it. I seem to be among only a few collegues in my team who open vscode almost always from the command line (Powershell 7 and the latest stable Windows Terminal). I've posted this info internally, which really helps as we're working on some very large asciidoc files with lots of images.
Let's observe the upstream issue for a bit and decide whether this needs a separate thread.
Thanks again!

@ggrossetie
Copy link
Member

It seems that VS Code normalizes some paths (on Windows) so I would strongly recommend to use lowercase names to avoid issues.

@ggrossetie
Copy link
Member

Oooh! It seems that we are normalizing the path in:

const folder = getWorkspaceFolder(resource)
if (folder) {
const workspaceRoots = getWorkspaceFolders()?.map((folder) => folder.uri)
if (workspaceRoots) {
baseRoots.push(...workspaceRoots)
}
} else {
baseRoots.push(uri.Utils.dirname(resource))
}
return baseRoots

@ggrossetie
Copy link
Member

I think I finally found the root cause, thanks all for providing reproduction cases! The 401 error was a bit misleading and it was even more weird that in some cases it worked (that's because VS code is using a cache).

Anyway, I will add tests, merge #825, update the CHANGELOG and release 3.1.9 ☺️

ggrossetie added a commit that referenced this issue Nov 19, 2023
Previously, we were applying toLowerCase on the whole path causing the WebView to return 401 on resources (such as images)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug ⬜ windows Issues related to Microsoft's Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants