Skip to content

fix(worker): : Blob URL revoke #19893

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

mangming2
Copy link

Description

This PR fixes an issue with WebKit browser compatibility in Vite's inline worker implementation. The problem occurs when creating workers using Blob URLs in WebKit browsers, particularly in Playwright's WebKit environment.

Issue Reference
Related Issue: #19238

Problem

The current implementation revokes the Blob URL too early in the finally block of the WorkerWrapper function, before the worker can properly utilize it. This causes failures in WebKit browsers where the Blob URL needs to remain valid throughout the worker's lifecycle.

Solution

The solution moves the URL revocation inside the worker script itself, similar to how it's already implemented for module workers. This ensures the URL remains valid until the worker is fully initialized and ready to use it.

Changes

Removed URL revocation from the finally block in WorkerWrapper
Added URL revocation inside the worker script for classic workers
Maintained existing URL revocation for module workers
Added comprehensive tests to verify the fix

Test Results

Playwright WebKit Test Results
Tests executed successfully using Playwright WebKit:

All tests are passing successfully:

Test Files  1 passed (1)
Tests  4 passed (4)
Duration  2.18s

The tests verify:

  • Basic worker creation and communication
  • Error handling
  • URL revocation timing
  • Multiple message handling

Alternatives Considered

Using load event listener on the worker
Delaying URL revocation with a timeout
Keeping the URL valid for the entire worker lifecycle
The chosen solution of moving URL revocation inside the worker script was selected because:
It's consistent with the existing module worker implementation
It ensures the URL remains valid until the worker is fully initialized
It's more reliable than event-based or timeout-based solutions

Areas Requiring Review

The timing of URL revocation in different browser environments
Potential edge cases in worker initialization
Memory management implications
This change should resolve the WebKit compatibility issues while maintaining proper resource cleanup.

@mangming2 mangming2 changed the title Fix(worker): : Blob URL revoke fix(worker): : Blob URL revoke Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant