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

fixes virtual dep resolution for dynamically imported inline styles #90

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
43 changes: 28 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,35 @@

const resolveVirtualDependency: Compiler.Config["resolveVirtualDependency"] =
(from, dep) => {
const query = `${virtualFileQuery}&id=${encodeURIComponent(
normalizePath(dep.virtualPath)
)}`;
const normalizedFrom = normalizePath(from);
const id = normalizePath(normalizedFrom) + query;

if (devServer) {
const prev = virtualFiles.get(id);
if (isDeferredPromise(prev)) {
prev.resolve(dep);
}
return resolveVirtualDependencyHandler("s", from, dep);
};
const resolveVirtualDependencyH: Compiler.Config["resolveVirtualDependency"] =
(from, dep) => {
return resolveVirtualDependencyHandler("h", from, dep);
};
const resolveVirtualDependencyHandler = (
type: string,
from: string,
dep: any
) => {
const query = `${virtualFileQuery}&id=${
type != "h"
? encodeURIComponent(normalizePath(dep.virtualPath))
: normalizePath(dep.virtualPath)
}`;
const normalizedFrom = normalizePath(from);
const id = normalizePath(normalizedFrom) + query;

if (devServer) {
const prev = virtualFiles.get(id);
if (isDeferredPromise(prev)) {
prev.resolve(dep);

Check warning on line 129 in src/index.ts

View check run for this annotation

Codecov / codecov/patch

src/index.ts#L129

Added line #L129 was not covered by tests
}
}

virtualFiles.set(id, dep);
return `./${path.posix.basename(normalizedFrom) + query}`;
};
virtualFiles.set(id, dep);
return `./${path.posix.basename(normalizedFrom) + query}`;
};

let root: string;
let devEntryFile: string;
Expand Down Expand Up @@ -189,7 +202,7 @@

hydrateConfig = {
...baseConfig,
resolveVirtualDependency,
resolveVirtualDependency: resolveVirtualDependencyH,
output: "hydrate",
};

Expand Down
Loading