Skip to content

Commit f44d05a

Browse files
committed
fix: Panel browser requirements
1 parent 4502817 commit f44d05a

9 files changed

Lines changed: 117 additions & 26 deletions

File tree

.gitattributes

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ psalm.xml.dist export-ignore
1313
tests/ export-ignore
1414

1515
# panel
16+
# .browserslistrc is intentionally not ignored, it is read at runtime
1617
panel/.env.example export-ignore
18+
panel/.gitignore export-ignore
1719
panel/.prettierignore export-ignore
1820
panel/.prettierrc.json export-ignore
1921
panel/dist/ui export-ignore
20-
panel/eslint.config.mjs export-ignore
21-
panel/jsconfig.json export-ignore
22+
panel/eslint.config.js export-ignore
2223
panel/lab export-ignore
2324
panel/package-lock.json export-ignore
2425
panel/package.json export-ignore
@@ -27,8 +28,8 @@ panel/README.md export-ignore
2728
panel/scripts export-ignore
2829
panel/src export-ignore
2930
panel/tests export-ignore
30-
panel/vite.config.mjs export-ignore
31-
panel/vitest.setup.js export-ignore
31+
panel/tsconfig.json export-ignore
32+
panel/vite.config.ts export-ignore
3233

3334
# other
3435
.tx export-ignore

panel/.browserslistrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# The single source of truth for Panel browser support.
2+
# Read by vite.config.ts (build target) and views/browser.php.
3+
#
4+
# Policy: Baseline "widely available" (roughly 30 months after a feature
5+
# has landed in all core browsers) when the major version is released.
6+
# Recompute for the next major and paste the result below:
7+
# npx baseline-browser-mapping --widely-available-on-date YYYY-MM-DD --include-downstream-browsers
8+
#
9+
Chrome >= 124
10+
ChromeAndroid >= 124
11+
Edge >= 124
12+
Firefox >= 125
13+
Opera >= 110
14+
Safari >= 17.5
15+
iOS >= 17.5
16+
Android >= 124

panel/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ To upate the dist files
6969
```
7070
npm run build
7171
```
72+
73+
## Browser support
74+
75+
`.browserslistrc` is the single source of truth. It feeds the Vite build target (`createTarget()` in `vite.config.ts`) and the "browser too old" page ( `views/browser.php`). Don't repeat the versions anywhere else.
76+
77+
To move the floor for the next major, see the instructions in `.browserslistrc`.

panel/package.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,6 @@
5454
"vue-docgen-api": "^4.79.2",
5555
"vue-tsc": "^3.3.7"
5656
},
57-
"browserslist": [
58-
"Chrome >= 123",
59-
"ChromeAndroid >= 126",
60-
"Edge >= 123",
61-
"Firefox >= 120",
62-
"Opera >= 109",
63-
"Safari >= 17.5",
64-
"iOS >= 17.5",
65-
"Android >= 126"
66-
],
6757
"allowScripts": {
6858
"fsevents@2.3.3": true
6959
}

panel/vite.config.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-env node */
2+
import fs from "fs";
23
import path from "path";
34

