-
Notifications
You must be signed in to change notification settings - Fork 275
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
Set web worker startup options with messages instead of query strings #1574
Set web worker startup options with messages instead of query strings #1574
Conversation
I adjusted the title and description – it talked about the service worker, but it's actual about the regular web worker. The PR looks good, thank you @bgrgicak! |
Ah, I merged and then realized it's the topmost of the three stacked PRs and now #1573 contains these changes. |
It seems like we remove the startupOptions from the worker URL now: - workerUrl = addQueryParams(workerUrl, startupOptions);
const worker = new Worker(workerUrl, { type: 'module' }); |
I did it now in 7c886d4. I wasn't sure if there is any value in keeping it around. |
[For offline support](#1600) we need to load the service worker as early as possible in the boot process. Booting early will allow fetch caching to cache more files on the first making the backfill of assets simpler. Read the full research recap here #1600 (review) ## Implementation details To move `registerServiceWorker` to the start of the boot process we had to generate the scope in `bootPlaygroundRemote` and pass it to the PHP worker thread together with other startup options. The service worker had to be registered before spawning the PHP worker thread to ensure WP and PHP assets were cached. But the service worker also depends on the `phpApi` returned by `spawnPHPWorkerThread`. We had to register the service worker first, after that, spawn the PHP worker thread, and then set the `phpApi`. This PR also includes changes from #1574 because they allow us to pass the scope. ## Testing Instructions (or ideally a Blueprint) - Ensure all tests pass --------- Co-authored-by: Adam Zieliński <[email protected]>
Motivation for the change, related issues
When the web worker is loaded from browser storage it loses the query string context we use to send startup options like WP and PHP version.
To enable offline support, this PR changes how the worker obtains startup options to ensure it works when cached.
Implementation details
Instead of fetching startup options from the query string,
spawnPHPWorkerThread
will post startup options as a message to the worker.When
worker-utils
loads it will await thestartup-options
message and continue once it receives the data.Testing Instructions (or ideally a Blueprint)
@brandonpayton @adamziel I'm not sure about this solution. It works, but I'm not happy with it. How does it look to you?