Skip to content

Commit b072eb5

Browse files
authored
fix: restore support for statefull urls (#276)
1 parent 8c7953e commit b072eb5

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/hooks/usePlayground.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ function getInitialState(props) {
278278
// try get state from url (legacy fallback)
279279
else {
280280
const params = url.load();
281-
if (params.markup && params.query) {
281+
if (params) {
282282
return {
283283
...state,
284284
...params,

src/lib/state/url.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,23 @@ function save({ markup, query }) {
4141
}
4242

4343
function load() {
44-
const { hash, search } = window.location;
44+
// .com?markup=...&query=...
45+
let params = queryString.parse(location.search);
4546

46-
// try to migrate old hash based format
47-
// .com/#markupLz&queryLz
48-
if (hash.includes('&')) {
49-
const [markup, query] = hash.slice(1).split('&');
50-
const decompressed = decompress({ markup, query });
47+
// .com#markup=...&query=...
48+
if (!params.markup && !params.query) {
49+
params = queryString.parse(location.hash);
50+
}
5151

52-
if (decompressed.markup && decompressed.query) {
53-
save(decompressed);
54-
}
52+
if (!params.markup && !params.query) {
53+
return;
5554
}
5655

57-
// .com?markup=markupLz&query=queryLz
58-
const { markup, query } = queryString.parse(search);
59-
return decompress({ markup, query });
56+
const { markup, query } = decompress(params);
57+
// we could call `save({ markup, query })` here to force migration. Should we?
58+
// not migrating them can be confusing, as the url style doesn't update on change
59+
60+
return { markup, query };
6061
}
6162

6263
export default {

0 commit comments

Comments
 (0)