Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

✨💥 pass data, url to app component by default in react-server-webpack-plugin#1423

Merged
marutypes merged 4 commits intomasterfrom
pass-url-and-data-through-webpack
May 11, 2020
Merged

✨💥 pass data, url to app component by default in react-server-webpack-plugin#1423
marutypes merged 4 commits intomasterfrom
pass-url-and-data-through-webpack

Conversation

@marutypes
Copy link
Contributor

@marutypes marutypes commented May 7, 2020

Closes #1115

What do

This PR revamps what we pass into the user's app in our react-server plugin. It is a breaking change, and since we

In detail it:

  • Moves x-quilt-data header parsing into it's own middleware
  • Changes the name of the x-quilt-data serialization key to just quilt-data (no need for x when it is no longer a header)
  • Passes the full WHATWG URL object into the app component in @shopify/react-server-webpack-plugin as an automatic prop
  • Deserializes and passes quilt-data into the app component as well
  • Updates relevant documentation

Tophatting 🎩

It's tough to write sane tests for this, but I tophatted this pretty thoroughly using hydrox-again following this method:

  • checkout this branch
  • yarn build
  • cp ./packages/react-server ../hydrox-again/node_modules/@shopify
  • cp ./packages/react-server-webpack-plugin ../hydrox-again/node_modules/@shopify
  • cp ./packages/react-server-webpack-plugin ../hydrox-again/node_modules/@shopify/sewing-kit/node_modules
  • change the App.tsx to use the new props
  • run the app

I also prepared this branch that makes all the changes necessary to get this working and also removes some cruft. Once this is actually released we can use this branch to actually install the new version.

@marutypes marutypes requested review from ismail-syed and michenly May 7, 2020 19:38
import App from 'index';
import {showPage, getSerialized} from '@shopify/react-html';

import App from './index';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is failing for me as it cannot find ./index

Copy link
Contributor Author

@marutypes marutypes May 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I thought I had left this as 'index' instead of './index', if you change it back does it work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup changing it back to index works fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah, I recall that the webpack plugin needed index instead of ./index. It was a weird thing I explored/debugged ~8-10 months ago when we first started the plugin.

return <div>this is an about page</div>;
}

return (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

running into a small integration issue with react-router

import {Router} from '@shopify/react-router';
<Router location={url}>

👆 this fail type check because location is typed location?: string;

we can use url.href or change the type to location?: string | URL; and everything would still work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url.href is the right choice, that's what I did in the branch I linked

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I understand that I can use url.href. The point I was trying to make it we don't have to.

Our Router only use location to pass to react-router's StaticRouter

Their doc show example of the following

<StaticRouter location={req.url} context={context}>
        <App />
</StaticRouter>

which mean with a type change Router can accept object as well as string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh, sorry I misunderstood your comment. Seems like it makes sense to update the type indeed then!

@michenly
Copy link
Contributor

michenly commented May 7, 2020

A thought I am having as I integrate it with the magic provider.
I wonder if we should just has @shopify/react-router build into @shopify/react-server ?

Once we have @shopify/react-router provider setup, presumably whenever consumer want url information they can call the various hooks react-router now has to use it. Unless there is an entire category of apps we want to support not using react-router?

<NetworkContext.Provider value={networkManager}>
{children}
<Serialize data={() => ctx.headers['x-quilt-data']} />
<Serialize data={() => ctx.state.quiltData} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a changelog update for this so I presume it doesn't need one. No user impact so makes sense.


### Changed

- Generated entrypoints no longer render the App component with a `location` prop. Apps can instead get the same data from the new `url` prop's `href` attribute.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would constitute a breaking change. Can we highlight this more with some ⚠️, maybe a code snippet comparison?

Copy link
Contributor

@ismail-syed ismail-syed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes make sense to me, 🎩 checks out as well.

One thing that concerns me is that the breaking changes are hidden in the changelog for react-server-webpack-plugin which wouldn't be the first place I'd look if I noticed a breaking change.
Maybe we can draw inspiration from sewing-kit's migration guide doc? But it'll be a bit trickier with quilt_rails related libs since they're all on different versions. This is probably worth a later discussion though.

@marutypes
Copy link
Contributor Author

@ismail-syed probably the relevant spot for more migration explanation would be sewing-kit since it will be hooking up the plugin?

@ismail-syed
Copy link
Contributor

the relevant spot for more migration explanation would be sewing-kit

Good point. Publishing this as a breaking change would address all the concerns I had in mind.

@marutypes marutypes force-pushed the pass-url-and-data-through-webpack branch from be3c491 to 36a969a Compare May 8, 2020 18:47
Copy link
Contributor

@michenly michenly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me & @TheMallen chatted about including react-router in this PR. I am good with it not being included now.

@marutypes marutypes force-pushed the pass-url-and-data-through-webpack branch from 36a969a to c930991 Compare May 11, 2020 17:43
@marutypes marutypes merged commit 7d335a1 into master May 11, 2020
@marutypes marutypes deleted the pass-url-and-data-through-webpack branch May 11, 2020 17:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

react-server-webpack-plugin should pass URL for location on client and server

3 participants