typst / webapp-issues

Issue tracker for Typst's web app.
https://typst.app
9 stars 0 forks source link

File not found errors in typst web application with a template that works with a locally installed typst CLI #310

Open SeSodesa opened 3 months ago

SeSodesa commented 3 months ago

Description

A typst template for our university theses (here) does not work with the typst web application due to file not found errors. The problem seems to be related to a discrepancy in how paths are resolved with #import and #include in the local binary and the web application: the locally installed typst compiler seems to expect that when a file is imported, the import path should be relative to the file where the import statement is (example). However, if this project is uploaded to the typst web application as-is, this not longer works: the import paths need to be changed such that they are relative to the main.typ file, or file not found errors are encountered.

The local typst CLI and the web application import paths should be resolved identically. Otherwise users will encounter unnecessary issues with project compilation.

Reproduction URL

https://gitlab.com/tuni-official/thesis-templates/tau-typst-thesis-template

Browsers

Firefox

OS

Linux

laurmaedje commented 3 months ago

The web app also resolves paths relatively.

Are you referring to import errors with the file tiivistelmä.typ? I managed to reproduce a problem and the cause seems to be that the file name is tiivistelmä.typ, but the import statement is tiivistelmä.typ. Those strings look the same, but the äs are different. The first is a single codepoint U+00E4 (Latin Small Letter A with Diaeresis), while the second is an a followed by U+0308 (Combining Diaeresis). Looks like local file systems normalize this difference, while the web app doesn't.

A potential fix might be to perform some form of Unicode normalization in this piece of code.

SeSodesa commented 3 months ago

The ä does not seem to be the issue, at least not at first glance, as the errors are removed and the template compiles, if all ../ are removed from the import statements in the contents/ folder.

SeSodesa commented 3 months ago

An that is on the web application. I'll try renaming the file to tiivistelma.typ and see if that helps in a case where I don't remove the relative paths.

SeSodesa commented 3 months ago

Ok, this is strange: I just now logged in to the web app and opened the project, and received the same errors as before removing the ../ from the import paths. After adding the ../ back in the project now compiles again. In other words, during this session the web app paths now seems to function as they do locally.

laurmaedje commented 3 months ago

Might be similar to https://github.com/typst/webapp-issues/issues/254, where the app gets into a bad state, but a reload fixes it.

SeSodesa commented 3 months ago

It might be. What #254 has in common with my problem is that of course when I upload the thesis template files to a fresh typst web app project, the default main.typ in there gets replaced by the one in the template. Maybe the order in which the files are added into the web app when uploading multiple files, and the replacement of the main.typ file holds significance here?

SeSodesa commented 3 months ago

However, even logging out and back in does not resolve #244. Is there some security measure in place in the web app, so that arbitrary file types cannot be uploaded there?

laurmaedje commented 3 months ago

244 is related to MIME types most likely. We currently store MIME types when files are uploaded and those seem to get out of sync with the file extension in some cases.