fix(worker): : Blob URL revoke #19893
Open
+22
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
The tests verify:
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.