Deprecated function: str_starts_with(): Passing null to parameter #1 ($haystack) of type string is deprecated

Created on 22 February 2024, 10 months ago

Problem/Motivation

The setting "offline_page" is optional and can be set empty:

And if so - in serviceWorkerRegistration() the var $cacheUrls will have array with one element some_key => null, and next in fetchOfflinePageResources() we will get "Deprecated function: str_starts_with(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\Core\Url::fromUserInput() (line 223 of core/lib/Drupal/Core/Url.php)."

Proposed resolution

Change:
$cacheUrls[] = $swConfig->get('offline_page');
To:

if (!empty($swConfig->get('offline_page')){
 $cacheUrls[] = $swConfig->get('offline_page');
}
🐛 Bug report
Status

Needs review

Version

2.1

Component

pwa_service_worker

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024