Skip to content

Commit 1334429

Browse files
agilityhawkmfix22
authored andcommitted
fix(Copy to Clipboard): fixed copying of updated URL to clipboard when new snippets are saved. Issue #1379
1 parent 63125dc commit 1334429

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

components/EditorContainer.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,23 @@ function EditorContainer(props) {
5757

5858
const snippetId = snippet && snippet.id
5959
React.useEffect(() => {
60-
if ('/' + (snippetId || '') === props.router.asPath) {
60+
const snippetPath = '/' + (snippetId || '')
61+
if (snippetPath === props.router.asPath) {
6162
return
6263
}
63-
window.history.pushState(null, null, '/' + (snippetId || ''))
64-
// props.router.replace(props.router.asPath, '/' + (snippetId || ''), { shallow: true })
64+
65+
// Reloads only if the snipped.id is different from before. Otherwise returns from above.
66+
props.router.push(
67+
{
68+
pathname: '/[id]',
69+
query: { id: snippetId },
70+
},
71+
snippetPath,
72+
{
73+
shallow: true,
74+
scroll: false
75+
}
76+
)
6577
}, [snippetId, props.router])
6678

6779
function onEditorUpdate(state) {

0 commit comments

Comments
 (0)