Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a dotcom-ui-client-embed package for sharing data between the server and the client #799

Closed
magsallen opened this issue Apr 16, 2020 · 3 comments · Fixed by #812
Closed

Comments

@magsallen
Copy link
Contributor

magsallen commented Apr 16, 2020

Currently we have no defined method for apps to share data between the client and the server. Some apps have resorted to updating the appContext object as a way around this but we want to discourage this practice and v0.7.0 of Page Kit introduced errors when modifying appContext to prevent this behaviour.

Proposal:

  • Create a new dotcom-ui-client-embed package containing all of the logic required to pass data from the server to the client without modifying appContext.
  • Refactor dotcom-middleware-app-context and dotcom-middleware-flags to use this new package rather than duplicating the same functionality in multiple places.
  • Document a process for other apps to make use of the new package to pass custom properties from the client to the server.
  • Incorporate this functionality into an example app.
@andygout
Copy link
Contributor

Case study: next-video-page, which currently adds this to appContext:

{
	permutiveContext: {
		publicId: process.env.PERMUTIVE_PUBLIC_ID,
		publicApikey: process.env.PERMUTIVE_PUBLIC_API_KEY
	}
}

@NickColley
Copy link
Contributor

One thought... If someone fails the appContext schema validation we could consider pointing them to the documentation for this...

@magsallen
Copy link
Contributor Author

Yes, I think so 👍 At the moment I believe we serve a Typescript error but we could definitely do better than this!

We actually have a design decisions doc about appContext which has become out-of-date; if we update that as part of this work then it might be a good resource to point to in the event of a validation error https://github.com/Financial-Times/dotcom-page-kit/blob/master/docs/design-decisions/app-context.md

@NickColley NickColley linked a pull request May 5, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants