Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

build(deps): bump ini from 1.3.5 to 1.3.8 #425

Open
wants to merge 8 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip: reused compiled script on template hmr
  • Loading branch information
yyx990803 committed Dec 15, 2020
commit 29bbe7ab499d787d7d5bfd435c03ace323469348
13 changes: 6 additions & 7 deletions src/handleHotUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs'
import _debug from 'debug'
import { parse, SFCBlock } from '@vue/compiler-sfc'
import { getDescriptor, setDescriptor } from './utils/descriptorCache'
import { getResolvedScript, setResolvedScript } from './script'

const debug = _debug('vite:hmr')

Expand Down Expand Up @@ -50,6 +51,11 @@ export async function handleHotUpdate(file: string, modules: any[]) {
}

if (!isEqualBlock(descriptor.template, prevDescriptor.template)) {
// when a <script setup> component's template changes, it will need correct
// binding metadata. However, when reloading the template alone the binding
// metadata will not be available since the script part isn't loaded.
// in this case, reuse the compiled script from previous descriptor.
setResolvedScript(descriptor, getResolvedScript(prevDescriptor)!)
needRerender = true
}

Expand All @@ -75,13 +81,6 @@ export async function handleHotUpdate(file: string, modules: any[]) {
const prev = prevStyles[i]
const next = nextStyles[i]
if (!prev || !isEqualBlock(prev, next)) {
// css modules update causes a reload because the $style object is changed
// and it may be used in JS.
// if (prev.module != null || next.module != null) {
// return modules.filter(
// (m) => !/type=/.test(m.id) || /type=script/.test(m.id)
// )
// }
didUpdateStyle = true
filteredModules.push(modules.find((m) => m.id.includes(`index=${i}`)))
}
Expand Down
10 changes: 9 additions & 1 deletion src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ const serverCache = new WeakMap<SFCDescriptor, SFCScriptBlock | null>()

export function getResolvedScript(
descriptor: SFCDescriptor,
isServer: boolean
isServer = false
): SFCScriptBlock | null | undefined {
return (isServer ? serverCache : clientCache).get(descriptor)
}

export function setResolvedScript(
descriptor: SFCDescriptor,
script: SFCScriptBlock,
isServer = false
) {
;(isServer ? serverCache : clientCache).set(descriptor, script)
}

export function resolveScript(
descriptor: SFCDescriptor,
scopeId: string,
Expand Down
1 change: 0 additions & 1 deletion src/utils/descriptorCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ export function getDescriptor(id: string) {
if (cache.has(id)) {
return cache.get(id)!
}

throw new Error(`${id} is not parsed yet`)
}