Skip to content

Commit 5b9acdf

Browse files
author
Ives van Hoorne
committed
Update version
1 parent 6d5f624 commit 5b9acdf

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

packages/react-sandpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-smooshpack",
3-
"version": "0.0.10",
3+
"version": "0.0.11",
44
"description": "",
55
"keywords": [],
66
"license": "SEE LICENSE.MD IN ROOT",

packages/react-sandpack/src/components/Navigator/Navigator.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ class Navigator extends React.Component<Props, State> {
6969
};
7070

7171
commitUrl = () => {
72-
this.props.sandpack.browserFrame.src =
73-
this.state.baseUrl + this.state.browserPath;
72+
if (this.props.sandpack.browserFrame) {
73+
this.props.sandpack.browserFrame.src =
74+
this.state.baseUrl + this.state.browserPath;
75+
}
7476
};
7577

7678
onInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
@@ -92,7 +94,9 @@ class Navigator extends React.Component<Props, State> {
9294
};
9395

9496
onRefresh = () => {
95-
this.props.sandpack.browserFrame.src = this.state.lastCommittedUrl;
97+
if (this.props.sandpack.browserFrame) {
98+
this.props.sandpack.browserFrame.src = this.state.lastCommittedUrl;
99+
}
96100
};
97101

98102
render() {

packages/react-sandpack/src/components/SandpackProvider/SandpackProvider.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Broadcast } from 'react-broadcast';
33
import { Manager, generatePackageJSON } from 'smooshpack';
44
import { listen } from 'codesandbox-api';
55

6-
import { IFile, IFiles, IManagerState } from '../../types';
6+
import { IFile, IFiles, IManagerState, ISandpackContext } from '../../types';
77

88
export interface State {
99
files: IFiles;
@@ -34,7 +34,7 @@ export interface Props {
3434
| 'angular-cli'
3535
| 'preact-cli';
3636

37-
onFileChange?: (files: IFiles) => void;
37+
onFileChange?: (files: IFiles, sandpack: ISandpackContext) => void;
3838
}
3939

4040
export default class SandpackProvider extends React.PureComponent<
@@ -138,7 +138,7 @@ export default class SandpackProvider extends React.PureComponent<
138138
this.setState({ files });
139139

140140
if (this.props.onFileChange) {
141-
this.props.onFileChange(files);
141+
this.props.onFileChange(files, this._getSandpackState());
142142
}
143143
if (this.manager) {
144144
this.manager.updatePreview({ files, template: this.props.template });
@@ -170,23 +170,25 @@ export default class SandpackProvider extends React.PureComponent<
170170
this.setState({ openedPath: path });
171171
};
172172

173+
_getSandpackState = (): ISandpackContext => {
174+
const { iframe, files, browserPath, openedPath, managerState } = this.state;
175+
return {
176+
files,
177+
openedPath,
178+
managerState,
179+
openFile: this.openFile,
180+
browserFrame: iframe,
181+
updateFiles: this.updateFiles,
182+
bundlerURL: this.manager ? this.manager.bundlerURL : undefined,
183+
};
184+
};
185+
173186
render() {
174187
const { children, className, style } = this.props;
175188
const { iframe, files, browserPath, openedPath, managerState } = this.state;
176189

177190
return (
178-
<Broadcast
179-
channel="sandpack"
180-
value={{
181-
files,
182-
openedPath,
183-
managerState,
184-
openFile: this.openFile,
185-
browserFrame: iframe,
186-
updateFiles: this.updateFiles,
187-
bundlerURL: this.manager ? this.manager.bundlerURL : undefined,
188-
}}
189-
>
191+
<Broadcast channel="sandpack" value={this._getSandpackState()}>
190192
<div style={style} className={`${className ? className : ''} sandpack`}>
191193
{/* We create a hidden iframe, the bundler will live in this.
192194
We expose this iframe to the Consumer, so other components can show the full

packages/react-sandpack/src/types.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ export interface IManagerState {
4646
}
4747

4848
export interface ISandpackContext {
49-
browserFrame: HTMLIFrameElement;
49+
browserFrame: HTMLIFrameElement | null;
5050
managerState: IManagerState | undefined;
51-
sandboxUrl: string;
51+
bundlerURL: string | undefined;
5252
openedPath: string;
53-
entry: string;
5453
files: IFiles;
5554
openFile: (path: string) => void;
5655
updateFiles: (files: IFiles) => void;

0 commit comments

Comments
 (0)