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

chore: setIsSelfAccepting param to isSelfAccepting #10960

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 7 additions & 2 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,16 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
// its last updated timestamp to force the browser to fetch the most
// up-to-date version of this module.
try {
// delay setting `isSelfAccepting` until the file is actually used (#7870)
const depModule = await moduleGraph.ensureEntryFromUrl(
unwrapId(url),
ssr,
canSkipImportAnalysis(url) || forceSkipImportAnalysis
// delay setting `isSelfAccepting` until the file is actually used (#7870)
{
isSelfAccepting:
canSkipImportAnalysis(url) || forceSkipImportAnalysis
? false
: undefined
}
Comment on lines +368 to +373
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to avoid an extra object allocation for now.

Btw, I handled this change in #7477. Maybe we can close this PR in favor of that, since it's not an urgent change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the extra allocation has any perf implications given everything else that is run when we create a new ModuleNode.
But seeing the errors in CI, the ModuleNode is a public API, and the setIsSelfAccepted param is documented at least in the code. So this is a small breaking change. I think forcing everybody to set false when creating a node is too disruptive. I'll close this PR, but I think we should leave setIsSelfAccepted untouched in your PR too. I don't think it is worth the disruption, I thought before that it would be something internal to core only.

Copy link
Member

@aleclarson aleclarson Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be a public API, but it's also undocumented. If anything, we should add private to the constructor and see if anyone complains in the next alpha. 🤞 If someone opens an issue about it, we can discuss the use case, but I'm guessing that ensureEntryFromResolved, ensureEntryFromUrl, and createFileOnlyEntry cover them all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I just realized that setIsSelfAccepted isn't only a constructor argument. You might be right that it's just too dangerous to change the default.

)
if (depModule.lastHMRTimestamp > 0) {
url = injectQuery(url, `t=${depModule.lastHMRTimestamp}`)
Expand Down
17 changes: 10 additions & 7 deletions packages/vite/src/node/server/moduleGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
import { FS_PREFIX } from '../constants'
import type { TransformResult } from './transformRequest'

type ModuleNodeOptions = { isSelfAccepting: boolean | undefined }

export class ModuleNode {
/**
* Public served url path, starts with /
Expand Down Expand Up @@ -37,14 +39,15 @@ export class ModuleNode {
lastInvalidationTimestamp = 0

/**
* @param setIsSelfAccepting - set `false` to set `isSelfAccepting` later. e.g. #7870
* @param isSelfAccepting - undefined means its value isn't know when creating the module #7870
*/
constructor(url: string, setIsSelfAccepting = true) {
constructor(
url: string,
options: ModuleNodeOptions = { isSelfAccepting: false }
) {
this.url = url
this.type = isDirectCSSRequest(url) ? 'css' : 'js'
if (setIsSelfAccepting) {
this.isSelfAccepting = false
}
this.isSelfAccepting = options.isSelfAccepting
}
}

Expand Down Expand Up @@ -182,12 +185,12 @@ export class ModuleGraph {
async ensureEntryFromUrl(
rawUrl: string,
ssr?: boolean,
setIsSelfAccepting = true
options?: ModuleNodeOptions
): Promise<ModuleNode> {
const [url, resolvedId, meta] = await this.resolveUrl(rawUrl, ssr)
let mod = this.idToModuleMap.get(resolvedId)
if (!mod) {
mod = new ModuleNode(url, setIsSelfAccepting)
mod = new ModuleNode(url, options)
if (meta) mod.meta = meta
this.urlToModuleMap.set(url, mod)
mod.id = resolvedId
Expand Down