45
import {
@@ -102,6 +103,41 @@ function createPlugins(mode: string): Plugin[] {
102103
return plugins;
103104
}
104105

106+
/**
107+
* Returns the build target, based on `.browserslistrc`
108+
*/
109+
function createTarget(): string[] {
110+
const engines: Record<string, string> = {
111+
Chrome: "chrome",
112+
Edge: "edge",
113+
Firefox: "firefox",
114+
iOS: "ios",
115+
Opera: "opera",
116+
Safari: "safari"
117+
};
118+
119+
const file = fs.readFileSync(
120+
path.resolve(__dirname, ".browserslistrc"),
121+
"utf-8"
122+
);
123+
124+
const target: string[] = [];
125+
126+
for (const line of file.split("\n")) {
127+
const match = line.trim().match(/^(\w+)\s*>=\s*([\d.]+)$/);
128+
129+
if (match !== null && engines[match[1]] !== undefined) {
130+
target.push(engines[match[1]] + match[2]);
131+
}
132+
}
133+
134+
if (target.length === 0) {
135+
throw new Error("No build target could be read from .browserslistrc");
136+
}
137+
138+
return target;
139+
}
140+
105141
/**
106142
* Returns vitest configuration
107143
*/
@@ -149,7 +185,7 @@ export default defineConfig(({ mode }) => {
149185
plugins,
150186
base: "./",
151187
build: {
152-
target: ["chrome123", "edge123", "firefox120", "safari17.5", "ios17.5"],
188+
target: createTarget(),
153189
cssCodeSplit: false,
154190
rolldownOptions: {
155191
checks: { pluginTimings: false },

src/Panel/Panel.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@ public function assets(): Assets
5858
return $this->assets ??= new Assets();
5959
}
6060

61+
/**
62+
* Minimum supported browser versions, read from
63+
* the browserslist config the Panel is built against
64+
* @since 6.0.0
65+
*/
66+
public function browsers(): array
67+
{
68+
$file = $this->kirby->root('panel') . '/.browserslistrc';
69+
70+
if (is_file($file) === false) {
71+
return [];
72+
}
73+
74+
$browsers = [];
75+
$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
76+
77+
foreach ($lines as $line) {
78+
if (preg_match('!^(\w+)\s*>=\s*([\d.]+)$!', trim($line), $match) === 1) {
79+
$browsers[$match[1]] = $match[2];
80+
}
81+
}
82+
83+
return $browsers;
84+
}
85+
6186
/**
6287
* Redirect to a Panel url
6388
*

src/Panel/Router.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ public function routes(Areas|null $areas = null): array
164164
'pattern' => 'browser',
165165
'auth' => false,
166166
'action' => fn () => new Response(
167-
Tpl::load($kirby->root('kirby') . '/views/browser.php')
167+
Tpl::load(
168+
$kirby->root('kirby') . '/views/browser.php',
169+
['browsers' => $panel->browsers()]
170+
)
168171
),
169172
]
170173
];

views/browser.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
<?php
2+
3+
use Kirby\Toolkit\Html;
4+
5+
/**
6+
* @var array<string, string> $browsers
7+
*/
8+
9+
$list = [];
10+
11+
foreach ($browsers as $browser => $version) {
12+
$list[] = Html::encode($browser . ' ' . $version);
13+
}
14+
15+
?>
116
<?php include __DIR__ . '/snippets/header.php' ?>
217

318
<p class="notice">
@@ -7,14 +22,11 @@
722

823
<div class="admin-advice">
924
<p>
10-
<strong>Fetch</strong><br>
11-
We use Javascript's new Fetch API. You can find a list of supported browsers for this feature on
12-
<strong><a href="https://caniuse.com/#feat=fetch">caniuse.com</a></strong>
25+
The Panel needs one of these browsers or higher:<br>
26+
<strong><?= implode(', ', $list) ?></strong>
1327
</p>
1428
<p>
15-
<strong>CSS Grid</strong><br>
16-
We use CSS Grids for all our layouts. You can find a list of supported browsers for this feature on
17-
<strong><a href="https://caniuse.com/#feat=css-grid">caniuse.com</a></strong>
29+
Please update your browser or switch to a different one.
1830
</p>
1931
</div>
2032

views/panel.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727

2828
<script nonce="<?= $nonce ?>">
2929
if (
30-
!window.CSS ||
31-
window.CSS.supports("display", "grid") === false ||
32-
!window.fetch
30+
!window.CSS ||
31+
window.CSS.supports("color", "light-dark(#fff, #000)") === false ||
32+
!window.HTMLScriptElement.supports ||
33+
window.HTMLScriptElement.supports("importmap") === false ||
34+
!window.Promise.withResolvers
3335
) {
34-
window.location.href = "<?= $panelUrl ?>browser";
36+
window.location.replace("<?= $panelUrl ?>browser");
3537
}
3638
</script>
3739

0 commit comments

Comments
 (0)