From b0d3bc0696d266fcfc4eb93d0a4adb9ccb56ade6 Mon Sep 17 00:00:00 2001 From: Bret Little Date: Wed, 14 Aug 2024 05:36:58 -0400 Subject: [PATCH] Fix the `Script` component to not throw within inline scripts (#2428) * Fix the `Script` component to not throw within inline scripts * Apply suggestions from code review --------- Co-authored-by: Fran Dios --- .changeset/flat-foxes-rhyme.md | 5 ++++ packages/hydrogen/src/csp/Script.test.ts | 37 ++++++++++++++++++++++++ packages/hydrogen/src/csp/Script.tsx | 8 +++-- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 .changeset/flat-foxes-rhyme.md diff --git a/.changeset/flat-foxes-rhyme.md b/.changeset/flat-foxes-rhyme.md new file mode 100644 index 000000000..a65336705 --- /dev/null +++ b/.changeset/flat-foxes-rhyme.md @@ -0,0 +1,5 @@ +--- +'@shopify/hydrogen': patch +--- + +Fix the `Script` component to not throw when using it for inline scripts with `dangerouslySetInnerHTML` diff --git a/packages/hydrogen/src/csp/Script.test.ts b/packages/hydrogen/src/csp/Script.test.ts index 5d35454f5..754c5e3b1 100644 --- a/packages/hydrogen/src/csp/Script.test.ts +++ b/packages/hydrogen/src/csp/Script.test.ts @@ -33,6 +33,27 @@ describe(' + + `); + }); + it('should load scripts after hydration', () => { const {asFragment} = render( createElement(NonceProvider, { @@ -53,4 +74,20 @@ describe('