Closed RohanM closed 3 years ago
That's an interesting solution, thanks for sharing! We could also introduce the following change to WithSuperJSONPage
, would that be helpful to you?
if (!serializedProps._superjson) {
const PageWithoutProps = Page as React.ComponentType<{}>;
- return <PageWithoutProps />;
+ return <PageWithoutProps {...props} />;
}
That's an interesting solution, thanks for sharing! We could also introduce the following change to
WithSuperJSONPage
, would that be helpful to you?if (!serializedProps._superjson) { const PageWithoutProps = Page as React.ComponentType<{}>; - return <PageWithoutProps />; + return <PageWithoutProps {...props} />; }
Seems like this change should be made regardless of the test issue, right?
It should! I'll put up a PR shortly.
That's an interesting solution, thanks for sharing! We could also introduce the following change to
WithSuperJSONPage
, would that be helpful to you?if (!serializedProps._superjson) { const PageWithoutProps = Page as React.ComponentType<{}>; - return <PageWithoutProps />; + return <PageWithoutProps {...props} />; }
Absolutely, that would make things much simpler. Thank you!
Published in v0.2.0 ☺️
I ran into trouble testing pages in my next.js app with react-testing-library once I introduced SuperJSON. Pages would render, but no props would make their way to them.
Page:
Test:
A quick look at the
babel-plugin-superjson-next
source code shows what's happening: the page is being wrapped inWithSuperJSON
, which expects to receive serialized props. But my test was bypassinggetServerSideProps
, which would have provided the serialized props.You could argue that it would be more comprehensive to test the whole page, including
getServerSideProps
. But for now, I solved the problem by wrapping the page in a serialization layer:And the test becomes: