[{"data":1,"prerenderedAt":432},["ShallowReactive",2],{"navigation_docs":3,"rule-content-\u002Fvue\u002Frules\u002Freactivity\u002Fprefer-computed-over-watch-assign":48},[4,8,12,16,20,24,28,32,36,40,44],{"title":5,"path":6,"stem":7},"CLI","\u002Fcli","1.cli",{"title":9,"path":10,"stem":11},"Nuxt","\u002Fnuxt","2.nuxt",{"title":13,"path":14,"stem":15},"Vue","\u002Fvue","3.vue",{"title":17,"path":18,"stem":19},"Vite","\u002Fvite","4.vite",{"title":21,"path":22,"stem":23},"Nitro","\u002Fnitro","5.nitro",{"title":25,"path":26,"stem":27},"TypeScript","\u002Ftypescript","6.typescript",{"title":29,"path":30,"stem":31},"shadcn","\u002Fshadcn","7.shadcn",{"title":33,"path":34,"stem":35},"Package","\u002Fpackage","8.package",{"title":37,"path":38,"stem":39},"Extending Doctor","\u002Fextending","9.extending",{"title":41,"path":42,"stem":43},"MCP","\u002Fmcp","9.mcp",{"title":45,"path":46,"stem":47},"Pinia","\u002Fpinia","9.pinia",{"id":49,"title":50,"body":51,"category":57,"description":420,"diagnosticCodes":421,"docsUrl":59,"extension":422,"fix":60,"framework":173,"meta":423,"navigation":424,"pack":61,"path":426,"recommendedReplacement":427,"ruleId":62,"seo":428,"severity":63,"source":64,"sourceUrl":65,"stem":429,"why":430,"__hash__":431},"rules\u002Fvue\u002Frules\u002Freactivity\u002Fprefer-computed-over-watch-assign.md","Derive state with computed() instead of a watcher",{"type":52,"value":53,"toc":411},"minimark",[54,66,71,115,119,131,135,141,145,157,161,166,169,321,324,407],[55,56],"rule-metadata",{"category":57,"diagnosticCodes":58,"docsUrl":59,"fix":60,"pack":61,"ruleId":62,"severity":63,"source":64,"sourceUrl":65},"reactivity","VUE0034","https:\u002F\u002Fvuejs.org\u002Fguide\u002Fessentials\u002Fcomputed.html","suggestion","vite-doctor\u002Fvue","vue\u002Freactivity\u002Fprefer-computed-over-watch-assign","warn","src\u002Frule-packs\u002Fvue\u002Frules\u002Fvue\u002Fprefer-computed-over-watch-assign.ts","https:\u002F\u002Fgithub.com\u002Fonmax\u002Fvite-doctor\u002Fblob\u002Fmain\u002Fsrc\u002Frule-packs\u002Fvue\u002Frules\u002Fvue\u002Fprefer-computed-over-watch-assign.ts",[67,68,70],"h2",{"id":69},"run-this-rule","Run this rule",[72,73,78],"pre",{"className":74,"code":75,"language":76,"meta":77,"style":77},"language-bash shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","pnpm vite-doctor . --framework vue --extends auto,vue\u002Fstrict --rules vue\u002Freactivity\u002Fprefer-computed-over-watch-assign\n","bash","",[79,80,81],"code",{"__ignoreMap":77},[82,83,86,90,94,97,100,103,106,109,112],"span",{"class":84,"line":85},"line",1,[82,87,89],{"class":88},"sBMFI","pnpm",[82,91,93],{"class":92},"sfazB"," vite-doctor",[82,95,96],{"class":92}," .",[82,98,99],{"class":92}," --framework",[82,101,102],{"class":92}," vue",[82,104,105],{"class":92}," --extends",[82,107,108],{"class":92}," auto,vue\u002Fstrict",[82,110,111],{"class":92}," --rules",[82,113,114],{"class":92}," vue\u002Freactivity\u002Fprefer-computed-over-watch-assign\n",[67,116,118],{"id":117},"why-it-matters","Why it matters",[120,121,122,123,126,127,130],"p",{},"A ref fed by a watcher is a second copy of derived state. A ",[79,124,125],{},"watch()"," without immediate does not run until a source changes, and Vue skips it entirely during server rendering, so the ref keeps its initial value until then. Other watchers write the ref in a later flush, so code that reads it right after changing a source sees the old value. ",[79,128,129],{},"computed()"," derives the value on read, caches it, and cannot drift from its sources.",[67,132,134],{"id":133},"recommended-fix","Recommended fix",[120,136,137,138,140],{},"Replace the ref and the watcher with a ",[79,139,129],{},". This Rule is in the strict preset: a non-immediate watcher also skips its first run on the client, so server and client render the same initial value and the pattern is a design choice, not a hydration defect.",[67,142,144],{"id":143},"useful-links","Useful links",[146,147,148],"ul",{},[149,150,151],"li",{},[152,153,156],"a",{"href":59,"rel":154},[155],"nofollow","Rule reference",[67,158,160],{"id":159},"example","Example",[162,163,165],"h3",{"id":164},"derive-state-with-computed","Derive state with computed()",[120,167,168],{},"Before",[72,170,174],{"className":171,"code":172,"language":173,"meta":77,"style":77},"language-vue shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u003Cscript setup lang=\"ts\">\nconst count = ref(1)\nconst doubled = ref(0)\nwatch(count, (value) => {\n  doubled.value = value * 2\n})\n\u003C\u002Fscript>\n","vue",[79,175,176,207,233,252,280,303,311],{"__ignoreMap":77},[82,177,178,182,186,190,193,196,199,202,204],{"class":84,"line":85},[82,179,181],{"class":180},"sMK4o","\u003C",[82,183,185],{"class":184},"swJcz","script",[82,187,189],{"class":188},"spNyl"," setup",[82,191,192],{"class":188}," lang",[82,194,195],{"class":180},"=",[82,197,198],{"class":180},"\"",[82,200,201],{"class":92},"ts",[82,203,198],{"class":180},[82,205,206],{"class":180},">\n",[82,208,210,213,217,219,223,226,230],{"class":84,"line":209},2,[82,211,212],{"class":188},"const",[82,214,216],{"class":215},"sTEyZ"," count ",[82,218,195],{"class":180},[82,220,222],{"class":221},"s2Zo4"," ref",[82,224,225],{"class":215},"(",[82,227,229],{"class":228},"sbssI","1",[82,231,232],{"class":215},")\n",[82,234,236,238,241,243,245,247,250],{"class":84,"line":235},3,[82,237,212],{"class":188},[82,239,240],{"class":215}," doubled ",[82,242,195],{"class":180},[82,244,222],{"class":221},[82,246,225],{"class":215},[82,248,249],{"class":228},"0",[82,251,232],{"class":215},[82,253,255,258,261,264,267,271,274,277],{"class":84,"line":254},4,[82,256,257],{"class":221},"watch",[82,259,260],{"class":215},"(count",[82,262,263],{"class":180},",",[82,265,266],{"class":180}," (",[82,268,270],{"class":269},"sHdIc","value",[82,272,273],{"class":180},")",[82,275,276],{"class":188}," =>",[82,278,279],{"class":180}," {\n",[82,281,283,286,289,291,294,297,300],{"class":84,"line":282},5,[82,284,285],{"class":215},"  doubled",[82,287,288],{"class":180},".",[82,290,270],{"class":215},[82,292,293],{"class":180}," =",[82,295,296],{"class":215}," value",[82,298,299],{"class":180}," *",[82,301,302],{"class":228}," 2\n",[82,304,306,309],{"class":84,"line":305},6,[82,307,308],{"class":180},"}",[82,310,232],{"class":215},[82,312,314,317,319],{"class":84,"line":313},7,[82,315,316],{"class":180},"\u003C\u002F",[82,318,185],{"class":184},[82,320,206],{"class":180},[120,322,323],{},"After",[72,325,327],{"className":171,"code":326,"language":173,"meta":77,"style":77},"\u003Cscript setup lang=\"ts\">\nconst count = ref(1)\nconst doubled = computed(() => count.value * 2)\n\u003C\u002Fscript>\n",[79,328,329,349,365,399],{"__ignoreMap":77},[82,330,331,333,335,337,339,341,343,345,347],{"class":84,"line":85},[82,332,181],{"class":180},[82,334,185],{"class":184},[82,336,189],{"class":188},[82,338,192],{"class":188},[82,340,195],{"class":180},[82,342,198],{"class":180},[82,344,201],{"class":92},[82,346,198],{"class":180},[82,348,206],{"class":180},[82,350,351,353,355,357,359,361,363],{"class":84,"line":209},[82,352,212],{"class":188},[82,354,216],{"class":215},[82,356,195],{"class":180},[82,358,222],{"class":221},[82,360,225],{"class":215},[82,362,229],{"class":228},[82,364,232],{"class":215},[82,366,367,369,371,373,376,378,381,383,386,388,391,394,397],{"class":84,"line":235},[82,368,212],{"class":188},[82,370,240],{"class":215},[82,372,195],{"class":180},[82,374,375],{"class":221}," computed",[82,377,225],{"class":215},[82,379,380],{"class":180},"()",[82,382,276],{"class":188},[82,384,385],{"class":215}," count",[82,387,288],{"class":180},[82,389,390],{"class":215},"value ",[82,392,393],{"class":180},"*",[82,395,396],{"class":228}," 2",[82,398,232],{"class":215},[82,400,401,403,405],{"class":84,"line":254},[82,402,316],{"class":180},[82,404,185],{"class":184},[82,406,206],{"class":180},[408,409,410],"style",{},"html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sHdIc, html code.shiki .sHdIc{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic}",{"title":77,"searchDepth":209,"depth":209,"links":412},[413,414,415,416,417],{"id":69,"depth":209,"text":70},{"id":117,"depth":209,"text":118},{"id":133,"depth":209,"text":134},{"id":143,"depth":209,"text":144},{"id":159,"depth":209,"text":160,"children":418},[419],{"id":164,"depth":235,"text":165},"Finds watchers whose only effect is assigning a value derived from their sources to a local ref.",[58],"md",{},{"title":425},"Watcher-derived refs","\u002Fvue\u002Frules\u002Freactivity\u002Fprefer-computed-over-watch-assign","Replace the ref and the watcher with a computed(). This Rule is in the strict preset: a non-immediate watcher also skips its first run on the client, so server and client render the same initial value and the pattern is a design choice, not a hydration defect.",{"title":50,"description":420},"vue\u002Frules\u002Freactivity\u002Fprefer-computed-over-watch-assign","A ref fed by a watcher is a second copy of derived state. A watch() without immediate does not run until a source changes, and Vue skips it entirely during server rendering, so the ref keeps its initial value until then. Other watchers write the ref in a later flush, so code that reads it right after changing a source sees the old value. computed() derives the value on read, caches it, and cannot drift from its sources.","uXAd-je9_sMv-0tmsBeXgiF73Cs5sDfmR5Opvk1U8L0",1795268789796]