Skip to content

Commit

Permalink
fix: use client version of react-dom
Browse files Browse the repository at this point in the history
Closes: #22
  • Loading branch information
targos authored and lpatiny committed Mar 22, 2024
1 parent b3ea22e commit 758b063
Show file tree
Hide file tree
Showing 8 changed files with 602 additions and 594 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lactame.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Get package name
run: echo "PACKAGE_NAME=$(jq .name package.json | tr -d '"')" >> $GITHUB_ENV
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/typedoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ on:
types: [published]

env:
NODE_VERSION: 16.x
NODE_VERSION: 20.x
ENTRY_FILE: 'src/index.ts'

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"eslint": "^8.57.0",
"eslint-config-cheminfo-react": "^10.1.0",
"eslint-config-cheminfo-typescript": "^12.2.0",
"jsdom": "^24.0.0",
"prettier": "^3.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
1,154 changes: 577 additions & 577 deletions src/__tests__/__snapshots__/molecule.test.tsx.snap

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/components/SVGBoxesTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function SVGBoxesTree(props) {
}
svgSize.width = Math.max(...width);

const svg = (
return (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox={`0 0 ${svgSize.width} ${svgSize.height}`}
Expand All @@ -34,6 +34,4 @@ export function SVGBoxesTree(props) {
{arrows}
</svg>
);

return svg;
}
8 changes: 5 additions & 3 deletions src/data/getBoxes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export function getBoxes(nodes) {
}

function appendBoxes(nodes, boxes) {
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
for (const node of nodes) {
boxes.push(
<g key={i} transform={`translate(${node.position.x} ${node.position.y})`}>
<g
key={boxes.length}
transform={`translate(${node.position.x} ${node.position.y})`}
>
{node.element}
</g>,
);
Expand Down
14 changes: 9 additions & 5 deletions src/render.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { renderToStaticMarkup } from 'react-dom/server';
import { flushSync } from 'react-dom';
import { createRoot } from 'react-dom/client';

import { SVGBoxesTree } from './components/SVGBoxesTree';

export function render(tree, options) {
const result = renderToStaticMarkup(
<SVGBoxesTree tree={tree} {...options} />,
);
return result;
const element = <SVGBoxesTree tree={tree} {...options} />;
const div = document.createElement('div');
const root = createRoot(div);
flushSync(() => {
root.render(element);
});
return div.innerHTML;
}
5 changes: 4 additions & 1 deletion vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { defineConfig } from 'vite'
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'

export default defineConfig({
plugins: [react()],
test: {
environment: 'jsdom'
}
});

0 comments on commit 758b063

Please sign in to comment.