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(hmr): add timestamp for assets in dev #13371

Merged
merged 1 commit into from
Oct 17, 2023
Merged

fix(hmr): add timestamp for assets in dev #13371

merged 1 commit into from
Oct 17, 2023

Conversation

ArnaudBarre
Copy link
Member

Fixes: #13379

@ArnaudBarre ArnaudBarre self-assigned this May 29, 2023
@stackblitz
Copy link

stackblitz bot commented May 29, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@ArnaudBarre
Copy link
Member Author

Expected various break of existing test on the exact matching of path. I will fix them once we agree on the fix!

@patak-dev patak-dev added feat: hmr p3-minor-bug An edge case that only affects very specific usage (priority) labels May 30, 2023
@@ -179,7 +179,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {

id = id.replace(urlRE, '$1').replace(unnededFinalQueryCharRE, '')
const url = await fileToUrl(id, config, this)
return `export default ${JSON.stringify(url)}`
return `export default ${JSON.stringify(`${url}?t=${Date.now()}`)}`
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't do this for public files, no?

I'm thinking we may also need to wait for Vite 5 to apply this change 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I need to test how this behaves for public files. But I think this currently marked as deprecated to import public files in source code so I would not worry too much about this.

What are you afraid it will break apart from test suite that are using exact match for paths?

Copy link
Member

Choose a reason for hiding this comment

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

I would think that projects shouldn't break as having a ?t= is expected. It still feels like a non-trivial change. Maybe we could move with it during the 4.4 beta and we see if some projects have issues with this.

Copy link
Member

Choose a reason for hiding this comment

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

But I think this currently marked as deprecated to import public files in source code so I would not worry too much about this.

I don't think it's deprecated (see https://vitejs.dev/guide/assets.html#the-public-directory). But nevertheless I don't see much harm if we add the timestamp for them either.

I think however we should only add the timestamp in dev.

@ArnaudBarre ArnaudBarre added this to the 4.4 milestone May 31, 2023
@patak-dev
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

vite-ecosystem-ci bot commented Jun 6, 2023

📝 Ran ecosystem CI: Open

suite result
astro ✅ success
histoire ✅ success
iles ✅ success
ladle ✅ success
laravel ✅ success
marko ❌ failure
nuxt ❌ failure
nx ✅ success
previewjs ✅ success
qwik ✅ success
rakkas ❌ failure
sveltekit ❌ failure
unocss ✅ success
vite-plugin-pwa ✅ success
vite-plugin-ssr ❌ failure
vite-plugin-react ✅ success
vite-plugin-react-pages ✅ success
vite-plugin-react-swc ✅ success
vite-plugin-svelte ✅ success
vite-plugin-vue ✅ success
vite-setup-catalogue ✅ success
vitepress ✅ success
vitest ❌ failure

@patak-dev
Copy link
Member

SvelteKit and Vitest are new failures in the ecosystem-ci run above. It is getting a bit difficult to work with so many reds in the results. But maybe better to check these two before merging.

@patak-dev
Copy link
Member

Maybe merging main and re-run could also be a good idea.

@ArnaudBarre
Copy link
Member Author

Totally related:
vitest: expected '/src/node_modules/file.mp3?t=16860633…' to be '/src/node_modules/file.mp3'
svletekit:

      -   "http://localhost:5173/src/routes/asset-import/small.png",
      -   "http://localhost:5173/src/routes/asset-import/large.jpg",
      +   "http://localhost:5173/src/routes/asset-import/small.png?t=1686063253094",
      +   "http://localhost:5173/src/routes/asset-import/large.jpg?t=1686063253094",

patak-dev
patak-dev previously approved these changes Jun 9, 2023
Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

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

The tests should be updated to match instead of to be equal. I'm hesitant about doing this change in 4.4, I'll let others comment here. We could try it out and revert, or directly move this one to Vite 5.

@bluwy
Copy link
Member

bluwy commented Jun 10, 2023

I think it's a bit borderline a breaking change that it would be safer to move it to Vite 5. Some user apps who used ?url might not anticipated the path to contain queries too.

@patak-dev patak-dev modified the milestones: 4.4, 5.0 Jun 10, 2023
@patak-dev
Copy link
Member

Ok, let's move it to Vite 5 👍🏼

@bluwy bluwy changed the title fix: hmr for assets fix(hmr): add timestamp for assets in dev Oct 16, 2023
@patak-dev patak-dev merged commit 40ee245 into main Oct 17, 2023
11 checks passed
@patak-dev patak-dev deleted the asset-hmr branch October 17, 2023 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: hmr p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

images update not trigger hot reload or page update
3 participants