Skip to content

Commit 2f33fc1

Browse files
authored
Merge pull request #1062 from RaspberryPiFoundation/fix-skulpt-external-files
Fix Skulpt External Files
2 parents 00dbfc2 + 8c8fcb4 commit 2f33fc1

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

.env.webcomponent.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ REACT_APP_AUTHENTICATION_URL='http://localhost:9001'
22
REACT_APP_SENTRY_DSN=''
33
REACT_APP_SENTRY_ENV='local'
44
# NB This is the URL of react-ui, rather than the web component
5-
PUBLIC_URL=http://localhost:3010
5+
PUBLIC_URL=http://localhost:3012
66
REACT_APP_IDENTITY_URL='http://localhost:3011'
77
REACT_APP_API_ENDPOINT='http://localhost:3009'
8-
ASSETS_URL='http://localhost:3010'
8+
ASSETS_URL='http://localhost:3011'

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1212

1313
### Fixed
1414

15+
- Attach Skulpt files to the `document.body` to avoid issues with the shadow DOM (#1062)
1516
- Small fix to ensure webpack is using the correct webSocketURL for live reloading\
1617
- Only register `editor-wc` once (#1052)
1718

src/components/EmbeddedViewer/__snapshots__/EmbeddedViewer.test.js.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ exports[`Renders without crashing 1`] = `
55
<div
66
class="embedded-viewer"
77
>
8-
<div
9-
hidden=""
10-
id="file-content"
11-
/>
128
<div
139
class="proj-runner-container"
1410
data-testid="output"

src/components/ExternalFiles/ExternalFiles.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import React from "react";
22
import { useSelector } from "react-redux";
3+
import { createPortal } from "react-dom";
34

45
const ExternalFiles = () => {
56
const project = useSelector((state) => state.editor.project);
7+
const hostElement = document.body;
68

7-
return (
9+
if (!hostElement) {
10+
return null;
11+
}
12+
13+
return createPortal(
814
<div id="file-content" hidden>
915
{project.components?.map((file, i) => {
1016
if (["csv", "txt"].includes(file.extension)) {
@@ -16,7 +22,8 @@ const ExternalFiles = () => {
1622
}
1723
return null;
1824
})}
19-
</div>
25+
</div>,
26+
hostElement,
2027
);
2128
};
2229

webpack.component.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ module.exports = {
7777
static: {
7878
directory: path.join(__dirname, "public"),
7979
},
80+
headers: {
81+
"Access-Control-Allow-Origin": "*",
82+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
83+
"Access-Control-Allow-Headers":
84+
"X-Requested-With, content-type, Authorization",
85+
},
8086
},
8187
plugins: [
8288
new Dotenv({

0 commit comments

Comments
 (0)