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

local media assets are not promoted to file attachments in hypertext literals #451

Closed
cinxmo opened this issue Jan 8, 2024 · 1 comment
Assignees
Labels
bug Something isn’t working

Comments

@cinxmo
Copy link
Contributor

cinxmo commented Jan 8, 2024

Local media assets should be promoted to file attachments in hypertext literals.
File structure:

├── docs
│   ├── sub
│   │   ├── pic.jpg
│   └── test.md

In test.md:

```js
const testArray = ['a', 'b', 'c'];
```

```js
function formatLetter(letter) {
	return html`
		<div>
			<img src="./sub/pic.jpg">${letter}</img>
		</div>
	`;
}
```

<div>
	${testArray.map((t) => formatLetter(t))}
</div>

Error:
Running yarn dev and navigating to http://127.0.0.1:3000/test shows a 404 when fetching http://127.0.0.1:3000/sub/pic.jpg.

Expectation:
The fetch for http://127.0.0.1:3000/sub/pic.jpg should be rewritten as http://127.0.0.1:3000/_file/sub/pic.jpg

@cinxmo cinxmo added the bug Something isn’t working label Jan 8, 2024
@cinxmo cinxmo added this to the General availability milestone Jan 8, 2024
@cinxmo cinxmo self-assigned this Jan 8, 2024
@mbostock
Copy link
Member

This isn’t a fixable problem in our current design: we can only promote assets that are declared statically, and anything within a hypertext literal is (by definition, since it’s inside JavaScript source rather than HTML) dynamic. You need to use FileAttachment if you want these assets to be treated as file attachments. I noted this previously in #424 (comment) and probably should be something we document.

(We could try to static analyze html tagged template literals of course, but my point is that you could always have JavaScript that is purely dynamic, so we’re never going to be able to find all the referenced files through static analysis. Therefore I suggest that we don’t try to static analyze beyond what we already do with FileAttachment.)

@mbostock mbostock closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2024
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

2 participants