Skip to content

Commit 9e96603

Browse files
committed
fix: scroll - add missing init method for window.name method of scroll restoring - fixes #1586 #1457 #1457
1 parent 48286e0 commit 9e96603

4 files changed

Lines changed: 21 additions & 12 deletions

File tree

client/lib/effects/set-scroll.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export function setScrollEffect(
135135
}
136136

137137
function scrollElement(element, scrollProportionally, event: IncomingPayload) {
138-
if (scrollProportionally) {
138+
if (scrollProportionally && element.scrollTo) {
139139
return element.scrollTo(
140140
0,
141141
element.scrollHeight * event.position.proportional

client/lib/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ import { merge } from "rxjs/observable/merge";
1010
import { initLogger, logHandler$ } from "./log";
1111
import { effectOutputHandlers$ } from "./effects";
1212
import { Nanologger } from "../vendor/logger";
13-
import { scrollRestoreHandlers$ } from "./scroll-restore";
13+
import { scrollRestoreHandlers$, initWindowName } from "./scroll-restore";
1414
import { initListeners } from "./listeners";
1515
import { groupBy } from "rxjs/operators/groupBy";
1616
import { withLatestFrom } from "rxjs/operators/withLatestFrom";
1717
import { mergeMap } from "rxjs/operators/mergeMap";
1818
import { share } from "rxjs/operators/share";
1919
import { filter } from "rxjs/operators/filter";
2020
import { pluck } from "rxjs/operators/pluck";
21-
import { tap } from "rxjs/operators/tap";
2221
import { of } from "rxjs/observable/of";
2322

2423
export interface Inputs {
@@ -35,6 +34,7 @@ export interface Inputs {
3534

3635
const window$ = initWindow();
3736
const document$ = initDocument();
37+
const names$ = initWindowName(window);
3838
const { socket$, io$ } = initSocket();
3939
const option$ = initOptions();
4040
const navigator$ = of(navigator);
@@ -86,7 +86,10 @@ const output$ = getStream("[socket]", inputs)(
8686
);
8787

8888
const effect$ = getStream("[effect]", inputs)(combinedEffectHandler$, output$);
89-
const dom$ = getStream("[dom-effect]", inputs)(domHandlers$, effect$);
89+
const dom$ = getStream("[dom-effect]", inputs)(
90+
domHandlers$,
91+
merge(effect$, names$)
92+
);
9093

9194
const merged$ = merge(output$, effect$, dom$);
9295

client/lib/scroll-restore.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ import { empty } from "rxjs/observable/empty";
77
import { of } from "rxjs/observable/of";
88
import * as Log from "./log";
99
import { withLatestFrom } from "rxjs/operators/withLatestFrom";
10-
import { take } from "rxjs/operators/take";
11-
import { mergeMap } from "rxjs/operators/mergeMap";
1210
import { map } from "rxjs/operators/map";
1311
import { setWindowName } from "./dom-effects/set-window-name.dom-effect";
1412
import { setScroll } from "./dom-effects/set-scroll.dom-effect";
1513

1614
export const PREFIX = "<<BS_START>>";
1715
export const SUFFIX = "<<BS_START>>";
18-
export const regex = new RegExp(PREFIX + "(.+?)" + SUFFIX);
16+
export const regex = new RegExp(PREFIX + "(.+?)" + SUFFIX, "g");
17+
18+
function parseFromString(input: string): any {
19+
var match;
20+
var last;
21+
while ((match = regex.exec(input))) {
22+
last = match[1];
23+
}
24+
if (last) {
25+
return JSON.parse(last);
26+
}
27+
}
1928

2029
export function initWindowName(window: Window) {
2130
const saved = (() => {
@@ -24,10 +33,7 @@ export function initWindowName(window: Window) {
2433
* BS json blob & parse it.
2534
*/
2635
try {
27-
const json = window.name.match(regex);
28-
if (json) {
29-
return JSON.parse(json[1]);
30-
}
36+
return parseFromString(window.name);
3137
} catch (e) {
3238
return {};
3339
}

cypress.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"videoRecording": false
2+
"video": false
33
}

0 commit comments

Comments
 (0)