fix(cli): #1770 pass the page node to getBody for develop SSR pages without a segment - #1775
Open
jstockdi wants to merge 2 commits into
Open
Conversation
…elop SSR pages without a segment
…m ssr page object fix
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Resolves #1770
Documentation
No documentation changes. This aligns
greenwood developwith the already documented and already correctgreenwood build+greenwood servebehavior for thepageargument ofgetBody.Summary of Changes
For an SSR page whose route has no dynamic segment,
developwas handinggetBody(compilation, page, request, params)an empty object, whilebuild+servehanded it the fully populated page node from the graph. Sopage.title,page.route,page.dataetc. wereundefinedin development and correct in production, with no error in either mode.In
packages/cli/src/plugins/resource/plugin-standard-html.js:getMatchingDynamicSsrRoutereturnsundefinedwhen nothing matches, but the|| {}turned that into{}.{}is not nullish, so the??never fell through tomatchingRoute— which is resolved on the very same request a couple of lines above and is used for the layout further down, so the correct node was available the whole time.The fix drops the
|| {}so the??can do its job, and switches the two unguarded property reads on that variable to optional chaining so they behave exactly as they did when it was defaulted to{}:matchingRoute.isSSR || matchingRouteWithSegment?.isSSRnew URL(pageHref ?? matchingRouteWithSegment?.pageHref)The other two reads (
matchingRouteWithSegment && matchingRouteWithSegment.segmentfor params) were already guarded and are untouched.getLayoutwas not affected — it is dispatched separately fromlib/layout-utils.jswith the real node — and layout behavior is unchanged here.Tests
Folded into the existing
develop.ssrcase rather than adding a new directory:packages/cli/test/cases/develop.ssr/src/pages/page-object.js, an SSR page withgetBody+getFrontmatterand no dynamic segment, which renderspage.id,page.routeandpage.titledescribeblock asserting those rendered values match the corresponding node in.greenwood/graph.jsonpackages/cli/test/cases/develop.ssr:expected 'undefined' to equal 'page-object')Also re-ran, all green:
develop.dynamic-routing,develop.dynamic-routing-static-paths,develop.typescript.ssr,serve.dynamic-routing,serve.dynamic-routing-static-paths(33 passing), andbuild.default.ssr-prerender,build.default.ssr-static-export,serve.default.ssr,serve.dynamic-routing(144 passing).Note
#1766's fix also lands in
packages/cli/src/plugins/resource/plugin-standard-html.js, around thefs.readFilea dozen lines below this hunk. The two changes are disjoint and should merge cleanly in either order.