@thoughtbot/superglue 0.50.0 → 0.51.1

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.
@@ -90,6 +90,8 @@ function remote(path, _temp) {
90
90
  fetchArgs: fetchArgs
91
91
  }));
92
92
  return fetch.apply(void 0, fetchArgs).then(_utils.parseResponse).then(function (_ref2) {
93
+ var _pages$currentPageKey;
94
+
93
95
  var rsp = _ref2.rsp,
94
96
  json = _ref2.json;
95
97
 
@@ -103,6 +105,14 @@ function remote(path, _temp) {
103
105
  rsp: rsp,
104
106
  fetchArgs: fetchArgs
105
107
  });
108
+ var willReplaceCurrent = pageKey == currentPageKey;
109
+ var existingId = (_pages$currentPageKey = pages[currentPageKey]) == null ? void 0 : _pages$currentPageKey.componentIdentifier;
110
+ var receivedId = json.componentIdentifier;
111
+
112
+ if (willReplaceCurrent && !!existingId && existingId != receivedId) {
113
+ console.warn("You're about replace an existing page located at pages[\"" + currentPageKey + "\"]\nthat has the componentIdentifier \"" + existingId + "\" with the contents of a\nreceived page that has a componentIdentifier of \"" + receivedId + "\".\n\nThis can happen if you're using data-sg-remote or remote but your response\nredirected to a completely different page. Since remote requests do not\nnavigate or change the current page component, your current page component may\nreceive a shape that is unexpected and cause issues with rendering.\n\nConsider using data-sg-visit, the visit function, or redirect_back.");
114
+ }
115
+
106
116
  var page = beforeSave(pages[pageKey], json);
107
117
  return dispatch((0, _index.saveAndProcessPage)(pageKey, page)).then(function () {
108
118
  meta.pageKey = pageKey;
package/components/Nav.js CHANGED
@@ -222,7 +222,7 @@ var Nav = /*#__PURE__*/function (_React$Component) {
222
222
  var reminder = '';
223
223
 
224
224
  if (!identifier) {
225
- reminder = 'Did you forget to add `json.component_identifier` in your application.json.props layout?';
225
+ reminder = 'Did you forget to add `json.componentIdentifier` in your application.json.props layout?';
226
226
  }
227
227
 
228
228
  var error = new Error("Superglue Nav component was looking for " + identifier + " but could not find it in your mapping. " + reminder);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thoughtbot/superglue",
3
- "version": "0.50.0",
3
+ "version": "0.51.1",
4
4
  "description": "Use a vanilla Rails with React and Redux",
5
5
  "repository": {
6
6
  "type": "git",
package/utils/url.js CHANGED
@@ -8,8 +8,7 @@ exports.pathQueryHash = pathQueryHash;
8
8
  exports.pathWithoutBZParams = pathWithoutBZParams;
9
9
  exports.removePropsAt = removePropsAt;
10
10
  exports.urlToPageKey = urlToPageKey;
11
- exports.withAntiCache = withAntiCache;
12
- exports.withMimeBust = withMimeBust;
11
+ exports.withFormatJson = withFormatJson;
13
12
  exports.withoutBusters = withoutBusters;
14
13
  exports.withoutHash = withoutHash;
15
14
 
@@ -17,10 +16,6 @@ var _urlParse = _interopRequireDefault(require("url-parse"));
17
16
 
18
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
18
 
20
- var uniqueId = function uniqueId() {
21
- return Math.random().toString(36).substring(2, 10);
22
- };
23
-
24
19
  function pathQuery(url) {
25
20
  var _parse = new _urlParse["default"](url, {}),
26
21
  pathname = _parse.pathname,
@@ -44,43 +39,17 @@ function hasPropsAt(url) {
44
39
  return !!query['props_at'];
45
40
  }
46
41
 
47
- function withAntiCache(url) {
48
- url = new _urlParse["default"](url, {}, true);
49
-
50
- if (Object.prototype.hasOwnProperty.call(url.query, '_')) {
51
- return url.toString();
52
- } else {
53
- url.query['_'] = uniqueId();
54
- return url.toString();
55
- }
56
- }
57
-
58
- function withMimeBust(url) {
42
+ function withFormatJson(url) {
59
43
  url = new _urlParse["default"](url, {}, true);
60
-
61
- if (Object.prototype.hasOwnProperty.call(url.query, '__')) {
62
- return url.toString();
63
- } else {
64
- url.query['__'] = '0';
65
- return url.toString();
66
- }
67
- }
68
-
69
- function withoutBusters(url) {
70
- url = new _urlParse["default"](url, {}, true);
71
- var query = url.query;
72
- delete query['__'];
73
- delete query['_'];
74
- url.query = query;
75
- return pathQuery(url.toString());
44
+ url.query['format'] = 'json';
45
+ return url.toString();
76
46
  }
77
47
 
78
48
  function pathWithoutBZParams(url) {
79
49
  url = new _urlParse["default"](url, {}, true);
80
50
  var query = url.query;
81
- delete query['__'];
82
- delete query['_'];
83
51
  delete query['props_at'];
52
+ delete query['format'];
84
53
  url.query = query;
85
54
  return pathQueryHash(url.toString());
86
55
  }
@@ -96,9 +65,8 @@ function removePropsAt(url) {
96
65
  function urlToPageKey(url) {
97
66
  url = new _urlParse["default"](url, {}, true);
98
67
  var query = url.query;
99
- delete query['__'];
100
- delete query['_'];
101
68
  delete query['props_at'];
69
+ delete query['format'];
102
70
  url.query = query;
103
71
  return pathQuery(url.toString());
104
72
  }
@@ -109,17 +77,16 @@ function withoutHash(url) {
109
77
  return url.toString();
110
78
  }
111
79
 
112
- function formatForXHR(url, opts) {
113
- if (opts === void 0) {
114
- opts = {};
115
- }
116
-
117
- var formats = [withMimeBust, withoutHash];
118
-
119
- if (opts.cacheRequest) {
120
- formats.push(withAntiCache);
121
- }
80
+ function withoutBusters(url) {
81
+ url = new _urlParse["default"](url, {}, true);
82
+ var query = url.query;
83
+ delete query['format'];
84
+ url.query = query;
85
+ return pathQuery(url.toString());
86
+ }
122
87
 
88
+ function formatForXHR(url) {
89
+ var formats = [withoutHash, withFormatJson];
123
90
  return formats.reduce(function (memo, f) {
124
91
  return f(memo);
125
92
  }, url);