-
-
Notifications
You must be signed in to change notification settings - Fork 289
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
feat: added vue 2 backwards compatibility for @vue-flow/background #1188
feat: added vue 2 backwards compatibility for @vue-flow/background #1188
Conversation
🦋 Changeset detectedLatest commit: 5a4ce17 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Someone is attempting to deploy a commit to a Personal Account owned by @bcakmakoglu on Vercel. @bcakmakoglu first needs to authorize it. |
b634310
to
c0f5e57
Compare
c0f5e57
to
e2850ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As previously mentioned, please don't remove current component and instead add new ones.
Replacing components can still be done at a later point.
const Background = /* #__PURE__ */ defineComponent({ | ||
name: 'Background', | ||
compatConfig: { MODE: 2 }, | ||
props: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alas, I thought this might be the result of the syntax change, which imo, increases maintenance a lot.
Instead of defineProps<Props>()
we now end up with this mess :(
I assume due to Vue 2 compatibility using the defineComponent<Props, Emits>({ ... })
will not work here, will it?
packages/background/src/patterns.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functional components are, I am pretty sure, Vue 2 compatible and seeing as these are stateless, I don't see why a refactor to stateful components (which in Vue 2 come with more overhead than in Vue 3, so there it would make much less a difference though)
}, | ||
}, | ||
setup(props: DotPatternProps) { | ||
const radius = computed(() => props.radius) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be I'm mistaken about available APIs in Vue 2 but:
-
computed
comes with caching, which produces overhead and therefore has better usage when it comes to expensive computations, not when returning a prop or doing simple equality comparisons likeprop.hello === 'world'
Can be replaced bytoRef
which doesnt produce the same overhead -
Props should still be reactive, even without wrapping them in extra reactive variables.
Meaning, if you doreturn () => h('div', props.label)
and update the label prop, it will still re-render appropriately without wrappingprops.label
incomputed
ortoRef
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you Can open a separate repository for Vue2
e2850ce
to
7897750
Compare
I'd tag this change as a |
Cool. I think the changesets will need the appropriate minor bump too. Do you want me to take care of this? |
Changed the base branch to |
I'm wondering how we could run the test suites for the Vue 2 components as well 🤔 |
7897750
to
66f9a88
Compare
What is your current test setup? Cypress? |
Taken care of the changesets. |
Yeah, tests are done with cypress component testing |
Could you possibly add a Vue 2 example App to the examples folder, so that this can be tried out? |
So I have added one locally, and it works well (not much use to you, granted) ... but we would need to migrate @vue-flow/core before we have full compatibility ... *To get the Vue 2 app working locally, I have to strip the dependency in background on core, and hardest the values return by the useVlueFlow() composable. |
Why would you need to strip that? The app can use a different vue version without the whole repo using the same ^^ |
You'd probably just need to remove the |
name: 'Background', | ||
compatConfig: { MODE: 2 }, | ||
setup(props: BackgroundProps, { slots }) { | ||
const initialPatternColor = props.patternColor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why aren't we allowing dynamic colors for patterns?
Users would expect changes to this prop to be reflected in the pattern color
const height = computed(() => { | ||
return props.height || 100 | ||
}) | ||
|
||
const width = computed(() => { | ||
return props.width || 100 | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong but if toRef
is available in Vue 2 a simple toRef(() => props.height || 100)
should be fine here as well?
}, | ||
"peerDependenciesMeta": { | ||
"@vue/composition-api": { | ||
"optional": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be mandatory?
packages/background/package.json
Outdated
"peerDependencies": { | ||
"@vue-flow/core": "^1.23.0", | ||
"vue": "^3.3.0" | ||
"@vue/composition-api": "^1.0.0-rc.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why rc.1
? Why not pick 1.0.0
, the actual release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If compat mode is set to 2 does the compiled out put of this SFC work in Vue 2 as well?
Imo this is a lot easier to maintain and read than the regular .ts
file since the h
syntax requires a lot of terniaries, making it look like a jsx mess.
The Background.ts
file would also not emit any usable types atm (just doing props: SomeProps
is not enough), giving the proposed implementation no auto-completion support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it out and, alas, it does not work with the SFC, which sucks 😢
I guess the type issue could be circumvented by force casting the exposed components prop, emit and slot types.
Something like this, I believe? Could compare to what Volar outputs with the current roll strategy.
export const VueFlow = /* ... */ as {
$props: FlowProps
// ...
}
66f9a88
to
474b5ba
Compare
474b5ba
to
c03a27e
Compare
So after a bit of playing around, it turns out you can do const Background = /* #__PURE__ */ defineComponent<BackgroundProps>({
// rest here...
}) That is a massive W tbh and should make this a lot easier. Though defining default values for props is still a hassle 😄 Editor: My bad, it does roll types with no error but the types aren't recognized by Volar properly Not the W I hoped for. |
Yeh this is a really strange one ... I'm wondering if this is a bug with Volar ... 🤔 |
c03a27e
to
e7b4e09
Compare
e7b4e09
to
e2ab4d4
Compare
No idea :/ |
e2ab4d4
to
7f756d7
Compare
feat: migrated vue 2 backwards compatibility for @vue-flow/background
7f756d7
to
95d49a0
Compare
Btw, appending + force pushing every commit you make messes up the comments on existing pieces of code ^^ You can just Squash the commits at the end instead of just forcing each time to preserve 1 commit |
"peerDependencies": { | ||
"@vue-flow/core": "^1.23.0", | ||
"vue": "^3.3.0" | ||
"@vue/composition-api": "^1.7.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this unnecessarily force composition api to be installed for Vue 3 users who don't even need this package?
Still think this should be optional: false
instead
@bcakmakoglu Yeh fair, sorry. Will squash at the end. So some of my testing has found some quirky things to make this Vue 2 & Vue 3 compatible:
|
import UserSelection from '../../components/UserSelection/UserSelection.vue' | ||
import NodesSelection from '../../components/NodesSelection/NodesSelection.vue' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no index file to import from so this would atm cause an error
fix: remove accidental push
Bummer but should be fine for now
Yeah, seems so - though for maintenance it might be better to define the props object in another file? iirc you can import object prop definitions
"a typing" issue or is it that the types aren't properly hinted in general? |
I'll continue to dig into why this is, and understand the cause in the API disparity.
Yeh I think we can do something like: export default {
props: {
title: String,
likes: Number
}
}
Yeh the hints is non-existing, and in the template usage where most of the mistakes will inevitably happen. I've reached out to the core team for some advice. I'm just not 100% sure ... |
Well,
Alright, let's wait and see :) |
@Braks Closing this one as I will refactor on top of the core migrated PR. |
refactor: migrated vue 2 backwards compatibility for @vue-flow/background
Description
This MR refactors the @vue-flow/background package to be entirely SFC independent, allowing for backwards compatibility with Vue 2.7.* as well as continuing support for Vue 3.
Essentially, these changes should be able to be merged into master / main without any trouble at all for the existing package.
Testing 🔧
Vue 2 App Example (with just the background component rendered*):
Vue 3 Vite App Example: