Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ten-baboons-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rescript-relay-router": patch
---

Make rescript-relay-router compatible with rescript v12
4 changes: 2 additions & 2 deletions packages/rescript-relay-router/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default [
format: "esm",
name: "RescriptRelayVitePlugin",
},
plugins: [resolve({ resolveOnly: [/^@rescript\/.*$/] })],
plugins: [resolve({ resolveOnly: ["@rescript/core", "rescript"] })],
external: ["fsevents"],
},
{
Expand All @@ -28,7 +28,7 @@ export default [
format: "esm",
name: "RescriptRelayServerVitePlugin",
},
plugins: [resolve({ resolveOnly: [/^@rescript\/.*$/] })],
plugins: [resolve({ resolveOnly: ["@rescript/core", "rescript"] })],
external: ["fsevents", "vite"],
},
];
67 changes: 37 additions & 30 deletions packages/rescript-relay-router/src/RelayRouter__Internal.res
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let useSetQueryParams = (
}

setQueryParamsFn({
applyQueryParams: applyQueryParams(~newParams, ...),
applyQueryParams: queryParams => applyQueryParams(~newParams, queryParams),
currentSearch: search,
navigationMode_,
removeNotControlledParams,
Expand Down Expand Up @@ -116,34 +116,42 @@ external matchPath: (string, string) => option<pathMatch> = "matchPath"
external matchPathWithOptions: ({"path": string, "end": bool}, string) => option<pathMatch> =
"matchPath"

// This will extract all dispose functions from anything you feed it.
let extractDisposables = %raw(`function extractDisposables_(s, disposables = [], seen = new Set()) {
if (s == null || seen.has(s)) {
return disposables;
}

seen.add(s);

if (Array.isArray(s)) {
s.forEach(function (o) {
extractDisposables_(o, disposables, seen);
});
return disposables;
}
type prepared
external toObject: Type.Classify.object => {..} = "%identity"
external objectToPreparedArrayUnsafe: Type.Classify.object => array<prepared> = "%identity"

if (typeof s === "object") {
if (s.hasOwnProperty("dispose") && typeof s.dispose === "function") {
disposables.push(s.dispose);
// This will extract all dispose functions from anything you feed it.
let extractDisposables = prepared => {
let rec aux = (s, disposables, seen) => {
switch Type.Classify.classify(s) {
| Object(object) =>
if !(seen->Set.has(s)) {
seen->Set.add(s)
if Array.isArray(object) {
let array = objectToPreparedArrayUnsafe(object)
array->Array.forEach(o => aux(o, disposables, seen))
} else {
let object = toObject(object)
if (
object->Object.hasOwnProperty("dispose") && Type.typeof(object["dispose"]) === #function
) {
disposables->Array.push(object["dispose"])
}
object
->Object.keysToArray
->Array.forEach(key => {
let o = object->Object.get(key)
o->Option.forEach(o => aux(o, disposables, seen))
})
}
}
| _ => ()
}

Object.keys(s).forEach(function (key) {
var o = s[key];
extractDisposables_(o, disposables, seen);
});
}

return disposables;
}`)
let disposables = []
aux(prepared, disposables, Set.make())
disposables
}

type requestIdleCallbackId

Expand All @@ -154,10 +162,9 @@ external requestIdleCallback: (callback, option<{"timeout": int}>) => requestIdl
@val
external cancelIdleCallback: requestIdleCallbackId => unit = "window.cancelIdleCallback"

let supportsRequestIdleCallback: bool = if RelaySSRUtils.ssr {
false
} else {
%raw(`window != null && window.requestIdleCallback != null`)
let supportsRequestIdleCallback: bool = switch (RelaySSRUtils.ssr, globalThis["window"]) {
| (true, _) | (_, None) => false
| (_, Some(window)) => Type.typeof(window["requestIdleCallback"]) === #function
}

let runCallback = (cb: callback, timeout) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ external matchPath: (string, string) => option<pathMatch> = "matchPath"
external matchPathWithOptions: ({"path": string, "end": bool}, string) => option<pathMatch> =
"matchPath"

let extractDisposables: 'any => array<unit => unit>
type prepared
let extractDisposables: prepared => array<unit => unit>

let runAtPriority: (
RelayRouter__Types.callback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exception Route_loading_failed(string)

type prepareProps
type prepared
type prepared = RelayRouter.Internal.prepared
type renderProps

// This works because the render props for a route is always the prepared props
Expand Down