@teleporthq/teleport-plugin-common 0.45.3-alpha.0 → 0.45.13
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.
- package/__tests__/builders/html-builders.ts +9 -2
- package/__tests__/builders/style-builders.ts +135 -1
- package/__tests__/node-handlers/node-to-html/index.ts +2 -0
- package/__tests__/node-handlers/node-to-jsx/attribute-value-mapper.ts +77 -0
- package/__tests__/node-handlers/node-to-jsx/calendar-events-reviver.ts +176 -0
- package/__tests__/node-handlers/node-to-jsx/chart-data-guard.ts +101 -0
- package/__tests__/node-handlers/node-to-jsx/cms-list-repeater-ecommerce-source.ts +79 -0
- package/__tests__/node-handlers/node-to-jsx/cms-list-repeater-loading.ts +122 -0
- package/__tests__/node-handlers/node-to-jsx/index.ts +719 -3
- package/__tests__/node-handlers/node-to-jsx/url-search-params-expression.ts +59 -0
- package/__tests__/node-handlers/node-to-jsx/utils.ts +635 -3
- package/__tests__/utils/ast-utils.ts +188 -0
- package/__tests__/utils/content-property-sanitiser.ts +156 -0
- package/__tests__/utils/page-seeds-state-from-data-source.ts +70 -0
- package/__tests__/utils/parse-string-with-template-expressions.ts +82 -0
- package/__tests__/utils/resource-auth-scheme.ts +55 -0
- package/__tests__/utils/route-utils.ts +118 -0
- package/__tests__/utils/style-utils.ts +59 -0
- package/__tests__/utils/template-expression-balance.ts +83 -0
- package/__tests__/utils/url-query-writer.ts +239 -0
- package/__tests__/utils/url-search-param-sync.ts +138 -0
- package/__tests__/utils/url-search-params.ts +48 -0
- package/dist/cjs/builders/ast-builders.d.ts +2 -0
- package/dist/cjs/builders/ast-builders.d.ts.map +1 -1
- package/dist/cjs/builders/ast-builders.js +41 -3
- package/dist/cjs/builders/ast-builders.js.map +1 -1
- package/dist/cjs/builders/hast-builders.d.ts +1 -0
- package/dist/cjs/builders/hast-builders.d.ts.map +1 -1
- package/dist/cjs/builders/hast-builders.js +11 -1
- package/dist/cjs/builders/hast-builders.js.map +1 -1
- package/dist/cjs/builders/style-builders.d.ts +8 -2
- package/dist/cjs/builders/style-builders.d.ts.map +1 -1
- package/dist/cjs/builders/style-builders.js +80 -33
- package/dist/cjs/builders/style-builders.js.map +1 -1
- package/dist/cjs/index.d.ts +5 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +10 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/constants.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/constants.js +2 -0
- package/dist/cjs/node-handlers/node-to-html/constants.js.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/index.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/index.js +69 -1
- package/dist/cjs/node-handlers/node-to-html/index.js.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/types.d.ts +5 -1
- package/dist/cjs/node-handlers/node-to-html/types.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/utils.d.ts +2 -1
- package/dist/cjs/node-handlers/node-to-html/utils.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-html/utils.js +174 -13
- package/dist/cjs/node-handlers/node-to-html/utils.js.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/index.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/index.js +1443 -45
- package/dist/cjs/node-handlers/node-to-jsx/index.js.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/types.d.ts +60 -6
- package/dist/cjs/node-handlers/node-to-jsx/types.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/utils.d.ts +80 -7
- package/dist/cjs/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
- package/dist/cjs/node-handlers/node-to-jsx/utils.js +883 -72
- package/dist/cjs/node-handlers/node-to-jsx/utils.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/utils/ast-utils.d.ts +163 -11
- package/dist/cjs/utils/ast-utils.d.ts.map +1 -1
- package/dist/cjs/utils/ast-utils.js +1013 -75
- package/dist/cjs/utils/ast-utils.js.map +1 -1
- package/dist/cjs/utils/hast-utils.d.ts +8 -6
- package/dist/cjs/utils/hast-utils.d.ts.map +1 -1
- package/dist/cjs/utils/hast-utils.js +28 -4
- package/dist/cjs/utils/hast-utils.js.map +1 -1
- package/dist/cjs/utils/nested-selector-commas.d.ts +2 -0
- package/dist/cjs/utils/nested-selector-commas.d.ts.map +1 -0
- package/dist/cjs/utils/nested-selector-commas.js +81 -0
- package/dist/cjs/utils/nested-selector-commas.js.map +1 -0
- package/dist/cjs/utils/route-utils.d.ts +117 -0
- package/dist/cjs/utils/route-utils.d.ts.map +1 -0
- package/dist/cjs/utils/route-utils.js +212 -0
- package/dist/cjs/utils/route-utils.js.map +1 -0
- package/dist/cjs/utils/style-utils.d.ts +1 -0
- package/dist/cjs/utils/style-utils.d.ts.map +1 -1
- package/dist/cjs/utils/style-utils.js +181 -2
- package/dist/cjs/utils/style-utils.js.map +1 -1
- package/dist/cjs/utils/template-expression-balance.d.ts +58 -0
- package/dist/cjs/utils/template-expression-balance.d.ts.map +1 -0
- package/dist/cjs/utils/template-expression-balance.js +181 -0
- package/dist/cjs/utils/template-expression-balance.js.map +1 -0
- package/dist/cjs/utils/types.d.ts +3 -0
- package/dist/cjs/utils/types.d.ts.map +1 -0
- package/dist/cjs/utils/types.js +3 -0
- package/dist/cjs/utils/types.js.map +1 -0
- package/dist/cjs/utils/url-query-writer.d.ts +123 -0
- package/dist/cjs/utils/url-query-writer.d.ts.map +1 -0
- package/dist/cjs/utils/url-query-writer.js +260 -0
- package/dist/cjs/utils/url-query-writer.js.map +1 -0
- package/dist/cjs/utils/url-search-param-sync.d.ts +4 -0
- package/dist/cjs/utils/url-search-param-sync.d.ts.map +1 -0
- package/dist/cjs/utils/url-search-param-sync.js +241 -0
- package/dist/cjs/utils/url-search-param-sync.js.map +1 -0
- package/dist/cjs/utils/url-search-params.d.ts +48 -0
- package/dist/cjs/utils/url-search-params.d.ts.map +1 -0
- package/dist/cjs/utils/url-search-params.js +109 -0
- package/dist/cjs/utils/url-search-params.js.map +1 -0
- package/dist/esm/builders/ast-builders.d.ts +2 -0
- package/dist/esm/builders/ast-builders.d.ts.map +1 -1
- package/dist/esm/builders/ast-builders.js +40 -4
- package/dist/esm/builders/ast-builders.js.map +1 -1
- package/dist/esm/builders/hast-builders.d.ts +1 -0
- package/dist/esm/builders/hast-builders.d.ts.map +1 -1
- package/dist/esm/builders/hast-builders.js +9 -0
- package/dist/esm/builders/hast-builders.js.map +1 -1
- package/dist/esm/builders/style-builders.d.ts +8 -2
- package/dist/esm/builders/style-builders.d.ts.map +1 -1
- package/dist/esm/builders/style-builders.js +78 -32
- package/dist/esm/builders/style-builders.js.map +1 -1
- package/dist/esm/index.d.ts +5 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node-handlers/node-to-html/constants.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-html/constants.js +2 -0
- package/dist/esm/node-handlers/node-to-html/constants.js.map +1 -1
- package/dist/esm/node-handlers/node-to-html/index.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-html/index.js +71 -3
- package/dist/esm/node-handlers/node-to-html/index.js.map +1 -1
- package/dist/esm/node-handlers/node-to-html/types.d.ts +5 -1
- package/dist/esm/node-handlers/node-to-html/types.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-html/utils.d.ts +2 -1
- package/dist/esm/node-handlers/node-to-html/utils.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-html/utils.js +170 -13
- package/dist/esm/node-handlers/node-to-html/utils.js.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/index.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/index.js +1442 -47
- package/dist/esm/node-handlers/node-to-jsx/index.js.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/types.d.ts +60 -6
- package/dist/esm/node-handlers/node-to-jsx/types.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/utils.d.ts +80 -7
- package/dist/esm/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
- package/dist/esm/node-handlers/node-to-jsx/utils.js +875 -70
- package/dist/esm/node-handlers/node-to-jsx/utils.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/utils/ast-utils.d.ts +163 -11
- package/dist/esm/utils/ast-utils.d.ts.map +1 -1
- package/dist/esm/utils/ast-utils.js +989 -75
- package/dist/esm/utils/ast-utils.js.map +1 -1
- package/dist/esm/utils/hast-utils.d.ts +8 -6
- package/dist/esm/utils/hast-utils.d.ts.map +1 -1
- package/dist/esm/utils/hast-utils.js +26 -3
- package/dist/esm/utils/hast-utils.js.map +1 -1
- package/dist/esm/utils/nested-selector-commas.d.ts +2 -0
- package/dist/esm/utils/nested-selector-commas.d.ts.map +1 -0
- package/dist/esm/utils/nested-selector-commas.js +77 -0
- package/dist/esm/utils/nested-selector-commas.js.map +1 -0
- package/dist/esm/utils/route-utils.d.ts +117 -0
- package/dist/esm/utils/route-utils.d.ts.map +1 -0
- package/dist/esm/utils/route-utils.js +179 -0
- package/dist/esm/utils/route-utils.js.map +1 -0
- package/dist/esm/utils/style-utils.d.ts +1 -0
- package/dist/esm/utils/style-utils.d.ts.map +1 -1
- package/dist/esm/utils/style-utils.js +179 -1
- package/dist/esm/utils/style-utils.js.map +1 -1
- package/dist/esm/utils/template-expression-balance.d.ts +58 -0
- package/dist/esm/utils/template-expression-balance.d.ts.map +1 -0
- package/dist/esm/utils/template-expression-balance.js +174 -0
- package/dist/esm/utils/template-expression-balance.js.map +1 -0
- package/dist/esm/utils/types.d.ts +3 -0
- package/dist/esm/utils/types.d.ts.map +1 -0
- package/dist/esm/utils/types.js +2 -0
- package/dist/esm/utils/types.js.map +1 -0
- package/dist/esm/utils/url-query-writer.d.ts +123 -0
- package/dist/esm/utils/url-query-writer.d.ts.map +1 -0
- package/dist/esm/utils/url-query-writer.js +229 -0
- package/dist/esm/utils/url-query-writer.js.map +1 -0
- package/dist/esm/utils/url-search-param-sync.d.ts +4 -0
- package/dist/esm/utils/url-search-param-sync.d.ts.map +1 -0
- package/dist/esm/utils/url-search-param-sync.js +213 -0
- package/dist/esm/utils/url-search-param-sync.js.map +1 -0
- package/dist/esm/utils/url-search-params.d.ts +48 -0
- package/dist/esm/utils/url-search-params.d.ts.map +1 -0
- package/dist/esm/utils/url-search-params.js +81 -0
- package/dist/esm/utils/url-search-params.js.map +1 -0
- package/package.json +4 -4
- package/src/builders/ast-builders.ts +80 -3
- package/src/builders/hast-builders.ts +11 -0
- package/src/builders/style-builders.ts +121 -43
- package/src/index.ts +22 -1
- package/src/node-handlers/node-to-html/constants.ts +2 -0
- package/src/node-handlers/node-to-html/index.ts +126 -6
- package/src/node-handlers/node-to-html/types.ts +6 -0
- package/src/node-handlers/node-to-html/utils.ts +228 -14
- package/src/node-handlers/node-to-jsx/index.ts +2135 -62
- package/src/node-handlers/node-to-jsx/types.ts +75 -32
- package/src/node-handlers/node-to-jsx/utils.ts +1173 -84
- package/src/utils/ast-utils.ts +1316 -127
- package/src/utils/hast-utils.ts +37 -9
- package/src/utils/nested-selector-commas.ts +88 -0
- package/src/utils/route-utils.ts +214 -0
- package/src/utils/style-utils.ts +183 -1
- package/src/utils/template-expression-balance.ts +196 -0
- package/src/utils/types.ts +25 -0
- package/src/utils/url-query-writer.ts +318 -0
- package/src/utils/url-search-param-sync.ts +303 -0
- package/src/utils/url-search-params.ts +122 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GACtB,KAAK,GACL,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,IAAI,GACJ,GAAG,GACH,GAAG,GACH,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,YAAY,GACZ,GAAG,GACH,GAAG,GACH,IAAI,GACJ,IAAI,CAAA;AAER,MAAM,MAAM,cAAc,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,GAAG,GAAG,GAAG,GAAG,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as types from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* The ONE place a generated page is allowed to write `router.query` from.
|
|
4
|
+
*
|
|
5
|
+
* ## The defect this exists to make impossible
|
|
6
|
+
*
|
|
7
|
+
* Every URL-bound control used to own a `useEffect` that did
|
|
8
|
+
*
|
|
9
|
+
* const __nextQuery = { ...router.query } // its own snapshot
|
|
10
|
+
* __nextQuery.categoryFilter = 'Rings'
|
|
11
|
+
* router.replace({ pathname, query: __nextQuery }, undefined, { shallow: true })
|
|
12
|
+
*
|
|
13
|
+
* `router.query` is a per-render SHALLOW COPY that Next rebuilds only when the
|
|
14
|
+
* router itself re-renders (`makePublicRouterInstance` — "makes sure query is
|
|
15
|
+
* not stateful"), and `router.replace` updates it asynchronously. So two
|
|
16
|
+
* controls writing in the same flush both spread the SAME pre-change object,
|
|
17
|
+
* and whichever `replace` commits last silently drops the key the other had
|
|
18
|
+
* just added — or resurrects one it had just deleted.
|
|
19
|
+
*
|
|
20
|
+
* That is not a rare interleaving; it is the common one. Changing a filter
|
|
21
|
+
* resets the page, so the filter's write-back and the page's write-back always
|
|
22
|
+
* fire together.
|
|
23
|
+
*
|
|
24
|
+
* ⛔ And the damage does not stop at a wrong URL. Each control also has a
|
|
25
|
+
* READ-BACK effect that pushes `router.query` back into React state. Once a key
|
|
26
|
+
* is erased, the read-back clears that control's state, the write-back
|
|
27
|
+
* re-asserts it, the next landing erases it again — and because each round
|
|
28
|
+
* reads the other side's PRE-flush value, the pair computes
|
|
29
|
+
* `(state, url) -> (url, state)`: a swap. A swap has no fixed point off the
|
|
30
|
+
* diagonal, so it never converges. The observed symptom was a products list
|
|
31
|
+
* that re-fetched and flickered forever after picking a category while on
|
|
32
|
+
* page 5.
|
|
33
|
+
*
|
|
34
|
+
* ## The fix
|
|
35
|
+
*
|
|
36
|
+
* Nobody spreads `router.query` any more. All writers go through one function
|
|
37
|
+
* that merges into `pending` — the last query this component ASKED for —
|
|
38
|
+
* falling back to `router.query` only when nothing is in flight. The second
|
|
39
|
+
* write of a flush therefore builds on the first's payload instead of racing
|
|
40
|
+
* it, no key is ever lost, and with no key lost there is nothing for a
|
|
41
|
+
* read-back to disagree about.
|
|
42
|
+
*
|
|
43
|
+
* `pending` is dropped once every replace it was built from has settled, so an
|
|
44
|
+
* external navigation (a Link, browser back/forward) is never merged into a
|
|
45
|
+
* stale snapshot.
|
|
46
|
+
*
|
|
47
|
+
* @see `buildUrlWriteBackEffect` in `./url-search-param-sync` and
|
|
48
|
+
* `buildPageUrlSyncEffect` in `teleport-plugin-next-data-source` — the two
|
|
49
|
+
* callers, in two different packages, which is why this lives here.
|
|
50
|
+
*/
|
|
51
|
+
/** `useRef` holding `{ pending, inFlight }`. Shared by every writer in a component. */
|
|
52
|
+
export declare const QUERY_SYNC_REF_ID = "__tqQuerySyncRef";
|
|
53
|
+
/** The write function every URL-bound control calls. */
|
|
54
|
+
export declare const QUERY_WRITER_ID = "__tqWriteQueryParam";
|
|
55
|
+
/**
|
|
56
|
+
* `__tqQuerySyncRef.current.inFlight === 0` — "the URL is settled".
|
|
57
|
+
*
|
|
58
|
+
* The page-URL effect uses it to gate its ADOPT branch: while a replace this
|
|
59
|
+
* component issued is still landing, `router.query` is a value the page is on
|
|
60
|
+
* its way OUT of, and adopting it would undo the move that is in flight.
|
|
61
|
+
*/
|
|
62
|
+
export declare const buildQuerySettledExpr: () => types.BinaryExpression;
|
|
63
|
+
/** `__tqWriteQueryParam('<paramKey>', <valueExpr>)` — `undefined` removes the key. */
|
|
64
|
+
export declare const buildQueryWriteCall: (paramKey: string, valueExpr: types.Expression) => types.ExpressionStatement;
|
|
65
|
+
/**
|
|
66
|
+
* True when a previous plugin already emitted the declarations.
|
|
67
|
+
*
|
|
68
|
+
* Both `createNextUrlSearchParamsPlugin` and
|
|
69
|
+
* `createNextArrayMapperPaginationPlugin` can be the first to need them on the
|
|
70
|
+
* same component, and neither knows whether the other ran.
|
|
71
|
+
*/
|
|
72
|
+
export declare const hasQuerySyncDeclarations: (body: types.Statement[]) => boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Emitted shape:
|
|
75
|
+
*
|
|
76
|
+
* const __tqQuerySyncRef = useRef({ pending: null, inFlight: 0 })
|
|
77
|
+
* const __tqWriteQueryParam = (key, value) => {
|
|
78
|
+
* const base = __tqQuerySyncRef.current.pending || router.query
|
|
79
|
+
* const next = { ...base }
|
|
80
|
+
* if (value === undefined || value === null || value === '') { delete next[key] }
|
|
81
|
+
* else { next[key] = String(value) }
|
|
82
|
+
* if (next[key] === base[key]) return
|
|
83
|
+
* __tqQuerySyncRef.current.pending = next
|
|
84
|
+
* __tqQuerySyncRef.current.inFlight += 1
|
|
85
|
+
* const settle = () => {
|
|
86
|
+
* __tqQuerySyncRef.current.inFlight -= 1
|
|
87
|
+
* if (__tqQuerySyncRef.current.inFlight <= 0) {
|
|
88
|
+
* __tqQuerySyncRef.current.inFlight = 0
|
|
89
|
+
* __tqQuerySyncRef.current.pending = null
|
|
90
|
+
* }
|
|
91
|
+
* }
|
|
92
|
+
* Promise.resolve(
|
|
93
|
+
* router.replace({ pathname: router.pathname, query: next }, undefined, { shallow: true })
|
|
94
|
+
* ).then(settle, settle)
|
|
95
|
+
* }
|
|
96
|
+
*
|
|
97
|
+
* Notes on the details that are load-bearing:
|
|
98
|
+
*
|
|
99
|
+
* - `next[key] === base[key]` is the ONLY bail. Comparing against the pending
|
|
100
|
+
* query rather than `router.query` is what makes a re-render during an
|
|
101
|
+
* in-flight replace a no-op instead of a duplicate write.
|
|
102
|
+
* - Bracket access, so a URL key that is not a JS identifier (`foo-bar`) works
|
|
103
|
+
* without the callers having to care.
|
|
104
|
+
* - `String(value)` here rather than at each call site — a number page and a
|
|
105
|
+
* string category then serialise identically.
|
|
106
|
+
* - `Promise.resolve(...)` wraps the `replace` because a stubbed router in a
|
|
107
|
+
* test may return a plain value; `.then(settle, settle)` releases the pending
|
|
108
|
+
* query on a rejected (cancelled) navigation too, so one failed replace cannot
|
|
109
|
+
* freeze every later write against a stale base.
|
|
110
|
+
* - `shallow: true` keeps `getStaticProps` out of it: the data is driven by the
|
|
111
|
+
* params memo, not by the URL.
|
|
112
|
+
*/
|
|
113
|
+
export declare const buildQuerySyncDeclarations: () => types.Statement[];
|
|
114
|
+
/**
|
|
115
|
+
* Inserts the declarations once, immediately after `const router = useRouter()`
|
|
116
|
+
* when that is already in the body (it is a plain closure over `router`, so the
|
|
117
|
+
* order only matters for readability — nothing reads it before an effect runs).
|
|
118
|
+
*
|
|
119
|
+
* @returns `true` when it inserted, so the caller can register the `useRef`
|
|
120
|
+
* import dependency only when it is actually needed.
|
|
121
|
+
*/
|
|
122
|
+
export declare const ensureQuerySyncDeclarations: (body: types.Statement[]) => boolean;
|
|
123
|
+
//# sourceMappingURL=url-query-writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-query-writer.d.ts","sourceRoot":"","sources":["../../../src/utils/url-query-writer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,uFAAuF;AACvF,eAAO,MAAM,iBAAiB,qBAAqB,CAAA;AAEnD,wDAAwD;AACxD,eAAO,MAAM,eAAe,wBAAwB,CAAA;AAQpD;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,QAAO,MAAM,gBAC+B,CAAA;AAE9E,sFAAsF;AACtF,eAAO,MAAM,mBAAmB,aACpB,MAAM,aACL,MAAM,UAAU,KAC1B,MAAM,mBAMN,CAAA;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,SAAU,MAAM,SAAS,EAAE,KAAG,OAQhE,CAAA;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,0BAA0B,QAAO,MAAM,SAAS,EAkJ5D,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,SAAU,MAAM,SAAS,EAAE,KAAG,OAkBrE,CAAA"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
+
if (ar || !(i in from)) {
|
|
4
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
+
ar[i] = from[i];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
+
};
|
|
10
|
+
import * as types from '@babel/types';
|
|
11
|
+
/**
|
|
12
|
+
* The ONE place a generated page is allowed to write `router.query` from.
|
|
13
|
+
*
|
|
14
|
+
* ## The defect this exists to make impossible
|
|
15
|
+
*
|
|
16
|
+
* Every URL-bound control used to own a `useEffect` that did
|
|
17
|
+
*
|
|
18
|
+
* const __nextQuery = { ...router.query } // its own snapshot
|
|
19
|
+
* __nextQuery.categoryFilter = 'Rings'
|
|
20
|
+
* router.replace({ pathname, query: __nextQuery }, undefined, { shallow: true })
|
|
21
|
+
*
|
|
22
|
+
* `router.query` is a per-render SHALLOW COPY that Next rebuilds only when the
|
|
23
|
+
* router itself re-renders (`makePublicRouterInstance` — "makes sure query is
|
|
24
|
+
* not stateful"), and `router.replace` updates it asynchronously. So two
|
|
25
|
+
* controls writing in the same flush both spread the SAME pre-change object,
|
|
26
|
+
* and whichever `replace` commits last silently drops the key the other had
|
|
27
|
+
* just added — or resurrects one it had just deleted.
|
|
28
|
+
*
|
|
29
|
+
* That is not a rare interleaving; it is the common one. Changing a filter
|
|
30
|
+
* resets the page, so the filter's write-back and the page's write-back always
|
|
31
|
+
* fire together.
|
|
32
|
+
*
|
|
33
|
+
* ⛔ And the damage does not stop at a wrong URL. Each control also has a
|
|
34
|
+
* READ-BACK effect that pushes `router.query` back into React state. Once a key
|
|
35
|
+
* is erased, the read-back clears that control's state, the write-back
|
|
36
|
+
* re-asserts it, the next landing erases it again — and because each round
|
|
37
|
+
* reads the other side's PRE-flush value, the pair computes
|
|
38
|
+
* `(state, url) -> (url, state)`: a swap. A swap has no fixed point off the
|
|
39
|
+
* diagonal, so it never converges. The observed symptom was a products list
|
|
40
|
+
* that re-fetched and flickered forever after picking a category while on
|
|
41
|
+
* page 5.
|
|
42
|
+
*
|
|
43
|
+
* ## The fix
|
|
44
|
+
*
|
|
45
|
+
* Nobody spreads `router.query` any more. All writers go through one function
|
|
46
|
+
* that merges into `pending` — the last query this component ASKED for —
|
|
47
|
+
* falling back to `router.query` only when nothing is in flight. The second
|
|
48
|
+
* write of a flush therefore builds on the first's payload instead of racing
|
|
49
|
+
* it, no key is ever lost, and with no key lost there is nothing for a
|
|
50
|
+
* read-back to disagree about.
|
|
51
|
+
*
|
|
52
|
+
* `pending` is dropped once every replace it was built from has settled, so an
|
|
53
|
+
* external navigation (a Link, browser back/forward) is never merged into a
|
|
54
|
+
* stale snapshot.
|
|
55
|
+
*
|
|
56
|
+
* @see `buildUrlWriteBackEffect` in `./url-search-param-sync` and
|
|
57
|
+
* `buildPageUrlSyncEffect` in `teleport-plugin-next-data-source` — the two
|
|
58
|
+
* callers, in two different packages, which is why this lives here.
|
|
59
|
+
*/
|
|
60
|
+
/** `useRef` holding `{ pending, inFlight }`. Shared by every writer in a component. */
|
|
61
|
+
export var QUERY_SYNC_REF_ID = '__tqQuerySyncRef';
|
|
62
|
+
/** The write function every URL-bound control calls. */
|
|
63
|
+
export var QUERY_WRITER_ID = '__tqWriteQueryParam';
|
|
64
|
+
var refCurrent = function () {
|
|
65
|
+
return types.memberExpression(types.identifier(QUERY_SYNC_REF_ID), types.identifier('current'));
|
|
66
|
+
};
|
|
67
|
+
var refField = function (field) {
|
|
68
|
+
return types.memberExpression(refCurrent(), types.identifier(field));
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* `__tqQuerySyncRef.current.inFlight === 0` — "the URL is settled".
|
|
72
|
+
*
|
|
73
|
+
* The page-URL effect uses it to gate its ADOPT branch: while a replace this
|
|
74
|
+
* component issued is still landing, `router.query` is a value the page is on
|
|
75
|
+
* its way OUT of, and adopting it would undo the move that is in flight.
|
|
76
|
+
*/
|
|
77
|
+
export var buildQuerySettledExpr = function () {
|
|
78
|
+
return types.binaryExpression('===', refField('inFlight'), types.numericLiteral(0));
|
|
79
|
+
};
|
|
80
|
+
/** `__tqWriteQueryParam('<paramKey>', <valueExpr>)` — `undefined` removes the key. */
|
|
81
|
+
export var buildQueryWriteCall = function (paramKey, valueExpr) {
|
|
82
|
+
return types.expressionStatement(types.callExpression(types.identifier(QUERY_WRITER_ID), [
|
|
83
|
+
types.stringLiteral(paramKey),
|
|
84
|
+
valueExpr,
|
|
85
|
+
]));
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* True when a previous plugin already emitted the declarations.
|
|
89
|
+
*
|
|
90
|
+
* Both `createNextUrlSearchParamsPlugin` and
|
|
91
|
+
* `createNextArrayMapperPaginationPlugin` can be the first to need them on the
|
|
92
|
+
* same component, and neither knows whether the other ran.
|
|
93
|
+
*/
|
|
94
|
+
export var hasQuerySyncDeclarations = function (body) {
|
|
95
|
+
return body.some(function (statement) {
|
|
96
|
+
return statement.type === 'VariableDeclaration' &&
|
|
97
|
+
statement.declarations.some(function (declarator) {
|
|
98
|
+
return declarator.id.type === 'Identifier' && declarator.id.name === QUERY_SYNC_REF_ID;
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Emitted shape:
|
|
104
|
+
*
|
|
105
|
+
* const __tqQuerySyncRef = useRef({ pending: null, inFlight: 0 })
|
|
106
|
+
* const __tqWriteQueryParam = (key, value) => {
|
|
107
|
+
* const base = __tqQuerySyncRef.current.pending || router.query
|
|
108
|
+
* const next = { ...base }
|
|
109
|
+
* if (value === undefined || value === null || value === '') { delete next[key] }
|
|
110
|
+
* else { next[key] = String(value) }
|
|
111
|
+
* if (next[key] === base[key]) return
|
|
112
|
+
* __tqQuerySyncRef.current.pending = next
|
|
113
|
+
* __tqQuerySyncRef.current.inFlight += 1
|
|
114
|
+
* const settle = () => {
|
|
115
|
+
* __tqQuerySyncRef.current.inFlight -= 1
|
|
116
|
+
* if (__tqQuerySyncRef.current.inFlight <= 0) {
|
|
117
|
+
* __tqQuerySyncRef.current.inFlight = 0
|
|
118
|
+
* __tqQuerySyncRef.current.pending = null
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
* Promise.resolve(
|
|
122
|
+
* router.replace({ pathname: router.pathname, query: next }, undefined, { shallow: true })
|
|
123
|
+
* ).then(settle, settle)
|
|
124
|
+
* }
|
|
125
|
+
*
|
|
126
|
+
* Notes on the details that are load-bearing:
|
|
127
|
+
*
|
|
128
|
+
* - `next[key] === base[key]` is the ONLY bail. Comparing against the pending
|
|
129
|
+
* query rather than `router.query` is what makes a re-render during an
|
|
130
|
+
* in-flight replace a no-op instead of a duplicate write.
|
|
131
|
+
* - Bracket access, so a URL key that is not a JS identifier (`foo-bar`) works
|
|
132
|
+
* without the callers having to care.
|
|
133
|
+
* - `String(value)` here rather than at each call site — a number page and a
|
|
134
|
+
* string category then serialise identically.
|
|
135
|
+
* - `Promise.resolve(...)` wraps the `replace` because a stubbed router in a
|
|
136
|
+
* test may return a plain value; `.then(settle, settle)` releases the pending
|
|
137
|
+
* query on a rejected (cancelled) navigation too, so one failed replace cannot
|
|
138
|
+
* freeze every later write against a stale base.
|
|
139
|
+
* - `shallow: true` keeps `getStaticProps` out of it: the data is driven by the
|
|
140
|
+
* params memo, not by the URL.
|
|
141
|
+
*/
|
|
142
|
+
export var buildQuerySyncDeclarations = function () {
|
|
143
|
+
var key = types.identifier('key');
|
|
144
|
+
var value = types.identifier('value');
|
|
145
|
+
var nextAtKey = function () {
|
|
146
|
+
return types.memberExpression(types.identifier('next'), types.cloneNode(key, true), true);
|
|
147
|
+
};
|
|
148
|
+
var settleBody = types.blockStatement([
|
|
149
|
+
types.expressionStatement(types.assignmentExpression('-=', refField('inFlight'), types.numericLiteral(1))),
|
|
150
|
+
types.ifStatement(types.binaryExpression('<=', refField('inFlight'), types.numericLiteral(0)), types.blockStatement([
|
|
151
|
+
types.expressionStatement(types.assignmentExpression('=', refField('inFlight'), types.numericLiteral(0))),
|
|
152
|
+
types.expressionStatement(types.assignmentExpression('=', refField('pending'), types.nullLiteral())),
|
|
153
|
+
])),
|
|
154
|
+
]);
|
|
155
|
+
var writerBody = types.blockStatement([
|
|
156
|
+
// const base = __tqQuerySyncRef.current.pending || router.query
|
|
157
|
+
types.variableDeclaration('const', [
|
|
158
|
+
types.variableDeclarator(types.identifier('base'), types.logicalExpression('||', refField('pending'), types.memberExpression(types.identifier('router'), types.identifier('query')))),
|
|
159
|
+
]),
|
|
160
|
+
// const next = { ...base }
|
|
161
|
+
types.variableDeclaration('const', [
|
|
162
|
+
types.variableDeclarator(types.identifier('next'), types.objectExpression([types.spreadElement(types.identifier('base'))])),
|
|
163
|
+
]),
|
|
164
|
+
types.ifStatement(types.logicalExpression('||', types.logicalExpression('||', types.binaryExpression('===', types.cloneNode(value, true), types.identifier('undefined')), types.binaryExpression('===', types.cloneNode(value, true), types.nullLiteral())), types.binaryExpression('===', types.cloneNode(value, true), types.stringLiteral(''))), types.blockStatement([
|
|
165
|
+
types.expressionStatement(types.unaryExpression('delete', nextAtKey())),
|
|
166
|
+
]), types.blockStatement([
|
|
167
|
+
types.expressionStatement(types.assignmentExpression('=', nextAtKey(), types.callExpression(types.identifier('String'), [types.cloneNode(value, true)]))),
|
|
168
|
+
])),
|
|
169
|
+
// if (next[key] === base[key]) return
|
|
170
|
+
types.ifStatement(types.binaryExpression('===', nextAtKey(), types.memberExpression(types.identifier('base'), types.cloneNode(key, true), true)), types.returnStatement(null)),
|
|
171
|
+
types.expressionStatement(types.assignmentExpression('=', refField('pending'), types.identifier('next'))),
|
|
172
|
+
types.expressionStatement(types.assignmentExpression('+=', refField('inFlight'), types.numericLiteral(1))),
|
|
173
|
+
types.variableDeclaration('const', [
|
|
174
|
+
types.variableDeclarator(types.identifier('settle'), types.arrowFunctionExpression([], settleBody)),
|
|
175
|
+
]),
|
|
176
|
+
types.expressionStatement(types.callExpression(types.memberExpression(types.callExpression(types.memberExpression(types.identifier('Promise'), types.identifier('resolve')), [
|
|
177
|
+
types.callExpression(types.memberExpression(types.identifier('router'), types.identifier('replace')), [
|
|
178
|
+
types.objectExpression([
|
|
179
|
+
types.objectProperty(types.identifier('pathname'), types.memberExpression(types.identifier('router'), types.identifier('pathname'))),
|
|
180
|
+
types.objectProperty(types.identifier('query'), types.identifier('next')),
|
|
181
|
+
]),
|
|
182
|
+
types.identifier('undefined'),
|
|
183
|
+
types.objectExpression([
|
|
184
|
+
types.objectProperty(types.identifier('shallow'), types.booleanLiteral(true)),
|
|
185
|
+
]),
|
|
186
|
+
]),
|
|
187
|
+
]), types.identifier('then')), [types.identifier('settle'), types.identifier('settle')])),
|
|
188
|
+
]);
|
|
189
|
+
return [
|
|
190
|
+
types.variableDeclaration('const', [
|
|
191
|
+
types.variableDeclarator(types.identifier(QUERY_SYNC_REF_ID), types.callExpression(types.identifier('useRef'), [
|
|
192
|
+
types.objectExpression([
|
|
193
|
+
types.objectProperty(types.identifier('pending'), types.nullLiteral()),
|
|
194
|
+
types.objectProperty(types.identifier('inFlight'), types.numericLiteral(0)),
|
|
195
|
+
]),
|
|
196
|
+
])),
|
|
197
|
+
]),
|
|
198
|
+
types.variableDeclaration('const', [
|
|
199
|
+
types.variableDeclarator(types.identifier(QUERY_WRITER_ID), types.arrowFunctionExpression([key, value], writerBody)),
|
|
200
|
+
]),
|
|
201
|
+
];
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Inserts the declarations once, immediately after `const router = useRouter()`
|
|
205
|
+
* when that is already in the body (it is a plain closure over `router`, so the
|
|
206
|
+
* order only matters for readability — nothing reads it before an effect runs).
|
|
207
|
+
*
|
|
208
|
+
* @returns `true` when it inserted, so the caller can register the `useRef`
|
|
209
|
+
* import dependency only when it is actually needed.
|
|
210
|
+
*/
|
|
211
|
+
export var ensureQuerySyncDeclarations = function (body) {
|
|
212
|
+
if (hasQuerySyncDeclarations(body)) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
var routerIndex = body.findIndex(function (statement) {
|
|
216
|
+
return statement.type === 'VariableDeclaration' &&
|
|
217
|
+
statement.declarations.some(function (declarator) {
|
|
218
|
+
var _a;
|
|
219
|
+
return declarator.id.type === 'Identifier' &&
|
|
220
|
+
declarator.id.name === 'router' &&
|
|
221
|
+
((_a = declarator.init) === null || _a === void 0 ? void 0 : _a.type) === 'CallExpression' &&
|
|
222
|
+
declarator.init.callee.type === 'Identifier' &&
|
|
223
|
+
declarator.init.callee.name === 'useRouter';
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
body.splice.apply(body, __spreadArray([routerIndex === -1 ? 0 : routerIndex + 1, 0], buildQuerySyncDeclarations(), false));
|
|
227
|
+
return true;
|
|
228
|
+
};
|
|
229
|
+
//# sourceMappingURL=url-query-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-query-writer.js","sourceRoot":"","sources":["../../../src/utils/url-query-writer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC;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K,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,EAAE,CAAC,GAAK,0BAA0B,EAAE,UAAC;IACzF,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as types from '@babel/types';
|
|
2
|
+
export declare const buildUrlWriteBackEffect: (paramKey: string, valueExpr: types.Expression, depExpr: types.Expression, defaultValueExpr?: types.Expression, adoptedRefName?: string) => types.ExpressionStatement;
|
|
3
|
+
export declare const buildUrlReadBackEffect: (paramKey: string, setterName: string, defaultValueExpr?: types.Expression, adoptedRefName?: string) => types.ExpressionStatement;
|
|
4
|
+
//# sourceMappingURL=url-search-param-sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-search-param-sync.d.ts","sourceRoot":"","sources":["../../../src/utils/url-search-param-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAwGrC,eAAO,MAAM,uBAAuB,aACxB,MAAM,aACL,MAAM,UAAU,WAClB,MAAM,UAAU,qBACN,MAAM,UAAU,mBAClB,MAAM,KACtB,MAAM,mBA0DR,CAAA;AAyCD,eAAO,MAAM,sBAAsB,aACvB,MAAM,cACJ,MAAM,qBACC,MAAM,UAAU,mBAClB,MAAM,KACtB,MAAM,mBAwFR,CAAA"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
+
if (ar || !(i in from)) {
|
|
4
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
+
ar[i] = from[i];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
+
};
|
|
10
|
+
import * as types from '@babel/types';
|
|
11
|
+
import * as URLQueryWriter from './url-query-writer';
|
|
12
|
+
// Shared builders for two-way `<state> ⇄ ?key=` URL search-param syncing.
|
|
13
|
+
//
|
|
14
|
+
// Used by BOTH:
|
|
15
|
+
// • `createNextUrlSearchParamsPlugin` (teleport-project-generator-next) for
|
|
16
|
+
// page/component state defs that declare `urlSearchParamBinding` — e.g.
|
|
17
|
+
// the products-list `selectedCategory` / `sortBy` dropdowns.
|
|
18
|
+
// • `createNextArrayMapperPaginationPlugin` (teleport-plugin-next-data-source)
|
|
19
|
+
// for the products-list search input, whose query lives in a
|
|
20
|
+
// pagination-managed state (`ds_N_searchQuery` / `ds_N_state.debouncedQuery`)
|
|
21
|
+
// rather than a UIDL state def, so it cannot ride the plugin above.
|
|
22
|
+
//
|
|
23
|
+
// Both emit the SAME loop-free read-back / write-back effect shapes, so the
|
|
24
|
+
// builders live here to keep the two call sites byte-identical and the
|
|
25
|
+
// loop-prevention reasoning in one place.
|
|
26
|
+
// Strict JS identifier (Latin only is fine: UIDL URL keys are limited to the
|
|
27
|
+
// subset Next.js supports as a query param key, which the GUI guarantees to
|
|
28
|
+
// be at minimum URL-safe; but the *generated* code must be valid JS, and
|
|
29
|
+
// `__nextQuery.foo-bar` parses as a subtraction). Anything off-pattern goes
|
|
30
|
+
// through bracket notation: `__nextQuery['foo-bar']`.
|
|
31
|
+
var VALID_JS_IDENTIFIER = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
32
|
+
// `object.<paramKey>` for identifier-safe keys, `object['param-key']` otherwise,
|
|
33
|
+
// so the emitted code is always valid JS regardless of the URL key shape.
|
|
34
|
+
var accessKeyOf = function (object, paramKey) {
|
|
35
|
+
if (VALID_JS_IDENTIFIER.test(paramKey)) {
|
|
36
|
+
return types.memberExpression(object, types.identifier(paramKey));
|
|
37
|
+
}
|
|
38
|
+
return types.memberExpression(object, types.stringLiteral(paramKey), true);
|
|
39
|
+
};
|
|
40
|
+
var adoptedRefCurrent = function (refName) {
|
|
41
|
+
return types.memberExpression(types.identifier(refName), types.identifier('current'));
|
|
42
|
+
};
|
|
43
|
+
var routerQueryAccess = function (paramKey) {
|
|
44
|
+
return accessKeyOf(types.memberExpression(types.identifier('router'), types.identifier('query')), paramKey);
|
|
45
|
+
};
|
|
46
|
+
// Clones an expression so it can be slotted into multiple positions of the
|
|
47
|
+
// emitted AST — Babel does not support sharing the same node reference across
|
|
48
|
+
// the tree, and callers pass arbitrary value/dependency expressions.
|
|
49
|
+
var clone = function (expr) {
|
|
50
|
+
return types.cloneNode(expr, /* deep */ true);
|
|
51
|
+
};
|
|
52
|
+
// Builds the state→URL write-back useEffect. Emitted shape (for a value of
|
|
53
|
+
// `selectedCategory` bound to URL key `categoryFilter`):
|
|
54
|
+
//
|
|
55
|
+
// useEffect(() => {
|
|
56
|
+
// if (typeof window === 'undefined') return
|
|
57
|
+
// if (!router.isReady) return
|
|
58
|
+
// __tqWriteQueryParam(
|
|
59
|
+
// 'categoryFilter',
|
|
60
|
+
// selectedCategory === '' || selectedCategory == null ? undefined : selectedCategory
|
|
61
|
+
// )
|
|
62
|
+
// }, [selectedCategory, router.isReady])
|
|
63
|
+
//
|
|
64
|
+
// `valueExpr` is the expression read each render and pushed to the URL (a bare
|
|
65
|
+
// state identifier for dropdowns, `ds_N_state.debouncedQuery` for the search
|
|
66
|
+
// input). `depExpr` is the effect dependency that re-triggers the write-back
|
|
67
|
+
// when that value changes — usually the same expression as `valueExpr`.
|
|
68
|
+
//
|
|
69
|
+
// `defaultValueExpr` (optional) is the state's default value. When supplied
|
|
70
|
+
// (only for bindings whose default is a non-empty value, e.g. the sort
|
|
71
|
+
// dropdown's `name-asc`), the current value being EQUAL TO THE DEFAULT also
|
|
72
|
+
// deletes the key — so the canonical/default view keeps a clean, param-free
|
|
73
|
+
// URL instead of stickily writing `?sortBy=name-asc` on first load. This is
|
|
74
|
+
// the write-back half of the default-aware pairing that keeps the URL⇄state
|
|
75
|
+
// sync loop-free: the read-back below resolves a missing key back to the same
|
|
76
|
+
// default, so the two never disagree.
|
|
77
|
+
//
|
|
78
|
+
// Notes:
|
|
79
|
+
// 1. `router.isReady` gate: on the very first SSG render `router.query` is
|
|
80
|
+
// empty, so without this gate any value initialized from
|
|
81
|
+
// `window.location.search` would immediately replace itself with the same
|
|
82
|
+
// value, racing with Next's own hydration. `router.isReady` is also in the
|
|
83
|
+
// deps array — once it flips to true, the effect re-runs with the
|
|
84
|
+
// now-hydrated query and decides correctly whether to write.
|
|
85
|
+
// 2. ⛔ THE EFFECT NO LONGER BUILDS THE NEXT QUERY ITSELF. It hands its single
|
|
86
|
+
// key to `URLQueryWriter`, which merges into the last query the component
|
|
87
|
+
// ASKED for rather than the one Next has got round to rendering. Two controls
|
|
88
|
+
// writing in the same flush — which is guaranteed, because changing a filter
|
|
89
|
+
// resets the page — used to spread the same stale `router.query` and erase
|
|
90
|
+
// each other's keys; the read-backs then fought over the wreckage forever.
|
|
91
|
+
// `url-query-writer.ts` has the full account.
|
|
92
|
+
// 3. Because no key can be clobbered any more, `router.query` is NOT a
|
|
93
|
+
// dependency here. It used to be, as a way to RE-ASSERT a key some other
|
|
94
|
+
// writer had just dropped — which is exactly the feedback edge that turned a
|
|
95
|
+
// one-shot loss into a non-terminating swap. Fixing the write at its source
|
|
96
|
+
// means there is nothing to re-assert.
|
|
97
|
+
// 4. Empty / null value deletes the key entirely so the URL never keeps a
|
|
98
|
+
// sticky `?key=` empty param. The writer treats `undefined` as "remove".
|
|
99
|
+
// 5. `adoptedRefName` (optional) names a `useRef(false)` the paired read-back
|
|
100
|
+
// flips once it has adopted the URL value; until then the write-back stays
|
|
101
|
+
// silent. For a state seeded with its DEFAULT rather than from the URL
|
|
102
|
+
// (`urlSearchParamBinding.hydrateAfterMount`): on the first ready render
|
|
103
|
+
// the state still holds the default, and a write-back running before the
|
|
104
|
+
// read-back would push that default onto the URL — deleting the very key
|
|
105
|
+
// the read-back was about to adopt — after which the two chase each other
|
|
106
|
+
// forever (`/products?view=list` → `/products` → …).
|
|
107
|
+
export var buildUrlWriteBackEffect = function (paramKey, valueExpr, depExpr, defaultValueExpr, adoptedRefName) {
|
|
108
|
+
// value === '' || value == null [|| value === <default>]
|
|
109
|
+
var deleteCondition = types.logicalExpression('||', types.binaryExpression('===', clone(valueExpr), types.stringLiteral('')), types.binaryExpression('==', clone(valueExpr), types.nullLiteral()));
|
|
110
|
+
if (defaultValueExpr) {
|
|
111
|
+
deleteCondition = types.logicalExpression('||', deleteCondition, types.binaryExpression('===', clone(valueExpr), clone(defaultValueExpr)));
|
|
112
|
+
}
|
|
113
|
+
var effectBody = types.blockStatement(__spreadArray(__spreadArray([
|
|
114
|
+
// if (typeof window === 'undefined') return
|
|
115
|
+
types.ifStatement(types.binaryExpression('===', types.unaryExpression('typeof', types.identifier('window')), types.stringLiteral('undefined')), types.returnStatement(null)),
|
|
116
|
+
// if (!router.isReady) return
|
|
117
|
+
types.ifStatement(types.unaryExpression('!', types.memberExpression(types.identifier('router'), types.identifier('isReady'))), types.returnStatement(null))
|
|
118
|
+
], (adoptedRefName
|
|
119
|
+
? [
|
|
120
|
+
types.ifStatement(types.unaryExpression('!', adoptedRefCurrent(adoptedRefName)), types.returnStatement(null)),
|
|
121
|
+
]
|
|
122
|
+
: []), true), [
|
|
123
|
+
// __tqWriteQueryParam('<key>', <deleteCondition> ? undefined : <value>)
|
|
124
|
+
URLQueryWriter.buildQueryWriteCall(paramKey, types.conditionalExpression(deleteCondition, types.identifier('undefined'), clone(valueExpr))),
|
|
125
|
+
], false));
|
|
126
|
+
return types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
|
|
127
|
+
types.arrowFunctionExpression([], effectBody),
|
|
128
|
+
types.arrayExpression([
|
|
129
|
+
clone(depExpr),
|
|
130
|
+
types.memberExpression(types.identifier('router'), types.identifier('isReady')),
|
|
131
|
+
]),
|
|
132
|
+
]));
|
|
133
|
+
};
|
|
134
|
+
// Builds the URL→state read-back useEffect. Emitted shape (for setter
|
|
135
|
+
// `setSelectedCategory` bound to URL key `categoryFilter`):
|
|
136
|
+
//
|
|
137
|
+
// useEffect(() => {
|
|
138
|
+
// if (!router.isReady) return
|
|
139
|
+
// const __urlValue = router.query.categoryFilter
|
|
140
|
+
// const __nextValue =
|
|
141
|
+
// typeof __urlValue === 'string' ? __urlValue : Array.isArray(__urlValue) ? (__urlValue[0] || '') : ''
|
|
142
|
+
// setSelectedCategory((prev) => (prev === __nextValue ? prev : __nextValue))
|
|
143
|
+
// }, [router.query.categoryFilter, router.isReady])
|
|
144
|
+
//
|
|
145
|
+
// Why pair this with the write-back effect:
|
|
146
|
+
// - On `<Link>` / `router.push` shallow navigations that land on the same path
|
|
147
|
+
// with a different query (or browser back/forward, which can change the query
|
|
148
|
+
// without remounting the page), `router.query` updates but the state hook does
|
|
149
|
+
// not. Without this effect, the control would be stuck on whatever the user
|
|
150
|
+
// last picked even though the URL has moved on.
|
|
151
|
+
// - The functional `setState((prev) => prev === next ? prev : next)` form
|
|
152
|
+
// guarantees React bails out when the URL value matches state, which prevents
|
|
153
|
+
// an infinite write-back ↔ read-back loop: when the user picks a new value,
|
|
154
|
+
// state→URL fires once, URL→state observes the matching value and returns
|
|
155
|
+
// `prev`, so React does not re-render or fire any deps.
|
|
156
|
+
// - `router.query[key]` can be either `string` (single value) or `string[]`
|
|
157
|
+
// (duplicate keys) per Next.js's typings; the helper normalizes both to a
|
|
158
|
+
// string before comparing, defaulting to `''` for the missing-key case so the
|
|
159
|
+
// comparison aligns with the write-back's `value === ''` empty-check.
|
|
160
|
+
//
|
|
161
|
+
// `defaultValueExpr` (optional) is the state's default value. When supplied
|
|
162
|
+
// (bindings with a non-empty default such as the sort dropdown's `name-asc`),
|
|
163
|
+
// an ABSENT or EMPTY URL value resolves to the default rather than `''` — via a
|
|
164
|
+
// trailing `(<normalized>) || <default>`. This is what makes the default sort
|
|
165
|
+
// "stick" on first load: without it the read-back would clobber the default
|
|
166
|
+
// state (`name-asc`) with `''` the instant the router hydrates with no `?sortBy`
|
|
167
|
+
// key, forcing an extra unsorted fetch and losing the ordering. It also keeps
|
|
168
|
+
// browser back/forward to the param-free URL restoring the default view.
|
|
169
|
+
// Omitting it reproduces the pre-default `''` fallback byte-for-byte.
|
|
170
|
+
//
|
|
171
|
+
// `adoptedRefName` (optional): the flag the paired write-back waits on — set
|
|
172
|
+
// once the URL value has been handed to the state. See the write-back's note 5.
|
|
173
|
+
export var buildUrlReadBackEffect = function (paramKey, setterName, defaultValueExpr, adoptedRefName) {
|
|
174
|
+
var normalizeArg = types.conditionalExpression(
|
|
175
|
+
// typeof __urlValue === 'string' ? __urlValue
|
|
176
|
+
types.binaryExpression('===', types.unaryExpression('typeof', types.identifier('__urlValue')), types.stringLiteral('string')), types.identifier('__urlValue'), types.conditionalExpression(
|
|
177
|
+
// Array.isArray(__urlValue) ? (__urlValue[0] || '') : ''
|
|
178
|
+
types.callExpression(types.memberExpression(types.identifier('Array'), types.identifier('isArray')), [types.identifier('__urlValue')]), types.logicalExpression('||', types.memberExpression(types.identifier('__urlValue'), types.numericLiteral(0), true), types.stringLiteral('')), types.stringLiteral('')));
|
|
179
|
+
// With a default, an absent/empty normalized value (falsy `''`) falls through
|
|
180
|
+
// to the default: `(<normalized>) || <default>`. Without one, the bare
|
|
181
|
+
// normalized expression is emitted unchanged.
|
|
182
|
+
var nextValueExpr = defaultValueExpr
|
|
183
|
+
? types.logicalExpression('||', normalizeArg, clone(defaultValueExpr))
|
|
184
|
+
: normalizeArg;
|
|
185
|
+
var effectBody = types.blockStatement(__spreadArray([
|
|
186
|
+
// if (!router.isReady) return
|
|
187
|
+
types.ifStatement(types.unaryExpression('!', types.memberExpression(types.identifier('router'), types.identifier('isReady'))), types.returnStatement(null)),
|
|
188
|
+
// const __urlValue = router.query.<paramKey>
|
|
189
|
+
types.variableDeclaration('const', [
|
|
190
|
+
types.variableDeclarator(types.identifier('__urlValue'), routerQueryAccess(paramKey)),
|
|
191
|
+
]),
|
|
192
|
+
// const __nextValue = (normalized) [|| <default>]
|
|
193
|
+
types.variableDeclaration('const', [
|
|
194
|
+
types.variableDeclarator(types.identifier('__nextValue'), nextValueExpr),
|
|
195
|
+
]),
|
|
196
|
+
// setState((prev) => prev === __nextValue ? prev : __nextValue)
|
|
197
|
+
types.expressionStatement(types.callExpression(types.identifier(setterName), [
|
|
198
|
+
types.arrowFunctionExpression([types.identifier('prev')], types.conditionalExpression(types.binaryExpression('===', types.identifier('prev'), types.identifier('__nextValue')), types.identifier('prev'), types.identifier('__nextValue'))),
|
|
199
|
+
]))
|
|
200
|
+
], (adoptedRefName
|
|
201
|
+
? [
|
|
202
|
+
types.expressionStatement(types.assignmentExpression('=', adoptedRefCurrent(adoptedRefName), types.booleanLiteral(true))),
|
|
203
|
+
]
|
|
204
|
+
: []), true));
|
|
205
|
+
return types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
|
|
206
|
+
types.arrowFunctionExpression([], effectBody),
|
|
207
|
+
types.arrayExpression([
|
|
208
|
+
routerQueryAccess(paramKey),
|
|
209
|
+
types.memberExpression(types.identifier('router'), types.identifier('isReady')),
|
|
210
|
+
]),
|
|
211
|
+
]));
|
|
212
|
+
};
|
|
213
|
+
//# sourceMappingURL=url-search-param-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-search-param-sync.js","sourceRoot":"","sources":["../../../src/utils/url-search-param-sync.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,cAAc,MAAM,oBAAoB,CAAA;AAEpD,0EAA0E;AAC1E,EAAE;AACF,gBAAgB;AAChB,8EAA8E;AAC9E,4EAA4E;AAC5E,iEAAiE;AACjE,iFAAiF;AACjF,iEAAiE;AACjE,kFAAkF;AAClF,wEAAwE;AACxE,EAAE;AACF,4EAA4E;AAC5E,uEAAuE;AACvE,0CAA0C;AAE1C,6EAA6E;AAC7E,4EAA4E;AAC5E,yEAAyE;AACzE,4EAA4E;AAC5E,sDAAsD;AAC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