Skip to content

Commit

Permalink
Fix/esm builds (#761)
Browse files Browse the repository at this point in the history
<!--
Filling out this template is required. Any PR that does not include
enough information to be reviewed may be closed at a maintainers'
discretion. All new code requires documentation and tests to ensure
against regressions.
-->

### Description of the Change
<!--
We must be able to understand the design of your change from this
description. The maintainer reviewing this PR may not have worked with
this code recently, so please provide as much detail as possible.

Where possible, please also include:
- verification steps to ensure your change has the desired effects and
has not introduced any regressions
- any benefits that will be realized
- any alternative implementations or possible drawbacks that you
considered
- screenshots or screencasts
-->

<!-- Enter any applicable Issue number(s) here that will be
closed/resolved by this PR. -->
Closes #

### How to test the Change
<!-- Please provide steps on how to test or validate that the change in
this PR works as described. -->

### Changelog Entry
<!--
Please include a summary for this PR, noting whether this is something
being Added / Changed / Deprecated / Removed / Fixed / or Security
related. You can replace the sample entries after this comment block
with the single changelog entry line for this PR. -->
> Added - New feature
> Changed - Existing functionality
> Deprecated - Soon-to-be removed feature
> Removed - Feature
> Fixed - Bug fix
> Security - Vulnerability


### Credits
<!-- Please list any and all contributors on this PR so that they can be
added to this projects CREDITS.md file. -->
Props @username, @username2, ...


### Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you are unsure about any of these, please ask for
clarification. We are here to help! -->
- [ ] I agree to follow this project's [**Code of
Conduct**](https://github.com/10up/.github/blob/trunk/CODE_OF_CONDUCT.md).
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my change.
- [ ] All new and existing tests pass.
  • Loading branch information
nicholasio authored May 7, 2024
2 parents 22c864b + a89b9fe commit 005addc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/chilled-masks-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@headstartwp/core": patch
"@headstartwp/next": patch
---

Fix: more fixes for esm builds
9 changes: 6 additions & 3 deletions packages/core/src/dom/wpKsesPost.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable no-param-reassign, @typescript-eslint/no-use-before-define */
import sanitize, { getDefaultWhiteList, IFilterXSSOptions } from 'xss';
import type { IWhiteList } from 'xss';
import * as xss from 'xss';
import type { IWhiteList, IFilterXSSOptions } from 'xss';
import { isHrefValueClean, linkingSVGElements, svgAllowList, svgHtmlAllowList } from './svg';

const { default: sanitize } = xss;

interface IWpKsesPostOptions extends IFilterXSSOptions {
svg?: boolean;
}
Expand Down Expand Up @@ -248,7 +250,8 @@ const commonAttributes = [
'data-wp-block-name',
];

const defaultAllowList = getDefaultWhiteList();
// @ts-expect-error
const defaultAllowList = sanitize.getDefaultWhiteList();

for (const tag of Object.keys(defaultAllowList)) {
if (typeof defaultAllowList[tag] !== 'undefined' && Array.isArray(defaultAllowList[tag])) {
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/react/components/BlocksRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import parse, { HTMLReactParserOptions, domToReact, Element } from 'html-react-parser';
import type { HTMLReactParserOptions, Element } from 'html-react-parser';
import * as HtmlReactParser from 'html-react-parser';
import React, { isValidElement, ReactElement, ReactNode } from 'react';
import type { IWhiteList } from 'xss';
import { isBlock, wpKsesPost } from '../../dom';
Expand All @@ -8,6 +9,8 @@ import { IBlockAttributes } from '../blocks/types';
import { useSettings } from '../provider';
import { getInlineStyles } from '../blocks/utils';

const { default: parse, domToReact } = HtmlReactParser;

/**
* The interface any children of {@link BlocksRenderer} must implement.
*/
Expand Down

0 comments on commit 005addc

Please sign in to comment.