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

Deleting token in a transformer causing hmr error in nuxt #3585

Open
4 tasks done
RebeccaStevens opened this issue Feb 29, 2024 · 1 comment
Open
4 tasks done

Deleting token in a transformer causing hmr error in nuxt #3585

RebeccaStevens opened this issue Feb 29, 2024 · 1 comment

Comments

@RebeccaStevens
Copy link
Contributor

RebeccaStevens commented Feb 29, 2024

UnoCSS version

0.58.5

Describe the bug

Calling tokens.delete(token) within a transformer results in an endless loop of errors and network requests for index.vue and __uno.css.

image

Contents of those two files:
import { createHotContext as __vite__createHotContext } from "/_nuxt/@vite/client";import.meta.hot = __vite__createHotContext("/pages/index.vue?macro=true");
const __nuxt_page_meta = null
export default __nuxt_page_meta

// Vite
if (import.meta.hot) {
  import.meta.hot.accept(mod => {
    Object.assign(__nuxt_page_meta, mod)
  })
}
// webpack
if (import.meta.webpackHot) {
  import.meta.webpackHot.accept((err) => {
    if (err) { window.location = window.location.href }
  })
}
import {createHotContext as __vite__createHotContext} from "/_nuxt/@vite/client";
import.meta.hot = __vite__createHotContext("/__uno.css");
import {updateStyle as __vite__updateStyle, removeStyle as __vite__removeStyle} from "/_nuxt/@vite/client"
const __vite__id = "/__uno.css"
const __vite__css = "..."
__vite__updateStyle(__vite__id, __vite__css)
import.meta.hot.accept()
import.meta.hot.prune(()=>__vite__removeStyle(__vite__id))
if (import.meta.hot) {
    try {
        let hash = __vite__css.match(/__uno_hash_(\w{6})/)
        hash = hash && hash[1]
        if (!hash)
            console.warn('[unocss-hmr]', 'failed to get unocss hash, hmr might not work')
        else
            await import.meta.hot.send('unocss:hmr', ['__ALL__']);
    } catch (e) {
        console.warn('[unocss-hmr]', e)
    }
    if (!import.meta.url.includes('?'))
        await new Promise(resolve=>setTimeout(resolve, 100))
}
document.querySelectorAll(`link[href="/_nuxt/__uno.css"]`).forEach(i=>i.remove())
document.querySelectorAll(`link[href="/_nuxt/@fs/__uno.css"]`).forEach(i=>i.remove())

Reproduction

I tried recreating a minimal example but couldn't.

Essentially what my transformer is doing is looking for tokens and replacing them with that token prefixed with a variant group.
e.g. Changing all uses of text-red to lg:text-red.

tokens.delete("text-red") is causing the issue. If I don't remove the token, everything works fine but extra CSS is generated.

System Info

Nuxt: 3.10.3

Validations

@RebeccaStevens RebeccaStevens closed this as not planned Won't fix, can't repro, duplicate, stale Feb 29, 2024
@RebeccaStevens
Copy link
Contributor Author

RebeccaStevens commented Feb 29, 2024

Workaround solution for now:

if (config.envMode === "build") {
	// For some reason this fails in dev so only do it during build.
	tokens.delete(token);
}

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

No branches or pull requests

1 participant