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

fix: make location configurable #432

Merged
merged 4 commits into from
Jun 18, 2021
Merged

fix: make location configurable #432

merged 4 commits into from
Jun 18, 2021

Conversation

jaulz
Copy link
Contributor

@jaulz jaulz commented Jun 4, 2021

This PR will add full SSR support.

@jaulz jaulz changed the title fix: make location configurable [WIP] fix: make location configurable Jun 4, 2021
@jaulz jaulz changed the title [WIP] fix: make location configurable fix: make location configurable Jun 4, 2021
@jaulz
Copy link
Contributor Author

jaulz commented Jun 4, 2021

@bakerkretzmar this is my suggestion for #431 😊 It would be great if you could have a look!
@aarondfrancis maybe also interesting for you 😊

@aarondfrancis
Copy link

aarondfrancis commented Jun 4, 2021 via email

@aarondfrancis
Copy link

aarondfrancis commented Jun 7, 2021

src/js/Router.js Outdated
@@ -15,7 +15,7 @@ export default class Router extends String {
super();

this._config = config ?? Ziggy ?? globalThis?.Ziggy;
this._config = { ...this._config, absolute };
this._config = { location: {}, ...this._config, absolute };
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't strictly necessary, right? As long as we check for null/undefined when we access it below with something like this._config.location?.host?

src/js/Router.js Outdated
*
* @return {Object}
*/
get location() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need to be public? The config object should be all people need in order to configure this functionality, so let's make this private if possible. Should be as simple as renaming to get _location().

@bakerkretzmar
Copy link
Collaborator

Thanks a ton for this PR @jaulz, and for your post @aarondfrancis! This looks great to me, I'll wait for you to take a look at my questions and I'm just going to push up some formatting tweaks and then it should be good to go.

Am I right that after this PR, using Ziggy with Inertia and SSR would look something like this?

import route from 'ziggy';

export default async function (event) {
    return await createInertiaApp({
        // ssr stuff...
        setup({app, props, plugin}) {

            const Ziggy = { ...event.props.ziggy, location: new URL(event.props.ziggy.url) };

            return createSSRApp({
                render: () => h(app, props),
            }).mixin({
              methods: {
                  route: (name, params, absolute, config = Ziggy) => route(name, params, absolute, config),
              },
          })
        },
    });
}

@aarondfrancis
Copy link

Thanks a ton for this PR @jaulz, and for your post @aarondfrancis! This looks great to me, I'll wait for you to take a look at my questions and I'm just going to push up some formatting tweaks and then it should be good to go.

Am I right that after this PR, using Ziggy with Inertia and SSR would look something like this?

import route from 'ziggy';

export default async function (event) {
    return await createInertiaApp({
        // ssr stuff...
        setup({app, props, plugin}) {

            const Ziggy = { ...event.props.ziggy, location: new URL(event.props.ziggy.url) };

            return createSSRApp({
                render: () => h(app, props),
            }).mixin({
              methods: {
                  route: (name, params, absolute, config = Ziggy) => route(name, params, absolute, config),
              },
          })
        },
    });
}

Yes, I think so! And it's beautiful 😍

Thanks @bakerkretzmar!

@bakerkretzmar bakerkretzmar linked an issue Jun 9, 2021 that may be closed by this pull request
@jaulz
Copy link
Contributor Author

jaulz commented Jun 9, 2021

@bakerkretzmar thanks for cross checking and I incorporated your feedback 😊

@jaulz
Copy link
Contributor Author

jaulz commented Jun 15, 2021

@bakerkretzmar do you think we could merge it in this state? Otherwise I am happy to rework it.

@bakerkretzmar bakerkretzmar merged commit b2f9715 into tighten:main Jun 18, 2021
@bakerkretzmar
Copy link
Collaborator

Thanks a ton @jaulz!

@yashiroiori
Copy link

Thanks a ton for this PR @jaulz, and for your post @aarondfrancis! This looks great to me, I'll wait for you to take a look at my questions and I'm just going to push up some formatting tweaks and then it should be good to go.

Am I right that after this PR, using Ziggy with Inertia and SSR would look something like this?

import route from 'ziggy';

export default async function (event) {
    return await createInertiaApp({
        // ssr stuff...
        setup({app, props, plugin}) {

            const Ziggy = { ...event.props.ziggy, location: new URL(event.props.ziggy.url) };

            return createSSRApp({
                render: () => h(app, props),
            }).mixin({
              methods: {
                  route: (name, params, absolute, config = Ziggy) => route(name, params, absolute, config),
              },
          })
        },
    });
}

From where import "createSSRApp", I'm using inertiajs with react

@bakerkretzmar
Copy link
Collaborator

I think SSR is still in early access for Inertia sponsors only: https://inertiajs.com/server-side-rendering

@yashiroiori
Copy link

I think SSR is still in early access for Inertia sponsors only: https://inertiajs.com/server-side-rendering

Yes, but in examples are in this page from where import createSSRApp??

@bakerkretzmar
Copy link
Collaborator

I would guess something like import { createSSRApp } from '@inertiajs/inertia-vue3' but I'm not in early access so I'm not sure 😅

@heychazza
Copy link

Hey guys,

Thanks a ton for this PR @jaulz, and for your post @aarondfrancis! This looks great to me, I'll wait for you to take a look at my questions and I'm just going to push up some formatting tweaks and then it should be good to go.

Am I right that after this PR, using Ziggy with Inertia and SSR would look something like this?

import route from 'ziggy';

export default async function (event) {
    return await createInertiaApp({
        // ssr stuff...
        setup({app, props, plugin}) {

            const Ziggy = { ...event.props.ziggy, location: new URL(event.props.ziggy.url) };

            return createSSRApp({
                render: () => h(app, props),
            }).mixin({
              methods: {
                  route: (name, params, absolute, config = Ziggy) => route(name, params, absolute, config),
              },
          })
        },
    });
}

trying this, I am told event doesn't exist, has anything changed since for configuring SSR?

@bakerkretzmar bakerkretzmar mentioned this pull request Dec 7, 2021
@anburocky3
Copy link

What is the equalent of using React?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Full SSR support
6 participants