Skip to content

Commit

Permalink
fix: wait for hydration via react effect
Browse files Browse the repository at this point in the history
  • Loading branch information
katywings committed Jun 27, 2024
1 parent 8600f15 commit 173663b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions test/fs-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ testDevAndProd("fs-router", ({ createFixture }) => {
test("hydrates", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/", true);
await app.page.waitForSelector('[data-ready]')

expect(await app.getHtml("[data-test-id=title]")).toBe(
prettyHtml(`<h1 data-test-id="title">Vinxi Home</h1>`),
Expand All @@ -76,6 +77,7 @@ testDevAndProd("fs-router", ({ createFixture }) => {

await app.clickElement("a[href='/hello']");
await app.waitForURL("/hello");
await app.page.waitForSelector('[data-ready]');
await new Promise((r) => setTimeout(r, 1000));

expect(await app.getHtml("[data-test-id=title]")).toBe(
Expand All @@ -87,6 +89,7 @@ testDevAndProd("fs-router", ({ createFixture }) => {

await app.clickElement("a[href='/']");
await app.waitForURL("/");
await app.page.waitForSelector('[data-ready]')
await new Promise((r) => setTimeout(r, 2000));

expect(await app.getHtml("[data-test-id=title]")).toBe(
Expand Down
6 changes: 4 additions & 2 deletions test/templates/react-ssr-fs/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from "react";
import React, { useEffect } from "react";

import { Counter } from "./Counter";
import "./style.css";

export default function App({ assets, children }) {
const [count, setCount] = React.useState(0);
const [ready, setReady] = React.useState(false);
useEffect(() => setReady(true), [])
return (
<html lang="en">
<html lang="en" data-ready={ready}>
<head>
<link rel="icon" href="/favicon.ico" />
{assets}
Expand Down

0 comments on commit 173663b

Please sign in to comment.