Fix route hydration with ssg without early chunk commit (#4654)
* Fix route hydration with ssg without early chunk commit * fix clobbered port for fullstack spread (merge conflict) * wait for hydration --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
d8a6c265ab
commit
d0c4376790
3 files changed
+24
-15
No files matched your search
@@ -33,11 +33,10 @@ pub(crate) fn finalize_route() {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let entry = entry
|
let Some(entry) = entry.entry.borrow_mut().take() else {
|
||||||
.entry
|
// If it was already taken, then just return. This can happen if commit_initial_chunk is called twice
|
||||||
.borrow_mut()
|
return;
|
||||||
.take()
|
};
|
||||||
.expect("Failed to get initial route from hydration context");
|
|
||||||
|
|
||||||
if cfg!(feature = "server") {
|
if cfg!(feature = "server") {
|
||||||
let history = history();
|
let history = history();
|
||||||
@@ -45,12 +44,10 @@ pub(crate) fn finalize_route() {
|
|||||||
entry.insert(&route, std::panic::Location::caller());
|
entry.insert(&route, std::panic::Location::caller());
|
||||||
provide_context(ResolvedRouteContext { route });
|
provide_context(ResolvedRouteContext { route });
|
||||||
} else if cfg!(feature = "web") {
|
} else if cfg!(feature = "web") {
|
||||||
let initial_route = entry
|
let route = entry
|
||||||
.get()
|
.get()
|
||||||
.expect("Failed to get initial route from hydration context");
|
.expect("Failed to get initial route from hydration context");
|
||||||
provide_context(ResolvedRouteContext {
|
provide_context(ResolvedRouteContext { route });
|
||||||
route: initial_route,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,10 +83,19 @@ impl<H> FullstackHistory<H> {
|
|||||||
where
|
where
|
||||||
H: History,
|
H: History,
|
||||||
{
|
{
|
||||||
match try_consume_context::<ResolvedRouteContext>() {
|
// If the route hydration entry is set, use that instead of the histories current route
|
||||||
Some(context) => context.route,
|
// for better hydration behavior. The client may be rendering from a ssg route that was
|
||||||
None => self.history.current_route(),
|
// rendered at a different url
|
||||||
|
if let Some(entry) = try_consume_context::<RouteEntry>() {
|
||||||
|
let entry = entry.entry.borrow();
|
||||||
|
if let Some(entry) = &*entry {
|
||||||
|
if let Ok(initial_route) = entry.get() {
|
||||||
|
return initial_route;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.history.current_route()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,14 @@
|
|||||||
const { test, expect } = require("@playwright/test");
|
const { test, expect } = require("@playwright/test");
|
||||||
|
|
||||||
test("spread attributes hydrate", async ({ page }) => {
|
test("spread attributes hydrate", async ({ page }) => {
|
||||||
await page.goto("http://localhost:7979");
|
await page.goto("http://localhost:7980");
|
||||||
|
|
||||||
|
await page.waitForTimeout(2000); // wait for hydration
|
||||||
|
|
||||||
// Expect the page to contain the button
|
// Expect the page to contain the button
|
||||||
const counter = page.locator("#counter");
|
const counter = page.locator("#counter");
|
||||||
await expect(counter).toHaveText("Count: 0");
|
await expect(counter).toHaveText("Count: 0");
|
||||||
|
|
||||||
// Clicking on the button should increment the count
|
// Clicking on the button should increment the count
|
||||||
await counter.click();
|
await counter.click();
|
||||||
await expect(counter).toHaveText("Count: 1");
|
await expect(counter).toHaveText("Count: 1");
|
||||||
|
|||||||
@@ -111,8 +111,8 @@ module.exports = defineConfig({
|
|||||||
{
|
{
|
||||||
cwd: path.join(process.cwd(), "fullstack-spread"),
|
cwd: path.join(process.cwd(), "fullstack-spread"),
|
||||||
command:
|
command:
|
||||||
'cargo run --package dioxus-cli --release -- run --verbose --force-sequential --web --addr "127.0.0.1" --port 7979',
|
'cargo run --package dioxus-cli --release -- run --verbose --force-sequential --web --addr "127.0.0.1" --port 7980',
|
||||||
port: 7979,
|
port: 7980,
|
||||||
timeout: 50 * 60 * 1000,
|
timeout: 50 * 60 * 1000,
|
||||||
reuseExistingServer: !process.env.CI,
|
reuseExistingServer: !process.env.CI,
|
||||||
stdout: "pipe",
|
stdout: "pipe",
|
||||||
|
|||||||
Reference in new issue
Block a user