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

🏝 React Islands: Can we only hydrate selected components? [ON PAUSE UNTIL APRIL] #445

Closed
wants to merge 6 commits into from

Conversation

AWare
Copy link
Contributor

@AWare AWare commented Feb 28, 2019

What

This provides a way to selectively hydrate only parts of the React tree.

Each part which must be hydrated and sent to the client is wrapped in a div which has it's props and filename included in data-attributes. These are then used to hydrate the component into the div.

Islands introduces a component which takes a component, the import path of the component and a serialisable object which takes the props of the component- and adds them to the DOM wrapped such that they can be automatically rehydrated.

 <Island
                    from="ClientComponent"
                    component={ClientComponent}
                    data={{ hello: 'world' }}
                />

TODO

  • The filename is directly set in the Island as a prop.
  • Only default exports are supported.
  • Server only js needs to be more thoroughly separated,
  • It needs to be type safe.
  • Should props be sent like this?

@PRBuilds
Copy link

PRBuilds commented Feb 28, 2019

PRbuilds results:

LightHouse Reporting
1551443235.report.html

--automated message

@AWare
Copy link
Contributor Author

AWare commented Feb 28, 2019

// const hello = document.getElementById('hello');
// hydrateApp(React.createElement(c.default, {}), hello);
// });
const islands = [...document.querySelectorAll('.js-island')];
Copy link

Choose a reason for hiding this comment

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

let's use <gu-island> it looks cooler

@@ -104,3 +124,5 @@ if (window.guardian.polyfilled) {
} else {
window.guardian.onPolyfilled = go;
}

console.log('HELLO IM RUNNIGN');
Copy link

Choose a reason for hiding this comment

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

😹

});
return (
<div className="js-island" data-island={c} data-data={JSON.stringify(data)}>
{s(data)}
Copy link

Choose a reason for hiding this comment

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

you need to use React.createElement() here or things will get weird

Copy link

Choose a reason for hiding this comment

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

Suggested change
{s(data)}
{React.createElement(s, data, data.children?)}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💯

packages/frontend/web/pages/Article.tsx Show resolved Hide resolved
@AWare AWare changed the title 🏝 🏝 React Islands: Can we only hydrate selected components? Mar 1, 2019
@AWare AWare changed the title 🏝 React Islands: Can we only hydrate selected components? 🏝 React Islands: Can we only hydrate selected components? [ON PAUSE UNTIL APRIL] Mar 4, 2019
@AWare
Copy link
Contributor Author

AWare commented Mar 11, 2019

Moving the create element into the loaded script would allow this to load any component. We could SSR anything into it with dangerouslySet and optionally jsdom maybe?

@nicl
Copy link
Contributor

nicl commented Jul 4, 2019

Hey both @walaura and @AWare I'm going to close this as we're not planning on working on it at the moment, but we can easily resurrent if it becomes relevant again in the future!

@nicl nicl closed this Jul 4, 2019
@gtrufitt gtrufitt deleted the island branch August 9, 2019 15:33
@oliverlloyd oliverlloyd mentioned this pull request Nov 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔬 R&D 🔬 🥒WiP Work in Progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants