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

fix: Improve post-build asset update check #6113

Merged
merged 7 commits into from
Dec 15, 2021
Merged

Conversation

Snugug
Copy link
Contributor

@Snugug Snugug commented Dec 14, 2021

Description

This currently fails on empty attributes (#4030) and links to MPA output (href="/my/mpa/output") that doesn't have a direct disk counterpart. Checking for these things resolves these errors.

Resolves #4030

Additional context

This fixes the MPA issue I'm experiencing (the above link would error as trying to read a directory, related to #4030 but a slightly different usecase). This should resolve all of them.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

This currently fails on empty attributes (vitejs#4030) and links to MPA output (`href="/my/mpa/output"`) that doesn't have a direct disk counterpart. Checking for these things resolves these errors.
@Snugug Snugug changed the title (fix) Improve post-build asset manipulation fix: Improve post-build asset update check Dec 14, 2021
@patak-dev patak-dev added the p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) label Dec 14, 2021
@Snugug Snugug marked this pull request as draft December 14, 2021 22:18
@Snugug Snugug marked this pull request as ready for review December 15, 2021 09:02
@Snugug
Copy link
Contributor Author

Snugug commented Dec 15, 2021

I didn't see any tests for the HTML plugin so I didn't add any for this functionality; hopefully that isn't a blocker to get this to land.

@patak-dev
Copy link
Member

patak-dev commented Dec 15, 2021

The html playground is testing the html related plugins

patak-dev
patak-dev previously approved these changes Dec 15, 2021
@patak-dev
Copy link
Member

LGTM, while we wait for an extra approval it would be good if you could add a simple check in the html playground to avoid future regressions

The only thing the test really cares about is that the build doesn't fail, don't need to test the output of each file
@Snugug
Copy link
Contributor Author

Snugug commented Dec 15, 2021

Ok! I've added a couple of test files; the empty attributes one fails w/o this patch, the link one seems to pass with both, but it'll fail in my codebase w/o my code, so there must be some edgecase that this resolves that isn't getting triggered where absolute anchor links get triggered as attributes and throw this error. That said, I also notice that the HTML playground isn't rendering the rollup input as I would expect per the MPA docs, so maybe that's why it's not being triggered.

@patak-dev patak-dev merged commit 611fa03 into vitejs:main Dec 15, 2021
@haoqunjiang
Copy link
Member

The empty attribute case should fail with a better error message, not silently pass.

In what scenario would you need a <img src="">?

@patak-dev
Copy link
Member

Let's hold releasing while we discuss, sorry if I merged too quickly. I would prefer a warning here myself instead of a hard error, so people can still preview their work, but it is true that this change should be better evaluated first

@Snugug
Copy link
Contributor Author

Snugug commented Dec 15, 2021 via email

@haoqunjiang
Copy link
Member

For that specific question, there's a common lazy loading pattern that uses this

Can you elaborate?

@Snugug
Copy link
Contributor Author

Snugug commented Dec 15, 2021

It's basically this article but with an src="" to ensure the img tag is valid.

The tl;dr of that article is: image tag, no src (or for this, empty src so it's a valid image), use IntersectionObserver to figure out when the image is visible, then swap in the data-src to the src

@Snugug Snugug deleted the patch-1 branch December 15, 2021 16:34
@haoqunjiang
Copy link
Member

Got it. Thanks for the explanation.

I previously thought that <img src=""> would initiate a request to the document itself. Turns out that's not the case.
An empty URL referenced in CSS (e.g. background-image: url("")) would do so, though.

As this PR only touches the code dealing with HTML asset URLs, I think the change is indeed an improvement.
Thanks!

@Snugug
Copy link
Contributor Author

Snugug commented Dec 16, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: html p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[vite:build-html] EISDIR: illegal operation on a directory, read
4 participants