hipstersmoothie / react-window-splitter

react-resizable-grid-panels
https://react-window-splitter-six.vercel.app
50 stars 2 forks source link

Restoring snapshots from cookie is causing errors on the server #39

Open matt-aitken opened 3 months ago

matt-aitken commented 3 months ago

This error is thrown:

TypeError: e.value.toNumber is not a function
    at ee (chunk-ZSHBCN6K.js:3:23605)
    at chunk-ZSHBCN6K.js:3:24762
    at Array.map (<anonymous>)
    at $r (chunk-ZSHBCN6K.js:3:24056)
    at chunk-ZSHBCN6K.js:3:39821
    at c (chunk-ZSHBCN6K.js:1:808)
    at chunk-ZSHBCN6K.js:1:1014
    at Object.useSyncExternalStore (chunk-LYHQCUWL.js:6:26399)
    at r.useSyncExternalStore (chunk-FTYKMG53.js:1:6374)
    at Os.useSyncExternalStoreWithSelector (chunk-ZSHBCN6K.js:1:1083)

Which seems to be from this code: https://github.com/hipstersmoothie/react-window-splitter/blob/d94688575b3b7b8ddea5df0a322606db62d46e27/packages/state/src/index.ts#L756

This is using this snapshot that is loaded from a cookie. I got this by going to the Inspector in Chrome and ticking "Show URL decoded". It looks to be in the same format as your test case ones:

{
  "status": "active",
  "value": "idle",
  "historyValue": {},
  "context": {
    "size": { "width": 0, "height": 0 },
    "items": [
      {
        "type": "panel",
        "min": { "type": "pixel", "value": "50" },
        "max": "1fr",
        "collapsible": false,
        "collapsedSize": { "type": "pixel", "value": "0" },
        "onCollapseChange": {},
        "onResize": {},
        "collapseIsControlled": false,
        "id": "tree",
        "default": { "type": "percent", "value": "0.5" },
        "currentValue": { "type": "pixel", "value": "-1" }
      },
      {
        "type": "handle",
        "size": { "type": "pixel", "value": "3" },
        "id": "tree-handle"
      },
      {
        "type": "panel",
        "min": { "type": "pixel", "value": "50" },
        "max": "1fr",
        "collapsible": false,
        "collapsedSize": { "type": "pixel", "value": "0" },
        "onCollapseChange": {},
        "onResize": {},
        "collapseIsControlled": false,
        "id": "timeline",
        "default": { "type": "percent", "value": "0.5" },
        "currentValue": { "type": "pixel", "value": "-1" }
      }
    ],
    "orientation": "horizontal",
    "dragOvershoot": "0",
    "groupId": "panel-run-tree",
    "autosaveStrategy": "cookie"
  },
  "children": {}
}

I think you might have the same error in the docs page for persistence, it's currently broken: https://react-window-splitter-six.vercel.app/docs/examples/persistance

hipstersmoothie commented 2 months ago

Our docs site seems to be hitting a different issue

hipstersmoothie commented 2 months ago

my gut says this is something like an incompatible breaking changes in the format

hipstersmoothie commented 2 months ago

If you delete the cookie does it persist?