-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #355 from preactjs/react-adapter-fixes
Fix React adapter in SSR and when rerendering
- Loading branch information
Showing
13 changed files
with
821 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@preact/signals-react": patch | ||
--- | ||
|
||
Fix React adapter in SSR and when rerendering |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { mountSignalsTests } from "../shared/mounting"; | ||
import { | ||
Root, | ||
createRoot, | ||
act, | ||
getConsoleErrorSpy, | ||
checkConsoleErrorLogs, | ||
} from "../shared/utils"; | ||
|
||
describe("@preact/signals-react mounting", () => { | ||
let scratch: HTMLDivElement; | ||
let root: Root; | ||
|
||
async function render(element: JSX.Element | null): Promise<string> { | ||
await act(() => root.render(element)); | ||
return scratch.innerHTML; | ||
} | ||
|
||
beforeEach(async () => { | ||
scratch = document.createElement("div"); | ||
document.body.appendChild(scratch); | ||
root = await createRoot(scratch); | ||
getConsoleErrorSpy().resetHistory(); | ||
}); | ||
|
||
afterEach(async () => { | ||
scratch.remove(); | ||
checkConsoleErrorLogs(); | ||
}); | ||
|
||
mountSignalsTests(render); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { signal, useSignalEffect } from "@preact/signals-react"; | ||
import { expect } from "chai"; | ||
import { createElement } from "react"; | ||
import { renderToStaticMarkup } from "react-dom/server"; | ||
import sinon from "sinon"; | ||
import { mountSignalsTests } from "../shared/mounting"; | ||
|
||
describe("renderToStaticMarkup", () => { | ||
mountSignalsTests(renderToStaticMarkup); | ||
|
||
it("should not invoke useSignalEffect", async () => { | ||
const spy = sinon.spy(); | ||
const sig = signal("foo"); | ||
|
||
function App() { | ||
useSignalEffect(() => spy(sig.value)); | ||
return <p>{sig.value}</p>; | ||
} | ||
|
||
const html = await renderToStaticMarkup(<App />); | ||
expect(html).to.equal("<p>foo</p>"); | ||
expect(spy.called).to.be.false; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// import register from "@babel/register"; | ||
const register = require("@babel/register").default; | ||
|
||
const coverage = String(process.env.COVERAGE) === "true"; | ||
|
||
// @babel/register doesn't hook into the experimental NodeJS ESM loader API so | ||
// we need all test files to run as CommonJS modules in Node | ||
const env = [ | ||
"@babel/preset-env", | ||
{ | ||
targets: { | ||
node: "current", | ||
}, | ||
loose: true, | ||
modules: "commonjs", | ||
}, | ||
]; | ||
|
||
const jsx = [ | ||
"@babel/preset-react", | ||
{ | ||
runtime: "classic", | ||
pragma: "createElement", | ||
pragmaFrag: "Fragment", | ||
}, | ||
]; | ||
|
||
const ts = [ | ||
"@babel/preset-typescript", | ||
{ | ||
jsxPragma: "createElement", | ||
jsxPragmaFrag: "Fragment", | ||
}, | ||
]; | ||
|
||
register({ | ||
extensions: [".js", ".mjs", ".ts", ".tsx", ".mts", ".mtsx"], | ||
cache: true, | ||
|
||
sourceMaps: "inline", | ||
presets: [ts, jsx, env], | ||
plugins: [ | ||
coverage && [ | ||
"istanbul", | ||
{ | ||
// TODO: Currently NodeJS tests always run against dist files. Should we | ||
// change this? | ||
// include: minify ? "**/dist/**/*.js" : "**/src/**/*.{js,jsx,ts,tsx}", | ||
}, | ||
], | ||
].filter(Boolean), | ||
}); |
Oops, something went wrong.