File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 1
1
<script lang =" ts" >
2
2
import { clsx } from " clsx" ;
3
3
import { browser } from " $app/environment" ;
4
- import IconSearch from " $lib/icons/IconSearch.svelte" ;
5
- import DOMPurify from " dompurify" ;
6
4
import { onMount } from " svelte" ;
5
+ import IconSearch from " $lib/icons/IconSearch.svelte" ;
6
+
7
+ // SSR-safe HTML sanitizer: no-op on server
8
+ let sanitize = $state <(html : string ) => string >((html ) => html );
9
+
10
+ // Hook up DOMPurify sanitize in browser
11
+ onMount (async () => {
12
+ if (browser ) {
13
+ const DOMPurify = (await import (" dompurify" )).default ;
14
+ sanitize = DOMPurify .sanitize ;
15
+ }
16
+ });
7
17
8
18
// Define the props based on GOV.UK documentation
9
19
type Props = {
157
167
158
168
{#snippet LabelContent ()}
159
169
<label for ={defaultId } class ={derivedLabelClasses }>
160
- {@html DOMPurify . sanitize (label_text )}
170
+ {@html sanitize (label_text )}
161
171
</label >
162
172
{/ snippet }
163
173
You can’t perform that action at this time.
0 commit comments