Skip to content

Commit

Permalink
cumulative wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
nitedani committed Jun 27, 2024
1 parent f2b1112 commit 460cba2
Show file tree
Hide file tree
Showing 5 changed files with 758 additions and 1,023 deletions.
2 changes: 1 addition & 1 deletion examples/zustand/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "^5.3.3",
"vike": "^0.4.151",
"vike": "^0.4.168",
"vike-react": "workspace:*",
"vike-react-zustand": "workspace:*",
"vite": "^5.0.10",
Expand Down
10 changes: 5 additions & 5 deletions packages/vike-react-zustand/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"exports": {
".": "./dist/index.js",
"./config": "./dist/renderer/+config.js",
"./renderer/VikeReactZustandWrapper": "./dist/renderer/VikeReactZustandWrapper.js",
"./renderer/Wrapper": "./dist/renderer/Wrapper.js",
"./plugin": "./dist/plugin.js"
},
"scripts": {
Expand Down Expand Up @@ -36,8 +36,8 @@
"react-dom": "^18.2.0",
"rimraf": "^5.0.5",
"typescript": "^5.3.3",
"vike": "^0.4.151",
"vike-react": "^0.3.8",
"vike": "^0.4.160",
"vike-react": "^0.4.4",
"vite": "^5.0.10",
"zustand": "^4.4.7"
},
Expand All @@ -49,8 +49,8 @@
"config": [
"dist/renderer/+config.d.ts"
],
"renderer/VikeReactZustandWrapper": [
"dist/renderer/VikeReactZustandWrapper.d.ts"
"renderer/Wrapper": [
"dist/renderer/Wrapper.d.ts"
],
"plugin": [
"dist/plugin.d.ts"
Expand Down
2 changes: 1 addition & 1 deletion packages/vike-react-zustand/src/renderer/+config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
// @ts-ignore Remove this ts-ignore once Vike's new version is released.
name: 'vike-react-zustand',
VikeReactZustandWrapper: 'import:vike-react-zustand/renderer/VikeReactZustandWrapper:default',
Wrapper: 'import:vike-react-zustand/renderer/Wrapper:default',
passToClient: ['_vikeReactZustand']
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { cloneDeep, mergeWith } from 'lodash-es'
import React, { ReactNode, useMemo } from 'react'
import type { PageContext } from 'vike/types'
import { getReactStoreContext, initializers_get, setPageContext } from './context.js'
import { assert, removeFunctionsAndUndefined } from '../utils.js'
import { usePageContext } from 'vike-react/usePageContext'
import { create as createZustand } from 'zustand'
import { devtools } from 'zustand/middleware'
import { cloneDeep, mergeWith } from 'lodash-es'
import { assert, removeFunctionsAndUndefined } from '../utils.js'
import { getReactStoreContext, initializers_get, setPageContext } from './context.js'

// Trick to make import.meta.env.SSR work direclty on Node.js (without Vite)
// @ts-expect-error
import.meta.env ??= { SSR: true }

type VikeReactZustandWrapperProps = {
pageContext: PageContext
children: ReactNode
}

export default function VikeReactZustandWrapper({ pageContext, children }: VikeReactZustandWrapperProps) {
export default function Wrapper({ children }: { children: ReactNode }) {
const pageContext = usePageContext()
const initializers = initializers_get()
const stores = useMemo(
() =>
Expand Down
Loading

0 comments on commit 460cba2

Please sign in to comment.