@thoughtbot/superglue 0.54.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
1
  // lib/utils/url.ts
8
2
  import parse from "url-parse";
9
3
  function pathQuery(url) {
@@ -19,6 +13,11 @@ function hasPropsAt(url) {
19
13
  const query = parsed.query;
20
14
  return !!query["props_at"];
21
15
  }
16
+ function propsAtParam(url) {
17
+ const parsed = new parse(url, {}, true);
18
+ const query = parsed.query;
19
+ return query["props_at"];
20
+ }
22
21
  function withFormatJson(url) {
23
22
  const parsed = new parse(url, {}, true);
24
23
  parsed.query["format"] = "json";
@@ -63,6 +62,13 @@ function formatForXHR(url) {
63
62
  const formats = [withoutHash, withFormatJson];
64
63
  return formats.reduce((memo, f) => f(memo), url);
65
64
  }
65
+ function parsePageKey(pageKey) {
66
+ const { pathname, query } = new parse(pageKey, {}, true);
67
+ return {
68
+ pathname,
69
+ search: query
70
+ };
71
+ }
66
72
 
67
73
  // lib/utils/helpers.ts
68
74
  function argsForHistory(path) {
@@ -191,23 +197,6 @@ function setIn(object, path, value) {
191
197
  return results[0];
192
198
  }
193
199
 
194
- // lib/utils/react.ts
195
- function mapStateToProps(state, ownProps) {
196
- let pageKey = ownProps.pageKey;
197
- const params = ownProps;
198
- const csrfToken = state.superglue.csrfToken;
199
- pageKey = urlToPageKey(pageKey);
200
- const { data, fragments } = state.pages[pageKey] || {
201
- data: {},
202
- fragments: []
203
- };
204
- return { ...data, ...params, pageKey, csrfToken, fragments };
205
- }
206
- var mapDispatchToProps = {
207
- saveAndProcessPage,
208
- copyPage
209
- };
210
-
211
200
  // lib/utils/request.ts
212
201
  import parse2 from "url-parse";
213
202
 
@@ -248,7 +237,7 @@ function validateResponse(args) {
248
237
  }
249
238
  function handleServerErrors(args) {
250
239
  const { rsp } = args;
251
- if (!rsp.ok) {
240
+ if (!rsp.ok && rsp.status !== 422) {
252
241
  if (rsp.status === 406) {
253
242
  console.error(
254
243
  "Superglue encountered a 406 Not Acceptable response. This can happen if you used respond_to and didn't specify format.json in the block. Try adding it to your respond_to. For example:\n\nrespond_to do |format|\n format.html\n format.json\n format.csv\nend"
@@ -260,7 +249,13 @@ function handleServerErrors(args) {
260
249
  }
261
250
  return args;
262
251
  }
263
- function argsForFetch(getState, pathQuery2, { method = "GET", headers = {}, body = "", signal } = {}) {
252
+ function argsForFetch(getState, pathQuery2, {
253
+ method = "GET",
254
+ headers = {},
255
+ body = "",
256
+ signal,
257
+ ...rest
258
+ } = {}) {
264
259
  method = method.toUpperCase();
265
260
  const currentState = getState().superglue;
266
261
  const nextHeaders = { ...headers };
@@ -311,7 +306,7 @@ function argsForFetch(getState, pathQuery2, { method = "GET", headers = {}, body
311
306
  }
312
307
  delete options.body;
313
308
  }
314
- return [fetchPath.toString(), options];
309
+ return [fetchPath.toString(), { ...options, ...rest }];
315
310
  }
316
311
  function extractJSON(rsp) {
317
312
  return rsp.json().then((json) => {
@@ -330,10 +325,12 @@ var HandlerBuilder = class {
330
325
  constructor({
331
326
  ujsAttributePrefix,
332
327
  visit: visit2,
333
- remote: remote2
328
+ remote: remote2,
329
+ store
334
330
  }) {
335
331
  this.attributePrefix = ujsAttributePrefix;
336
332
  this.isUJS = this.isUJS.bind(this);
333
+ this.store = store;
337
334
  this.handleSubmit = this.handleSubmit.bind(this);
338
335
  this.handleClick = this.handleClick.bind(this);
339
336
  this.visit = visit2;
@@ -347,7 +344,7 @@ var HandlerBuilder = class {
347
344
  }
348
345
  }
349
346
  isNonStandardClick(event) {
350
- return event.which > 1 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;
347
+ return event.button > 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;
351
348
  }
352
349
  isUJS(node) {
353
350
  const hasVisit = !!node.getAttribute(this.attributePrefix + "-visit");
@@ -392,18 +389,17 @@ var HandlerBuilder = class {
392
389
  this.visitOrRemote(link, url, { method: "GET" });
393
390
  }
394
391
  visitOrRemote(linkOrForm, url, opts) {
392
+ const dataset = { ...linkOrForm.dataset };
395
393
  if (linkOrForm.getAttribute(this.attributePrefix + "-visit")) {
396
- const nextOpts = { ...opts };
397
- const placeholderKey = linkOrForm.getAttribute(
398
- this.attributePrefix + "-placeholder"
399
- );
400
- if (placeholderKey) {
401
- nextOpts.placeholderKey = urlToPageKey(placeholderKey);
402
- }
403
- return this.visit(url, { ...nextOpts });
394
+ this.visit(url, { ...opts, dataset });
404
395
  }
405
396
  if (linkOrForm.getAttribute(this.attributePrefix + "-remote")) {
406
- return this.remote(url, opts);
397
+ const { currentPageKey } = this.store.getState().superglue;
398
+ this.remote(url, {
399
+ ...opts,
400
+ pageKey: currentPageKey,
401
+ dataset
402
+ });
407
403
  }
408
404
  }
409
405
  handlers() {
@@ -416,12 +412,14 @@ var HandlerBuilder = class {
416
412
  var ujsHandlers = ({
417
413
  ujsAttributePrefix,
418
414
  visit: visit2,
419
- remote: remote2
415
+ remote: remote2,
416
+ store
420
417
  }) => {
421
418
  const builder = new HandlerBuilder({
422
419
  visit: visit2,
423
420
  remote: remote2,
424
- ujsAttributePrefix
421
+ ujsAttributePrefix,
422
+ store
425
423
  });
426
424
  return builder.handlers();
427
425
  };
@@ -440,65 +438,55 @@ function needsRefresh(prevAssets, newAssets) {
440
438
  import parse3 from "url-parse";
441
439
 
442
440
  // lib/actions.ts
443
- var actions_exports = {};
444
- __export(actions_exports, {
445
- BEFORE_FETCH: () => BEFORE_FETCH,
446
- BEFORE_REMOTE: () => BEFORE_REMOTE,
447
- BEFORE_VISIT: () => BEFORE_VISIT,
448
- COPY_PAGE: () => COPY_PAGE,
449
- GRAFTING_ERROR: () => GRAFTING_ERROR,
450
- GRAFTING_SUCCESS: () => GRAFTING_SUCCESS,
451
- HANDLE_GRAFT: () => HANDLE_GRAFT,
452
- HISTORY_CHANGE: () => HISTORY_CHANGE,
453
- REMOVE_PAGE: () => REMOVE_PAGE,
454
- SAVE_RESPONSE: () => SAVE_RESPONSE,
455
- SET_CSRF_TOKEN: () => SET_CSRF_TOKEN,
456
- SUPERGLUE_ERROR: () => SUPERGLUE_ERROR,
457
- UPDATE_FRAGMENTS: () => UPDATE_FRAGMENTS
458
- });
459
- var BEFORE_FETCH = "@@superglue/BEFORE_FETCH";
460
- var BEFORE_VISIT = "@@superglue/BEFORE_VISIT";
461
- var BEFORE_REMOTE = "@@superglue/BEFORE_REMOTE";
462
- var SAVE_RESPONSE = "@@superglue/SAVE_RESPONSE";
463
- var HANDLE_GRAFT = "@@superglue/HANDLE_GRAFT";
464
- var SUPERGLUE_ERROR = "@@superglue/ERROR";
441
+ import { createAction } from "@reduxjs/toolkit";
465
442
  var GRAFTING_ERROR = "@@superglue/GRAFTING_ERROR";
466
443
  var GRAFTING_SUCCESS = "@@superglue/GRAFTING_SUCCESS";
467
- var HISTORY_CHANGE = "@@superglue/HISTORY_CHANGE";
468
- var SET_CSRF_TOKEN = "@@superglue/SET_CSRF_TOKEN";
469
- var REMOVE_PAGE = "@@superglue/REMOVE_PAGE";
470
- var COPY_PAGE = "@@superglue/COPY_PAGE";
471
- var UPDATE_FRAGMENTS = "@@superglue/UPDATE_FRAGMENTS";
444
+ var saveResponse = createAction(
445
+ "@@superglue/SAVE_RESPONSE",
446
+ ({ pageKey, page }) => {
447
+ pageKey = urlToPageKey(pageKey);
448
+ return {
449
+ payload: {
450
+ pageKey,
451
+ page
452
+ }
453
+ };
454
+ }
455
+ );
456
+ var handleGraft = createAction(
457
+ "@@superglue/HANDLE_GRAFT",
458
+ ({ pageKey, page }) => {
459
+ pageKey = urlToPageKey(pageKey);
460
+ return {
461
+ payload: {
462
+ page,
463
+ pageKey
464
+ }
465
+ };
466
+ }
467
+ );
468
+ var superglueError = createAction(
469
+ "@@superglue/ERROR"
470
+ );
471
+ var updateFragments = createAction("@@superglue/UPDATE_FRAGMENTS");
472
+ var copyPage = createAction(
473
+ "@@superglue/COPY_PAGE"
474
+ );
475
+ var removePage = createAction(
476
+ "@@superglue/REMOVE_PAGE"
477
+ );
478
+ var beforeFetch = createAction(
479
+ "@@superglue/BEFORE_FETCH"
480
+ );
481
+ var beforeVisit = createAction("@@superglue/BEFORE_VISIT");
482
+ var beforeRemote = createAction("@@superglue/BEFORE_REMOTE");
483
+ var setCSRFToken = createAction("@@superglue/SET_CSRF_TOKEN");
484
+ var historyChange = createAction("@@superglue/HISTORY_CHANGE");
485
+ var setActivePage = createAction("@@superglue/SET_ACTIVE_PAGE");
472
486
 
473
487
  // lib/action_creators/requests.ts
474
- function beforeVisit(payload) {
475
- return {
476
- type: BEFORE_VISIT,
477
- payload
478
- };
479
- }
480
- function beforeRemote(payload) {
481
- return {
482
- type: BEFORE_REMOTE,
483
- payload
484
- };
485
- }
486
- function beforeFetch(payload) {
487
- return {
488
- type: BEFORE_FETCH,
489
- payload
490
- };
491
- }
492
- function handleError(err) {
493
- return {
494
- type: SUPERGLUE_ERROR,
495
- payload: {
496
- message: err.message
497
- }
498
- };
499
- }
500
488
  function handleFetchErr(err, fetchArgs, dispatch) {
501
- dispatch(handleError(err));
489
+ dispatch(superglueError({ message: err.message }));
502
490
  throw err;
503
491
  }
504
492
  function buildMeta(pageKey, page, state, rsp, fetchArgs) {
@@ -514,47 +502,55 @@ function buildMeta(pageKey, page, state, rsp, fetchArgs) {
514
502
  needsRefresh: needsRefresh(prevAssets, nextAssets)
515
503
  };
516
504
  }
505
+ var MismatchedComponentError = class extends Error {
506
+ constructor(message) {
507
+ super(message);
508
+ this.name = "MismatchedComponentError";
509
+ }
510
+ };
517
511
  var remote = (path, {
518
- method = "GET",
519
- headers,
520
- body,
521
- pageKey: rawPageKey,
522
- beforeSave = (prevPage, receivedPage) => receivedPage
512
+ pageKey: targetPageKey,
513
+ force = false,
514
+ beforeSave = (prevPage, receivedPage) => receivedPage,
515
+ ...rest
523
516
  } = {}) => {
524
517
  path = withoutBusters(path);
525
- rawPageKey = rawPageKey && urlToPageKey(rawPageKey);
518
+ targetPageKey = targetPageKey && urlToPageKey(targetPageKey);
526
519
  return (dispatch, getState) => {
527
- const fetchArgs = argsForFetch(getState, path, {
528
- method,
529
- headers,
530
- body
531
- });
532
- if (rawPageKey === void 0) {
533
- rawPageKey = getState().superglue.currentPageKey;
534
- }
535
- const pageKey = rawPageKey;
520
+ const fetchArgs = argsForFetch(getState, path, rest);
536
521
  const currentPageKey = getState().superglue.currentPageKey;
537
522
  dispatch(beforeRemote({ currentPageKey, fetchArgs }));
538
523
  dispatch(beforeFetch({ fetchArgs }));
539
524
  return fetch(...fetchArgs).then(parseResponse).then(({ rsp, json }) => {
540
525
  const { superglue, pages = {} } = getState();
526
+ let pageKey;
527
+ if (targetPageKey === void 0) {
528
+ const isGet = fetchArgs[1].method === "GET";
529
+ pageKey = calculatePageKey(rsp, isGet, currentPageKey);
530
+ } else {
531
+ pageKey = targetPageKey;
532
+ }
541
533
  const meta = buildMeta(pageKey, json, superglue, rsp, fetchArgs);
542
- const willReplaceCurrent = pageKey == currentPageKey;
543
- const existingId = pages[currentPageKey]?.componentIdentifier;
534
+ const existingId = pages[pageKey]?.componentIdentifier;
544
535
  const receivedId = json.componentIdentifier;
545
- if (willReplaceCurrent && !!existingId && existingId != receivedId) {
546
- console.warn(
547
- `You're about replace an existing page located at pages["${currentPageKey}"]
548
- that has the componentIdentifier "${existingId}" with the contents of a
549
- received page that has a componentIdentifier of "${receivedId}".
536
+ if (!!existingId && existingId != receivedId && !force) {
537
+ const message = `You cannot replace or update an existing page
538
+ located at pages["${currentPageKey}"] that has a componentIdentifier
539
+ of "${existingId}" with the contents of a page response that has a
540
+ componentIdentifier of "${receivedId}".
550
541
 
551
- This can happen if you're using data-sg-remote or remote but your response
552
- redirected to a completely different page. Since remote requests do not
553
- navigate or change the current page component, your current page component may
554
- receive a shape that is unexpected and cause issues with rendering.
542
+ This can happen if you're using data-sg-remote or remote but your
543
+ response redirected to a page with a different componentIdentifier
544
+ than the target page.
555
545
 
556
- Consider using data-sg-visit, the visit function, or redirect_back.`
557
- );
546
+ This limitation exists because the resulting page shape from grafting
547
+ "${receivedId}"'s "${propsAtParam(path)}" into "${existingId}" may not be
548
+ compatible with the page component associated with "${existingId}".
549
+
550
+ Consider using data-sg-visit, the visit function, or redirect_back to
551
+ the same page. Or if you're sure you want to proceed, use force: true.
552
+ `;
553
+ throw new MismatchedComponentError(message);
558
554
  }
559
555
  const page = beforeSave(pages[pageKey], json);
560
556
  return dispatch(saveAndProcessPage(pageKey, page)).then(() => meta);
@@ -562,121 +558,115 @@ Consider using data-sg-visit, the visit function, or redirect_back.`
562
558
  };
563
559
  };
564
560
  var lastVisitController = {
565
- abort: () => {
561
+ /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
562
+ abort: (_reason) => {
566
563
  }
567
564
  };
568
565
  var visit = (path, {
569
- method = "GET",
570
- headers,
571
- body,
572
566
  placeholderKey,
573
567
  beforeSave = (prevPage, receivedPage) => receivedPage,
574
- revisit = false
568
+ revisit = false,
569
+ ...rest
575
570
  } = {}) => {
576
571
  path = withoutBusters(path);
577
- let pageKey = urlToPageKey(path);
578
572
  return (dispatch, getState) => {
579
- placeholderKey = placeholderKey && urlToPageKey(placeholderKey);
580
- const hasPlaceholder = !!(placeholderKey && getState().pages[placeholderKey]);
581
- if (placeholderKey && hasPlaceholder) {
582
- dispatch(copyPage({ from: placeholderKey, to: pageKey }));
583
- }
584
- if (placeholderKey && !hasPlaceholder) {
573
+ const currentPageKey = getState().superglue.currentPageKey;
574
+ placeholderKey = placeholderKey && urlToPageKey(placeholderKey) || currentPageKey;
575
+ const hasPlaceholder = placeholderKey in getState().pages;
576
+ if (hasPropsAt(path) && !hasPlaceholder) {
585
577
  console.warn(
586
578
  `Could not find placeholder with key ${placeholderKey} in state. The props_at param will be ignored`
587
579
  );
588
580
  path = removePropsAt(path);
589
581
  }
590
- if (!placeholderKey && hasPropsAt(path)) {
591
- console.warn(
592
- `visit was called with props_at param in the path ${path}, this will be ignore unless you provide a placeholder.`
593
- );
594
- path = removePropsAt(path);
595
- }
596
582
  const controller = new AbortController();
597
583
  const { signal } = controller;
598
584
  const fetchArgs = argsForFetch(getState, path, {
599
- headers,
600
- body,
601
- method,
585
+ ...rest,
602
586
  signal
603
587
  });
604
- const currentPageKey = getState().superglue.currentPageKey;
605
588
  dispatch(beforeVisit({ currentPageKey, fetchArgs }));
606
589
  dispatch(beforeFetch({ fetchArgs }));
607
- lastVisitController.abort();
590
+ lastVisitController.abort(
591
+ "Aborting the previous `visit`. There can be one visit at a time. Use `remote` if there is a need for async requests."
592
+ );
608
593
  lastVisitController = controller;
609
594
  return fetch(...fetchArgs).then(parseResponse).then(({ rsp, json }) => {
610
595
  const { superglue, pages = {} } = getState();
611
- const meta = buildMeta(pageKey, json, superglue, rsp, fetchArgs);
612
596
  const isGet = fetchArgs[1].method === "GET";
613
- meta.suggestedAction = "push";
614
- if (!rsp.redirected && !isGet) {
615
- meta.suggestedAction = "replace";
616
- }
617
- if (revisit && isGet) {
618
- if (rsp.redirected) {
619
- meta.suggestedAction = "replace";
620
- } else {
621
- meta.suggestedAction = "none";
597
+ const pageKey = calculatePageKey(rsp, isGet, currentPageKey);
598
+ if (placeholderKey && hasPropsAt(path) && hasPlaceholder) {
599
+ const existingId = pages[placeholderKey]?.componentIdentifier;
600
+ const receivedId = json.componentIdentifier;
601
+ if (!!existingId && existingId != receivedId) {
602
+ const message = `You received a page response with a
603
+ componentIdentifier "${receivedId}" that is different than the
604
+ componentIdentifier "${existingId}" located at ${placeholderKey}.
605
+
606
+ This can happen if you're using data-sg-visit or visit with a
607
+ props_at param, but the response redirected to a page with a
608
+ different componentIdentifier than the target page.
609
+
610
+ This limitation exists because the resulting page shape from grafting
611
+ "${receivedId}"'s "${propsAtParam(path)}" into "${existingId}" may not be
612
+ compatible with the page component associated with "${existingId}".
613
+
614
+ Check that you're rendering a page with a matching
615
+ componentIdentifier, or consider using redirect_back_with_props_at
616
+ to the same page.
617
+ `;
618
+ throw new MismatchedComponentError(message);
622
619
  }
620
+ dispatch(copyPage({ from: placeholderKey, to: pageKey }));
623
621
  }
624
- pageKey = urlToPageKey(rsp.url);
625
- if (!isGet && !rsp.redirected) {
626
- pageKey = currentPageKey;
627
- }
628
- const contentLocation = rsp.headers.get("content-location");
629
- if (contentLocation) {
630
- pageKey = urlToPageKey(contentLocation);
631
- }
622
+ const meta = buildMeta(pageKey, json, superglue, rsp, fetchArgs);
623
+ const visitMeta = {
624
+ ...meta,
625
+ navigationAction: calculateNavAction(
626
+ meta,
627
+ rsp,
628
+ isGet,
629
+ pageKey,
630
+ currentPageKey,
631
+ revisit
632
+ )
633
+ };
632
634
  const page = beforeSave(pages[pageKey], json);
633
- return dispatch(saveAndProcessPage(pageKey, page)).then(() => {
634
- meta.pageKey = pageKey;
635
- return meta;
636
- });
635
+ return dispatch(saveAndProcessPage(pageKey, page)).then(() => visitMeta);
637
636
  }).catch((e) => handleFetchErr(e, fetchArgs, dispatch));
638
637
  };
639
638
  };
640
-
641
- // lib/action_creators/index.ts
642
- function copyPage({
643
- from,
644
- to
645
- }) {
646
- return {
647
- type: COPY_PAGE,
648
- payload: {
649
- from,
650
- to
651
- }
652
- };
653
- }
654
- function saveResponse({
655
- pageKey,
656
- page
657
- }) {
658
- pageKey = urlToPageKey(pageKey);
659
- return {
660
- type: SAVE_RESPONSE,
661
- payload: {
662
- pageKey,
663
- page
639
+ function calculateNavAction(meta, rsp, isGet, pageKey, currentPageKey, revisit) {
640
+ let navigationAction = "push";
641
+ if (!rsp.redirected && !isGet) {
642
+ navigationAction = "replace";
643
+ }
644
+ const isSamePage = pageKey == currentPageKey;
645
+ if (isSamePage) {
646
+ navigationAction = "none";
647
+ }
648
+ if (revisit && isGet) {
649
+ if (rsp.redirected) {
650
+ navigationAction = "replace";
651
+ } else {
652
+ navigationAction = "none";
664
653
  }
665
- };
654
+ }
655
+ return navigationAction;
666
656
  }
667
- function handleGraft({
668
- pageKey,
669
- page
670
- }) {
671
- pageKey = urlToPageKey(pageKey);
672
- return {
673
- type: HANDLE_GRAFT,
674
- payload: {
675
- pageKey,
676
- page
677
- }
678
- };
657
+ function calculatePageKey(rsp, isGet, currentPageKey) {
658
+ let pageKey = urlToPageKey(rsp.url);
659
+ if (!isGet && !rsp.redirected) {
660
+ pageKey = currentPageKey;
661
+ }
662
+ const contentLocation = rsp.headers.get("content-location");
663
+ if (contentLocation) {
664
+ pageKey = urlToPageKey(contentLocation);
665
+ }
666
+ return pageKey;
679
667
  }
668
+
669
+ // lib/action_creators/index.ts
680
670
  function fetchDeferments(pageKey, defers = []) {
681
671
  pageKey = urlToPageKey(pageKey);
682
672
  return (dispatch) => {
@@ -710,35 +700,60 @@ function fetchDeferments(pageKey, defers = []) {
710
700
  return Promise.all(fetches);
711
701
  };
712
702
  }
713
- function updateFragmentsUsing(page) {
714
- const changedFragments = {};
715
- page.fragments.forEach((fragment) => {
716
- const { type, path } = fragment;
717
- changedFragments[type] = getIn(page, path);
718
- });
719
- return {
720
- type: UPDATE_FRAGMENTS,
721
- payload: { changedFragments }
722
- };
723
- }
724
703
  function saveAndProcessPage(pageKey, page) {
725
704
  return (dispatch, getState) => {
726
705
  pageKey = urlToPageKey(pageKey);
727
706
  const { defers = [] } = page;
728
707
  if ("action" in page) {
708
+ const prevPage = getState().pages[pageKey];
729
709
  dispatch(handleGraft({ pageKey, page }));
710
+ const currentPage = getState().pages[pageKey];
711
+ currentPage.fragments.forEach((fragment) => {
712
+ const { type, path } = fragment;
713
+ const currentFragment = getIn(currentPage, path);
714
+ const prevFragment = getIn(prevPage, path);
715
+ if (!prevFragment) {
716
+ dispatch(
717
+ updateFragments({
718
+ name: type,
719
+ pageKey,
720
+ value: currentFragment,
721
+ path
722
+ })
723
+ );
724
+ } else if (currentFragment !== prevFragment) {
725
+ dispatch(
726
+ updateFragments({
727
+ name: type,
728
+ pageKey,
729
+ value: currentFragment,
730
+ previousValue: prevFragment,
731
+ path
732
+ })
733
+ );
734
+ }
735
+ });
730
736
  } else {
731
737
  dispatch(saveResponse({ pageKey, page }));
738
+ const currentPage = getState().pages[pageKey];
739
+ currentPage.fragments.forEach((fragment) => {
740
+ const { type, path } = fragment;
741
+ const currentFragment = getIn(currentPage, path);
742
+ dispatch(
743
+ updateFragments({
744
+ name: type,
745
+ pageKey,
746
+ value: currentFragment,
747
+ path
748
+ })
749
+ );
750
+ });
732
751
  }
733
752
  const hasFetch = typeof fetch != "undefined";
734
753
  if (hasFetch) {
735
- return dispatch(fetchDeferments(pageKey, defers)).then(() => {
736
- if (page.fragments.length > 0) {
737
- const finishedPage = getState().pages[pageKey];
738
- dispatch(updateFragmentsUsing(finishedPage));
739
- return Promise.resolve();
740
- }
741
- });
754
+ return dispatch(fetchDeferments(pageKey, defers)).then(
755
+ () => Promise.resolve()
756
+ );
742
757
  } else {
743
758
  return Promise.resolve();
744
759
  }
@@ -746,34 +761,30 @@ function saveAndProcessPage(pageKey, page) {
746
761
  }
747
762
 
748
763
  export {
764
+ config,
749
765
  pathWithoutBZParams,
750
766
  urlToPageKey,
767
+ parsePageKey,
751
768
  argsForHistory,
752
- KeyPathError,
753
769
  getIn,
754
770
  setIn,
755
- BEFORE_FETCH,
756
- BEFORE_VISIT,
757
- BEFORE_REMOTE,
758
- SAVE_RESPONSE,
759
- HANDLE_GRAFT,
771
+ ujsHandlers,
760
772
  GRAFTING_ERROR,
761
773
  GRAFTING_SUCCESS,
762
- HISTORY_CHANGE,
763
- SET_CSRF_TOKEN,
764
- REMOVE_PAGE,
765
- COPY_PAGE,
766
- UPDATE_FRAGMENTS,
767
- actions_exports,
768
- remote,
769
- visit,
770
- copyPage,
771
774
  saveResponse,
772
775
  handleGraft,
773
- saveAndProcessPage,
774
- mapStateToProps,
775
- mapDispatchToProps,
776
- config,
777
- ujsHandlers
776
+ updateFragments,
777
+ copyPage,
778
+ removePage,
779
+ beforeFetch,
780
+ beforeVisit,
781
+ beforeRemote,
782
+ setCSRFToken,
783
+ historyChange,
784
+ setActivePage,
785
+ MismatchedComponentError,
786
+ remote,
787
+ visit,
788
+ saveAndProcessPage
778
789
  };
779
- //# sourceMappingURL=chunk-MNVGYKSD.mjs.map
790
+ //# sourceMappingURL=chunk-LGUVOEZ3.mjs.map