Skip to content

fix: make HMR working again with latest vite version #999

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

elwin013
Copy link
Contributor

@elwin013 elwin013 commented Apr 1, 2025

Fixing HMR with latest version of the Vite (>=6.0.9, >=5.4.12, <6.0.0, >=4.5.6, <5.0.0) - passing web socket token.

Changes based on comment from vite dev (#971 (comment)) - passing config.webSocketToken to hmr-client-worker.ts under the key __HMR_TOKEN__.

Closes #971

Copy link

changeset-bot bot commented Apr 1, 2025

🦋 Changeset detected

Latest commit: b93dcd1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@crxjs/vite-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Apr 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vite-plugin-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 7, 2025 6:30pm

Copy link
Contributor

github-actions bot commented Apr 1, 2025

⚠️ Important Notice: CRXJS is seeking new maintainers.

  • New issues and PRs may not receive immediate attention
  • A new maintenance team must establish itself by March 31, 2025 or this repository will be archived on June 1, 2025
  • Learn more about the transition

This is an automated message. Please do not reply to this comment.

@elwin013
Copy link
Contributor Author

elwin013 commented Apr 2, 2025

Svelte content scripts E2E tests fails but looking into it ;-) It take more-than-expected to render broken image and results differs. Other than that everything works as expected (even for vite 3.x).

@elwin013
Copy link
Contributor Author

elwin013 commented Apr 2, 2025

In d6fc56c the image is removed from Svelte tests (as well as the check for the image).

It changes the test, but makes it more stable. await app.locator('img').evaluate(image => image.complete); works randomly and adding artificial delay doesn't seem right.

Copy link

@AllenBW AllenBW left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! This looks like a solid fix for HMR compatibility with newer Vite versions. The issue was that Vite now requires a WebSocket token to be passed for security, which this implementation properly handles.

elwin013 added a commit to elwin013/chrome-extension-tools that referenced this pull request Apr 7, 2025
* replace google.com with example.com
* remove broken image from svelte content-script tests to make tests more stable

Changes pulled from crxjs#999
Fixing HMR with latest version of the Vite (>=6.0.9, >=5.4.12, <6.0.0, >=4.5.6, <5.0.0) - passing web socket token.

Changes based on comment from vite dev (crxjs#971 (comment)) - passing config.webSocketToken to hmr-client-worker.ts under the key __HMR_TOKEN__.
@elwin013 elwin013 force-pushed the fix/pass-hmr-token-to-make-hmr-working-again-with-latest-vite-versions branch from b93dcd1 to a336cdf Compare April 7, 2025 18:29
@elwin013
Copy link
Contributor Author

elwin013 commented Apr 7, 2025

Rebased over the latest main.

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.

CORS policy blocks script access in development
4 participants