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: style comparison error when hotUpdate #3387

Closed
wants to merge 1 commit into from

Conversation

brenner8023
Copy link

FIXED: #3358

I think it need not transform code when hotUpdate. File content comparison when hotUpdate should compare raw code, not transformed code. The transformed code include unocss:vue-scoped's generated code and raw code, generated code is not chaged.

There is a comment from @vitejs/plugin-vue
packages/plugin-vue/src/main.ts
image

Copy link

netlify bot commented Nov 28, 2023

Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2bae6b3
🔍 Latest deploy log https://app.netlify.com/sites/unocss/deploys/65657cd0dea5af00089ecf3e
😎 Deploy Preview https://deploy-preview-3387--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@auvred auvred left a comment

Choose a reason for hiding this comment

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

If we don't inject styles on handleHotUpdate, all applied styles disappear after HMR (you can try to run it locally to see what happens). Most likely it's the bug of @vitejs/plugin-vue
Ref: vitejs/vite-plugin-vue#301

@brenner8023
Copy link
Author

If we don't inject styles on handleHotUpdate, all applied styles disappear after HMR (you can try to run it locally to see what happens). Most likely it's the bug of @vitejs/plugin-vue Ref: vitejs/vite-plugin-vue#301

I run it locally and everything seems to be ok. Because unocss:vue-scoped's transform hook is called after every HMR. I think applied styles will not disappear.

return {
    name: "unocss:vue-scoped",
    transform(code, id) {
      if (!filter(id))
        return;
      return transformSFC(code); // will run after every HMR
    },
    handleHotUpdate(ctx) {
      // const read = ctx.read;
      // if (filter(ctx.file)) {
      //   ctx.read = async () => {
      //     const code = await read();
      //     return await transformSFC(code) || code;
      //   };
      // }
    }
  };

@auvred
Copy link
Contributor

auvred commented Nov 28, 2023

Yes, you are right, transform hook is called. But updated styles are not pushed

Reproduction: https://stackblitz.com/edit/vitejs-vite-mnvzcb?file=src%2FApp.vue
Wait for dev server to start and change class text-red to text-blue. The text should change its color, but it doesn't do so

I just commented out handleHotUpdate code (patch-unocss.mjs).


But maybe we need to push this change as temporary workaround? I guess the runtime error is worse than missed hot update

@brenner8023
Copy link
Author

I open a PR(vitejs/vite-plugin-vue#306) for vite-plugin-vue to fix the bug. Take a look at my PR and give me some review comments.

Copy link

stale bot commented Jan 30, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 30, 2024
@stale stale bot closed this Feb 6, 2024
@coderwyd coderwyd mentioned this pull request Mar 28, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vite 5.0 Unknown word
2 participants