Skip to content

Conversation

@btea
Copy link
Contributor

@btea btea commented Jul 5, 2024

Description

close #17508

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@MathiasWP
Copy link

Would it also be relevant to cast the actual error being thrown in https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/importAnalysisBuild.ts#L148

Doing something like this in the importAnalysisBuild.ts file:

const e: VitePreloadErrorEvent = new Event('vite:preloadError', { cancelable: true })
e.payload = err
window.dispatchEvent(e)
if (!e.defaultPrevented) {
    throw err
}

I think that will also make it possible to remove the // @ts-expect-error comment

@bluwy bluwy added the p2-nice-to-have Not breaking anything but nice to have (priority) label Jul 23, 2024
@btea
Copy link
Contributor Author

btea commented Jul 23, 2024

As @MathiasWP said, do you think we need to customize a VitePreloadErrorEvent type to remove ts comments? @bluwy

bluwy
bluwy previously approved these changes Jul 23, 2024
@bluwy
Copy link
Member

bluwy commented Jul 23, 2024

As @MathiasWP said, do you think we need to customize a VitePreloadErrorEvent type to remove ts comments? @bluwy

If it's possible to cast then that would be great, but I don't know if there's complications doing that when the types come from client.d.ts. I don't mind if not either.

@btea
Copy link
Contributor Author

btea commented Jul 23, 2024

The type is not complicated, it is simpler to just declare one.

@bluwy bluwy added this to the 5.4 milestone Jul 24, 2024
@bluwy bluwy merged commit 116e37a into vitejs:main Jul 30, 2024
@btea btea deleted the feat/custom-VitePreloadErrorEvent branch July 30, 2024 08:37
@curtdept
Copy link

curtdept commented Aug 8, 2024

Feedback for whoever, in typescript this makes is more complicated to spyOn as there is now a colliding overload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2-nice-to-have Not breaking anything but nice to have (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Declare missing vite:preloadErrorevent on Window namespace

4 participants