Coder Social home page Coder Social logo

luisfuturist / vike-island-example Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 0.0 211 KB

(⚗️ Experimental) Islands architecture implementation example using Vike + React + Vue.

Home Page: https://vike-islands-example.luisfuturist.workers.dev

JavaScript 10.57% TypeScript 83.69% CSS 0.27% Vue 5.47%
react vike vite vue islands islands-architecture public

vike-island-example's Introduction

Luis Emidio Full Stack Developer • Cyberspace

Hey there! As a self-taught Full Stack developer, my journey is fueled by a passion for language, philosophy, and the boundless realms of technology and the future. In my free time, I immerse myself in the captivating worlds of cyberpunk, with favorites like Ghost in the Shell sparking my imagination and propelling me towards new horizons.


Art by Alex Feliksovich

"That's all it is: information. Even a simulated experience or a dream; simultaneous reality and fantasy. Any way you look at it, all the information that person accumulates in a lifetime is just a drop in the bucket..." – Batou


If you share similar interests or want to chat about exciting futuristic projects, don't hesitate to reach out – let's be part of the future together

LinkedIn X (Social Media) Discord

vike-island-example's People

Contributors

lourot avatar luisfuturist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vike-island-example's Issues

Flexible Hydration with Multi-Framework Islands on Vike

Thanks @luisfloat for exploring this. Interestingly I had a different understanding of what islands are, especially because one island could be in React, another one could be in Vue, etc. At least this is an idea that caught my eye in https://docs.astro.build/en/concepts/islands/ . So here is the direction I would have taken:

1. Replace +Page.tsx by one + file per island

I would create one new setting per island, say islandReact and islandVue, so for each page I would have files like +islandReact.tsx and +islandVue.vue instead of +Page.tsx.

See https://vike.dev/meta for creating your own settings. Page is just a setting.

2. Adapt onRenderHtml() and onRenderClient() for rendering both islands

It would look like

// https://vike.dev/onRenderHtml
export { onRenderHtml }

import React from 'react'
import { renderToString as renderReactToString } from 'react-dom/server'
import { renderToString as renderVueToString } from '@vue/server-renderer'
import { createVueApp } from './app'
import { escapeInject, dangerouslySkipEscape } from 'vike/server'

async function onRenderHtml(pageContext) {
  const { islandReact } = pageContext
  const reactViewHtml = dangerouslySkipEscape(
    renderReactToString(<islandReact />)
  )

  const vueApp = createVueApp(pageContext)
  const vueViewHtml = await renderToVueString(app)

  return escapeInject`<!DOCTYPE html>
    <html>
      <body>
        <div id="react-view">${reactViewHtml}</div>
        <div id="vue-view">${vueViewHtml}</div>
      </body>
    </html>`
}
// https://vike.dev/onRenderClient
export { onRenderClient }

import React from 'react'
import { hydrateRoot } from 'react-dom/client'
import { createVueApp } from './app'

async function onRenderClient(pageContext) {
  const { islandReact, islandVue } = pageContext
  hydrateRoot(
    document.getElementById('react-view'), <islandReact />
  )

  const vueApp = createVueApp(pageContext)
  vueApp.mount('#vue-view')
}

I basically merged these two examples:

What do you think? One drawback of this is that the amount of islands is hardcoded for all pages of the entire app, as is their layout. But I'm wondering if it is any different with Astro if you want to mix React and Vue? 👀 Anyway such an example of mixing React and Vue in the same page on Vike could be quite nice.

But if what you want is just to have certain areas of the app not being hydrated, you are basically reinventing Server Components? That's quite a complex topic and we have it on our radar: https://vike.dev/react#react-server-components

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.