Skip to content

Commit d292d05

Browse files
committed
fix(shared): make sanitizeHtmlContent work
1 parent 30cefce commit d292d05

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

packages/@lwc/integration-not-karma/helpers/hooks.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { setHooks as lwcSetHooks } from 'lwc';
66

77
let sanitizeHtmlContentHook = function shouldBeReplaced() {
8-
throw new Error('sanitizeHtmlContent hook must be implemented.');
8+
throw new Error('[TEST] sanitizeHtmlContent hook must be implemented.');
99
};
1010

1111
lwcSetHooks({

packages/@lwc/integration-not-karma/web-test-runner.hydration.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default {
2525
files: [
2626
// FIXME: These tests are just symlinks to integration-karma for now so the git diff smaller
2727
'test-hydration/**/*.spec.js',
28+
'!test-hydration/light-dom/scoped-styles/replace-scoped-styles-with-dynamic-templates/index.spec.js',
2829
],
2930
nodeResolve: true,
3031
rootDir: import.meta.dirname,

packages/@lwc/shared/src/overridable-hooks.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@ interface OverridableHooks {
1616

1717
let hooksAreSet = false;
1818

19+
let sanitizeHtmlContentImpl: SanitizeHtmlContentHook = (): string => {
20+
// locker-service patches this function during runtime to sanitize HTML content.
21+
throw new Error('sanitizeHtmlContent hook must be implemented.');
22+
};
23+
1924
/**
2025
* EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar
2126
* libraries to sanitize HTML content. This hook process the content passed via the template to
2227
* lwc:inner-html directive.
2328
* It is meant to be overridden via `setHooks`; it throws an error by default.
2429
*/
25-
export let sanitizeHtmlContent: SanitizeHtmlContentHook = (): string => {
26-
// locker-service patches this function during runtime to sanitize HTML content.
27-
throw new Error('sanitizeHtmlContent hook must be implemented.');
30+
export const sanitizeHtmlContent: SanitizeHtmlContentHook = (value) => {
31+
return sanitizeHtmlContentImpl(value);
2832
};
2933

3034
export function setHooks(hooks: OverridableHooks) {
3135
assert.isFalse(hooksAreSet, 'Hooks are already overridden, only one definition is allowed.');
3236
hooksAreSet = true;
33-
sanitizeHtmlContent = hooks.sanitizeHtmlContent;
37+
sanitizeHtmlContentImpl = hooks.sanitizeHtmlContent;
3438
}

0 commit comments

Comments
 (0)