Skip to content

Conversation

@nami8824
Copy link

What is this PR solving?

This PR fixes an issue where absolute ?raw imports from files in publicDir(e.g. /raw.txt?raw) throw an import analysis error, even though they work correctly at runtime.

This mismatch causes unnecessary IDE errors and confusion for users.

Fixes #21277

@sapphi-red
Copy link
Member

While I understand the motivation, it feels confusing to me that the content won't change even if you change the content after bundling. This behavior differs from other behaviors related to the public directory.

An output like below would behave like I'd expect, but it'll require TLA.

const res = await fetch('/_redirect')
const content = await res.text()
export default content
@nami8824
Copy link
Author

I think this behavior already comes from the existing implementation in packages/vite/src/node/plugins/asset.ts.

Should this PR also change that behavior?

Regarding the point:

it feels confusing to me that the content won't change even if you change the content after bundling. This behavior differs from other behaviors related to the public directory.

This feels like a different issue to me, rather than something introduced by this PR.

@sapphi-red
Copy link
Member

I think this behavior already comes from the existing implementation in packages/vite/src/node/plugins/asset.ts.

Yes, and that's fine because that behavior only exists for non-public files which is meant to be bundled.

it feels confusing to me that the content won't change even if you change the content after bundling. This behavior differs from other behaviors related to the public directory.

This feels like a different issue to me, rather than something introduced by this PR.

It is a behavior introduced by this PR by allowing ?raw for public files.

@nami8824
Copy link
Author

nami8824 commented Jan 14, 2026

Thanks for pointing this out.

Would it be acceptable to allow ?raw imports from publicDir, but implement them via a runtime fetch, like:

const res = await fetch('/_redirect')
const content = await res.text()
export default content

This would better match the expected behavior of public assets.

If this approach turns out to be too complex for me to implement correctly, I may close this PR and revisit it later.

@bluwy
Copy link
Member

bluwy commented Jan 15, 2026

While I understand the motivation, it feels confusing to me that the content won't change even if you change the content after bundling. This behavior differs from other behaviors related to the public directory.

I think this is fine for me since ?raw usually means a macro that works at the time of bundling. If a bundled asset is both used via ?url and ?raw then theoretically it could also diverge if changed. Is there a behaviour where the public directory would work differently now?

@sapphi-red
Copy link
Member

sapphi-red commented Jan 15, 2026

If a bundled asset is both used via ?url and ?raw then theoretically it could also diverge if changed.

I think this is not a problem because I'd expect the bundled assets (i.e. the assets not in the public directory) to be immutable. On the other hand, I don't think assets in public directory can be always treated as immutable.

Is there a behaviour where the public directory would work differently now?

I'm not sure if I follow this question. I think the assets in the public directory are always externalized from the bundle.

@bluwy
Copy link
Member

bluwy commented Jan 15, 2026

It's about your comment:

This behavior differs from other behaviors related to the public directory.

I wonder if there are current behaviors you're thinking of that makes this feature request an odd one out.


I still think though that supporting ?raw for public files is harmless here. It being dynamically live-updated would be surprising to me, compared to ?raw always being consistent in how it works for any files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants