Skip to content

fix mobile importJs - #1

Merged
mProjectsCode merged 1 commit into
mProjectsCode:masterfrom
Krakor92:master
Sep 7, 2023
Merged

mProjectsCode merged 1 commit into
mProjectsCode:masterfrom
Krakor92:master

Conversation

@Krakor92

@Krakor92 Krakor92 commented Sep 7, 2023

Copy link
Copy Markdown
Contributor

I'm gonna rewrite here what I've written on Discord to have the context of this PR:

DataAdapter.getResourcePath method doesn't have the same behavior on computer and on mobile. While they both returns the absolute path of the resource passed in parameter, the desktop version append a ?mtime suffix at the end, which correspond to the file's modified time. This let the import(fullPath) in API.ts know when the resource can be cached hit or not. Unfortunately since this suffix isn't added on mobile (I'd be interested to know the reason behind this), the import always return the cached version of the file. Thus, only a full reload of the app flush the cache on mobile (I guess)

I think that using getFirstLinkpathDest, to retrieve a TFile of the imported script is the cleanest workaround. That way I can append the TFile.mtime directly at the end of path to optimize cache hits.

Comment thread src/api/API.ts
public async importJs(path: string): Promise<any> {
const fullPath = this.app.vault.adapter.getResourcePath(path);
let fullPath = this.app.vault.adapter.getResourcePath(path);
if (!fullPath.includes('?')) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the path on mobile includes a ? somewhere along the way?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this/is/a?path/foo.js

@Krakor92 Krakor92 Sep 7, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it have one? Isn't ? an illegal character to have in a path or in a filename? If you're talking about a mobile path that already contains query parameters then It shouldn't be the case since on mobile, getResourcePath doesn't append anything at the end of the full path.

Edit: If you prefer I can construct an URL object with the full path and check whether or not it has a searchParams.size === 0

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mProjectsCode
mProjectsCode merged commit c22b779 into mProjectsCode:master Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants