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
feat(nuxt): allow fallback production content in <DevOnly>
#20817
Conversation
β Live Preview ready!
|
Sorry I'm unable to figure out why tests are failing (webpack in my testing works, and the vite test on |
What if instead we applied |
If I'm not wrong, styles can't be applied to DevOnly, and regardless of whatever the contents, it gets removed from the SFC |
Yes I read the component code after commenting π. But I'm wondering if providing a production fallback doesn't defeat the whole purpose of the component π€. I don't know, I guess we'll wait for a maintainer's comment |
Very fair point - I do think it won't change functionality but rather provide the feature if ever required (like in the above examples) Can't see it hurt - it's nice to have! π |
<DevOnly>
component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a nice feature - thank you! β€οΈ
I think it makes sense to keep fallback
as similar to <ClientOnly>
.
<DevOnly>
component<DevOnly>
@@ -9,7 +9,7 @@ interface DevOnlyPluginOptions { | |||
} | |||
|
|||
export const DevOnlyPlugin = createUnplugin((options: DevOnlyPluginOptions) => { | |||
const DEVONLY_COMP_RE = /<(dev-only|DevOnly)>[\s\S]*?<\/(dev-only|DevOnly)>/g | |||
const DEVONLY_COMP_RE = /<(?:dev-only|DevOnly)>[^<]*(?:<template\s+#fallback>(?<fallback>[\s\S]*?)<\/template>)?[\s\S]*?<\/(?:dev-only|DevOnly)>/g |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this regex won't work with the example in the updated doc and the following html due to [^<]*
:
<DevOnly>
<p>Some dev-only info</p>
<template #fallback>
Some prod-only info
</template>
</DevOnly>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm.... i forgot to submit the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for looking at this. we should probably add the handling to TreeShakeTemplatePlugin
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sharing! I was chaining the two regex/matches earlier (inefficient imo) but I think putting it into one (needing [^<]
) caused it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using ultrahtml
instead of the regex and keep the dev-only
plugin ? TreeShakeTemplatePlugin
won't remove ssrRender(DevOnly...)
but only remove its slots that are not fallback
or placeholder
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely up for using parsers over regex for safer template handling! Should it wait for #20284 as it adds ultrahtml
to Nuxt dependencies first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do it now, it won't cause any complex merge conflict π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently gone for splitting regex (in #20840) as ultrahtml
could cause trade-off with performance (through safety).
π Linked issue
β Type of change
π Description
This is a (silly little) PR that's motivated by some use-cases/scenarios where usage of the handy DevOnly causes some design changes in my app during build and so usage requires extra consideration. For example,
In such cases, especially where I have
flex
class, whenDevOnly
is removed, it causes block of three to change into two across the screen. This could allow fallback usage if ever required by devs.Could test it out in the repository playground:
playground/app.vue
and run
pnpm play:build && pnpm play:preview
π Checklist