Skip to content

[fix] check for private var usage in client code instead of server code #7487

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

Merged
merged 6 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/empty-dryers-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] check for private var usage in client code instead of server code
25 changes: 14 additions & 11 deletions packages/kit/src/exports/vite/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ export async function dev(vite, vite_config, svelte_config) {
async function resolve(id) {
const url = id.startsWith('..') ? `/@fs${path.posix.resolve(id)}` : `/${id}`;

const module = await vite.ssrLoadModule(url);

// need to ensure the entry is in the module graph before we can get it
// we leave the ssr parameter undefined because we care about the client-side code here
await vite.moduleGraph.ensureEntryFromUrl(url);
const module_node = await vite.moduleGraph.getModuleByUrl(url);
if (!module_node) throw new Error(`Could not find node for ${url}`);

return { module, module_node, url };
return { module_node, url };
}

async function update_manifest() {
Expand Down Expand Up @@ -87,9 +88,8 @@ export async function dev(vite, vite_config, svelte_config) {

if (node.component) {
result.component = async () => {
const { module_node, module, url } = await resolve(
/** @type {string} */ (node.component)
);
const id = /** @type {string} */ (node.component);
const { module_node, url } = await resolve(id);

module_nodes.push(module_node);
result.file = url.endsWith('.svelte') ? url : url + '?import'; // TODO what is this for?
Expand All @@ -100,27 +100,30 @@ export async function dev(vite, vite_config, svelte_config) {
extensions
);

// wait to load the module until after we check for illegal imports
const module = await vite.ssrLoadModule(url);
return module.default;
};
}

if (node.shared) {
const { module, module_node } = await resolve(node.shared);
const { module_node, url } = await resolve(node.shared);

module_nodes.push(module_node);

result.shared = module;

prevent_illegal_vite_imports(
module_node,
normalizePath(svelte_config.kit.files.lib),
extensions
);

// wait to load the module until after we check for illegal imports
result.shared = await vite.ssrLoadModule(url);
}

if (node.server) {
const { module } = await resolve(node.server);
result.server = module;
const { url } = await resolve(node.server);
result.server = await vite.ssrLoadModule(url);
result.server_id = node.server;
}

Expand Down