Skip to content

Commit 1944578

Browse files
authored
fix: prevent sandbox update when clicking elements in sandbox (#264)
1 parent 97d55cb commit 1944578

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

devtools/src/devtools/panel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function Panel() {
3232
setResult(result);
3333
});
3434

35-
if (action.updateEditor !== false) {
35+
if (action.origin !== 'EDITOR') {
3636
editor.current.setValue(action.query);
3737
}
3838
break;

src/components/MarkupEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function MarkupEditor({ markup, dispatch }) {
1414
dispatch({
1515
type: 'SET_MARKUP',
1616
markup,
17-
updateEditor: false,
17+
origin: 'EDITOR',
1818
immediate: origin === 'user',
1919
}),
2020
[dispatch],

src/components/Preview.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ function Preview({ markup, variant, forwardedRef, dispatch }) {
6666
}
6767

6868
case 'SELECT_NODE': {
69-
dispatch({ type: 'SET_QUERY', query: suggestion.snippet });
69+
dispatch({
70+
type: 'SET_QUERY',
71+
query: suggestion.snippet,
72+
origin: 'SANDBOX',
73+
});
7074
break;
7175
}
7276

src/components/QueryEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function QueryEditor(props) {
1414
dispatch({
1515
type: 'SET_QUERY',
1616
query,
17-
updateEditor: false,
17+
origin: 'EDITOR',
1818
immediate: origin === 'user',
1919
}),
2020
[dispatch],

src/hooks/usePlayground.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function reducer(state, action, exec) {
5252
}
5353

5454
case 'SET_MARKUP': {
55-
if (action.updateEditor !== false) {
55+
if (action.origin !== 'EDITOR') {
5656
exec({ type: 'UPDATE_EDITOR', editor: 'markup' });
5757
}
5858

@@ -66,11 +66,13 @@ function reducer(state, action, exec) {
6666
}
6767

6868
case 'SET_QUERY': {
69-
if (action.updateEditor !== false) {
69+
if (action.origin !== 'EDITOR') {
7070
exec({ type: 'UPDATE_EDITOR', editor: 'query' });
7171
}
7272

73-
exec({ type: 'UPDATE_SANDBOX', immediate });
73+
if (action.origin !== 'SANDBOX') {
74+
exec({ type: 'UPDATE_SANDBOX', immediate });
75+
}
7476

7577
return {
7678
...state,

src/sandbox.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ function onSelectNode(node, { origin }) {
125125
cssPath: cssPath(node, true).toString(),
126126
};
127127

128+
if (action.type === 'SELECT_NODE') {
129+
// optimistically update the highlighted node
130+
state.queriedNodes = [node];
131+
state.highlighter.highlight({ nodes: state.queriedNodes });
132+
}
133+
128134
postMessage(action);
129135
}
130136

0 commit comments

Comments
 (0)