451 Commits

Author SHA1 Message Date
WorldSEnder
6f6c61b975
Allow macro invocations as prop values (#2687)
* fix: macro invocations in props #2267

convert macro invocation Item statements to Exprs

* remove now useless braces in docs
2022-05-18 07:58:46 +02:00
Shadlock0133
08fb060afb
Point to callback_future in callback docs (#2674) 2022-05-11 12:56:44 +02:00
WorldSEnder
d7b43bbc26
Change access to VList children to a wrapper (#2673)
this should avoid having to manually call recheck_fully_keyed

* add mutable accessor to children
* fix workflow
* fix markdown example
* remove recheck_fully_keyed
2022-05-11 12:37:39 +02:00
WorldSEnder
1d579a8bf4
Rework a bunch of cfg(feature) flags to be more principled (#2666)
* rework a bunch of feature flags to be more principled

* fixup of Collectable

* silence clippy

* unfix Mountable trait

leads to bundle size increase, so stick to the optimized version

* use required-features for function_router

* use --all-features in various places

* disable tokio dependency on wasm tests again

* add some #[inline] annotations

* merge one more feature annotations

* fixup: remove a line connected to trace_hydration
2022-05-07 21:17:47 +05:00
Kaede Hoshikawa
00b94d0051
Make Switch to accept a closure as render function directly (#2659)
* RenderFn can be be directly Fn() now.

* Switch switch to function component.

* Make Link a function component.

* Remove non-exhaustive.

* Add migration guide.

* Update Website Docs.

* Fix CI.

* Pushing to Navigator no longer requires an owned instance.

* Fix CI.

* Fix code size.

* Further optimisation.
2022-05-06 09:56:49 +09:00
Dietmar Maurer
e5880136bb
Attributes: Fix apply_diff_index_maps (#2653)
* Attributes: Fix apply_diff_index_maps

The old algorithm simply stops when key name/order changes, which
is simply wrong.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>

* add test case for test for bug #2653
2022-05-05 15:20:05 +09:00
Muhammad Hamza
18f004bc57
Fix cargo make config and tests (#2640)
* remove pr-flow, run all the tests when asked

* make tests that were never run pass

* run tests cargo make properly

* use wasm-pack-base test for running wasm tests

* cargo make config should be good

* update CI
2022-04-28 21:04:55 +05:00
Kaede Hoshikawa
2576372e26
Delay Hydration second render until all assistive nodes have been removed (#2629)
* Separate hydration and render queue.

* Revert "Fix issue with node refs and hydration (#2597)"

This reverts commit 469cc341c340bd0093d9233847f523b66a18fd90.

* Priority Render.

* Add some tests.

* Add more tests.

* Add test result after click.

* Fix test comment.

* Fix test timing.

* Restore test.

* Once AtomicBool, now a Cell.

* Prefer use_future.

* Revealing of Suspense always happen after the component has re-rendered itself.

* Shifting should register correct next_sibling.

* Revert to HashMap.

* cargo +nightly fmt.

* Fix comment.

* Optimise Code size?

* Add comment if assertion fails.

* Revert "Merge branch 'hydration-4' into fc-prepared-state"

This reverts commit 427b087d4db6b2e497ad618273655bd18ba9bd01, reversing
changes made to 109fcfaa127aefc5fa3c697e254fe2c049292be2.

* Revert "Revert "Merge branch 'hydration-4' into fc-prepared-state""

This reverts commit f1e408958d94cb13813ce75aa6f0aad06c9fa3e8.

* Redo #2957.
2022-04-25 07:35:55 +09:00
Lucille Blumire
2db4c81ad6
Add VTag::into_children (#2638)
* Add `VTag::into_children`

Currently, VTag supports `children` and `children_mut`, but not `into_children` to complete the pattern. This is useful if someone wishes to destructively acquire the children of a VTag to reparent them to a different VTag.

* Repair broken doc comment on `VTag::children_mut`

* Remove spaces between functions
2022-04-23 21:06:41 +09:00
WorldSEnder
1794dd01bc
Fix cargo fmt from merge changes (#2636)
Fixup #2630
2022-04-22 17:26:41 +02:00
Muhammad Hamza
c28a71e78e
Use nightly for Rustfmt (#2630)
* add rustfmt.toml, use nightly in CI, update contributing docs

* run `cargo +nightly fmt`
2022-04-21 23:21:15 +05:00
Muhammad Hamza
12c9ebb0ea
Move hook API docs to Rustdoc (#2628)
* Move hook API docs to Rustdoc

* npm update, fix links and doc tests and callback docs

* make doc tests pass

* Update packages/yew/src/functional/hooks/use_ref.rs

* Update packages/yew/src/functional/hooks/use_ref.rs

* Update use_ref.rs
2022-04-21 15:28:09 +05:00
WorldSEnder
c2b2f2cf2d
fixes bubbling of events originating in shadow dom (#2627)
when we not explicitly portaling into the shadow, we
should bubble up to the host element and continue.
This fixes custom elements internally using open SD
2022-04-20 16:33:52 +05:00
WorldSEnder
504693ff30
Introduce use_future_with_deps (#2615)
* introduce use_future_with_deps

* add documentation to use_future

* use_future_with_deps now uses Rc<D> instead of &D

* fix expansion and simplify use_future
2022-04-17 21:07:26 +05:00
Kaede Hoshikawa
c5b7790949
Remove IntoComponent (#2579)
* Make Function Component to Implement BaseComponent.

* Remove IntoComponent.

* Inline some methods.

* Move some logic out of proc macro.

* Move position of the self generics.

* Discourage direct implementation `FunctionComponent` & `#[doc(hidden)]`.
2022-04-16 00:44:39 +02:00
Kaede Hoshikawa
6fb547339f
Fix some Hook edge cases (#2592)
* Fix a couple edge cases.

* no implicit prelude.
2022-04-16 01:47:04 +05:00
Jet Li
58db53a026
Allow to consume deps in use_callback (#2617) 2022-04-16 01:43:13 +05:00
dependabot[bot]
d2c3685521
Update gloo requirement from 0.6 to 0.7 (#2613)
Updates the requirements on [gloo](https://github.com/rustwasm/gloo) to permit the latest version.
- [Release notes](https://github.com/rustwasm/gloo/releases)
- [Commits](https://github.com/rustwasm/gloo/compare/0.6.0...0.7.0)

---
updated-dependencies:
- dependency-name: gloo
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-04-15 12:16:04 +02:00
Muhammad Hamza
edeb59d777
Add use_future hook to make consuming futures as suspense easier (#2609)
* Add `use_suspending_future` hook to make consuming futures as suspense easier

* Add test

* fmt

* use_suspending_future -> use_future

* use_future takes a closure
2022-04-14 23:10:32 +05:00
WorldSEnder
469cc341c3
Fix issue with node refs and hydration (#2597)
* Fix issue with node refs and hydration

When a component is contained in a component, the
inner reconciles, which used to replace the NodeRef,
which left a badly linked one in the outer Hydration render state.

Now, keep a stable internal_ref besides the user-passed node_ref.
The internal_ref never gets replaced as long as the BComp lives.
2022-04-13 00:31:48 +02:00
Muhammad Hamza
e9b64e0a45
Add the ability to use non-literal string as attribute names (#2593)
* Use AttrValue instead of &'static str in Attributes::IndexMap

* avoid monomorphization to reduce binary size

* fmt & `#[inline(always)]`s

* more attempts to reduce the code size

* make clippy happy
2022-04-13 03:27:22 +05:00
WorldSEnder
6992a454e3
Introduce a dedicated use_force_update hook (#2586)
* introduce a dedicated use_force_update hook

* fix doc links
2022-04-09 16:54:39 +05:00
Nano
ae26885589
Impl ImplicitClone for Rc<T> where T: Sized (#2594) 2022-04-09 13:33:16 +02:00
WorldSEnder
e2405298c6
update zxcvbn to 2.2.1 (#2568)
* update zxcvbn to 2.2.1

* fix clippy issues

* Upgrade to wasm_bindgen 0.2.80

* resolve TODO, linked pr now merged
2022-04-08 13:03:45 +05:00
Kaede Hoshikawa
6d07ba3b90
Fix generic with impl trait. (#2589) 2022-04-07 19:45:26 +05:00
Muhammad Hamza
2f3b90ce2c
Fix macro hygine issues (#2585)
* no_implicit_prelude in macro tests

* #[automatically_derived] and #[doc(hidden)]

* Span::call_site() -> Span::mixed_site()
2022-04-07 01:14:00 +05:00
Kai Jellinghaus
ec1f43aa24
Fix typo(s) in use_callback docs (#2580)
* Fix typo in use-callback.mdx

* Fix the same typo in two more places 🤔

* Fix rest of typos
2022-04-06 16:48:51 +02:00
WorldSEnder
8978baa45d
Fix casing of dynamic tags (#2578)
* fix casing of dynamic tags
* add test case for unknown tag names
* add lint for non-normalized tags
2022-04-05 19:07:31 +02:00
Kaede Hoshikawa
e46ae55cab
SSR Hydration (#2552)
* Bring changes to this branch.

* Add feature hydration.

* Hydrate text.

* Hydrate tag.

* Hydrate node.

* Hydrate List.

* Hydrate Suspense.

* Hydrate component.

* Renderer::hydrate.

* Add example and tests.

* Fix comp_id.

* Move some code away from generics.

* Fix everything.

* trybuild?

* Collectable!

* Phantom component.

* Migrate docs as well.

* Update example.

* Fix docs and improve debug message.

* Minor fixing.

* Add hydration to feature soundness check.

* Fix name in debug.

* Remove Shift.

* Remove comment.

* Adjust readme.

* Update website/docs/advanced-topics/server-side-rendering.md

Co-authored-by: Muhammad Hamza <muhammadhamza1311@gmail.com>

* Update packages/yew/src/dom_bundle/bnode.rs

Co-authored-by: Muhammad Hamza <muhammadhamza1311@gmail.com>

* Update packages/yew/src/dom_bundle/bnode.rs

Co-authored-by: Muhammad Hamza <muhammadhamza1311@gmail.com>

* Once via structopt, now direct clap.

* Fix docs and empty fragment.

* Remove struct component warning.

* Move function router into a separate binary.

* Optimise Code Logic.

* Fix condition.

* Fix rendering behaviour.

* Fix comment.

Co-authored-by: Muhammad Hamza <muhammadhamza1311@gmail.com>
2022-04-03 08:00:16 +09:00
Jet Li
421b4e1f60
Add use_callback hook (#2566)
* Add use_callback hook

* Simply use_callback
2022-04-01 13:10:27 +03:00
Finn Bear
ea8a530454
Fix #2553 - automatically convert closure to callback for component properties (#2554)
* Fix #2553 - automatically convert closure to callback for component properties.

* Support F -> Option<Callback<_>> too.

* test stderr.
2022-03-28 00:43:53 +02:00
Kaede Hoshikawa
2e098f4f6c
Introduce additional information in SSR artifact to facilitate Hydration (#2540)
* Bring changes to this branch.

* Child components always render after parents.

* Add hydratable to render_to_string.

* Revert portal example.

* Fix vcomp.

* Prefer debug_assert.

* ServerRenderer now a Builder Pattern.

* Collectable.
2022-03-26 08:57:08 +09:00
WorldSEnder
ee6a67e3ea
Scoped event handlers (#2510)
* implement event handling with multiple subtree roots
* add listeners to all subtree roots
* move host element to Registry
* add BSubtree argument
* surface level internal API for BSubtree
* cache invalidation & document limitations
* Update portal documentation
* Add test case for hierarchical event bubbling
* add shadow dom test case
* add button to portals/shadow dom example
* change ShadowRootMode in example to open

BSubtree controls the element where listeners are registered.
 we have create_root and create_ssr

Async event dispatching is surprisingly complicated.
Make sure to see #2510 for details, comments and discussion

takes care of catching original events in shadow doms
2022-03-25 17:09:15 +01:00
Kaede Hoshikawa
62d78d0641
An ever Increasing Component ID (#2537)
* Bring changes to this branch.

* Child components always render after parents.

* Cleanup residual Portal references.

* Fix after merge.

* Fix trybuild.

* Opt for usize.

* Strip Generics.

* take instead of replace, first instead of front.
2022-03-21 23:47:33 +09:00
Kaede Hoshikawa
b392023686
Prevents Fallback UI from becoming suspended (#2532)
* Bring changes to this branch.

* Add BaseSuspense.

* Create detached parent inside of bundle.

* Fix ctx and opt for html!.

* Make Portals "work" with SSR.

* Update docs.

* Fix feature flags.

* Revert portal design.

* Fix feature flag.
2022-03-20 17:01:40 +09:00
Kaede Hoshikawa
8bc2212716
#[cfg(feature = "render")] and yew::Renderer (#2498)
* Bring changes to this branch.

* Bring changes to this branch.

* Add feature render and renderer.

* Bring changes to this branch.

* Migrate examples to Renderer.

* Satisfy no any render.

* Satisfy ssr.

* Satisfy feature render.

* Lint feature soundness.

* Suppress tests.

* Fix pr-flow, update docs.

* Add a notice.

* Adjust visibility.

* Correctly feature gate tests.

* make test scope available under feature render.

* Fix CI.

* Fix CI.

* Restore tests module to its original place as well.

* Make bundles crate private.

* Make most bundle APIs private.

* Adjust docs.

* Adjust debug implementation.

* Replace start_app with Renderer.

* Adjust documentation.

* Remove unused lint.

* Remove start_app from docs.

* DomBundle -> ReconcileTarget.

* Adjust documentation.

* Once render, now csr.

* Fix docs as well.
2022-03-20 00:48:47 +09:00
WorldSEnder
889c6ba74e
Fix #2506 and improve some related documentation (#2507) 2022-03-10 15:37:12 +01:00
Kaede Hoshikawa
51238fb0e3
Better Function Component in docs + Macro-based Hooks (#2478)
* Fix const function component.

* Show Properties on the function definition.

* Filter certain doc attributes to be applied to type alias. More precise warnings.

* Implement macro-based hook.

* Add fail case.

* Function Component no longer a type alias.

* Clippy!

* Force 'static on generics.

* Fix clippy!

* Fix clippy and trybuild.

* Fix clippy and trybuild.

* Fix clippy.

* BaseComponent was not sealed properly.

* Adjust prelude.

* Public API should use IntoComponent for better ergonomics.

* Fix race condition.

* Fix trybuild.
2022-03-08 18:03:40 +05:00
Yuki Kodama
e2b91caabd
Includes query parameters in rendered Link component (#2464)
* Add tests for Link component

* Include query parameters in href of Link component

* Add test cases for HashRouter and basename option

* Fix test name, format, clippy

* Ignore clippy warnings for test helpers
2022-03-07 18:32:01 +05:00
Kaede Hoshikawa
f39afdc5e1
Remove benchmarks for now as it does not work at all. (#2495) 2022-03-07 18:28:58 +05:00
WorldSEnder
78d4204a9a
Introduce explicit internal datastructures modeling dom state (#2330)
* detach destructures now

* add failing keyed-list issue

* crude port to the new bundle infrastructure

* port over the infrastructure

the new bcomp is especially nice and lost a few unwraps owed to not having
to reserve space for a scope before rendering.
Note also that bsuspense has been slimmed a bit, storing the suspended flag
implicitly in the state.
some naming is not perfect yet and has to be adjusted still.

* mass rename: apply -> reconcile

* get rid of move_before in favor of shift

* generate id directly when creating a new scope

* bundle for text nodes

* work on naming: ancestor -> bundle

* slightly optimize list reconciler, add doccomments

* address review

* add internal documentation

* address review comments

rename fields in bsuspense
convert to gloo::events

* move even more stuff into dom_bundle to scope exports

- app_handle and layout_tests are now in there
- items are publically re-exported in crate::dom_bundle
- dom_bundle itself is private
- btag and bcomp get their own submodules
- bcomp now contains the lifecycle and scope impls

* move replace into Reconcilable

* move lifecycle and scope back into html as per review

* move back Value and InputFields into html

* actually only type-check format args in production

* fix documentation link

* move btag_impl up into containing module

* shift comps immediately

shifting the rendered Nodes does not tie into the lifecycle,
as such it can happen immediately

* use list-bundle in tag-bundle

* fix cargo make tests

* improve 05_swap benchmark

* fix a blunder where I swapped operands

* fix naming of BNode variants
2022-03-06 08:37:07 +05:00
Julius Lungys
221b4dfa51
fix clippy (#2492) 2022-03-05 20:53:19 +01:00
Aaron Erhardt
36058d455c
Improve AnyScope API (#2445)
* Improve AnyScope API

Signed-off-by: Aaron Erhardt <aaron.erhardt@t-online.de>

* Make find_parent_scope public

Signed-off-by: Aaron Erhardt <aaron.erhardt@t-online.de>
2022-02-26 13:00:44 +01:00
Kaede Hoshikawa
fc067ab56c
Fix Call Generics & FnOnce macro hygiene (#2437)
* Fix Call Generics & FnOnce macro hygiene.

* Add a failure case as well.

* Remove a unused struct in test case.

* Update packages/yew-macro/tests/hook_attr/hook-const-generic-pass.rs

Co-authored-by: Muhammad Hamza <muhammadhamza1311@gmail.com>
2022-02-12 18:26:23 +05:00
Cecile Tonglet
95fb5dc8fb
Remove probably unused impl ImplicitClone on Cow<str> (#2447)
* Remove probably unused impl ImplicitClone on Cow<str>

* Remove unused import

* Remove variant Owned for AttrValue for consistency

* Implement ImplicitClone on primitive types

Especially those that are Copy.
2022-02-12 01:09:49 +05:00
Kaede Hoshikawa
e56ff20b63
Automatic Message Batching (#2421)
* (○`дノ´)ノ┳┳・゚・┻┻・゚・。

* Recover docs as well.

* Make scheduler synchronous for now.

* Disable Component IDs as they are not useful at the moment.

* Minor fixing, amending messages and apply optimisation on batched messages.
2022-02-07 20:46:09 +05:00
Julius Lungys
636692507e
Convert components concept docs from SC to FC (#2434)
* Convert components concept docs from SC to FC
- moved struct components to advanced topics
- added docs about HOC for Suspense and Context
- added a ease-in topic before components that introduces
HTML/CSS/JS in yew
- edit components concept to use function components

* translations

* fix todo links

* fix tests

* spelling bee
2022-02-07 11:03:12 +02:00
Alexander Mescheryakov
d5cc4a3237
Add Other variant to the ListenerKind (#2417)
* Add other listener kind

* Remove Copy restriction

* Fix fmt
2022-01-31 09:57:08 +02:00
Kaede Hoshikawa
b7b28ba963
Do not detach child elements if parent element is about to be detached (#2420)
* Make a use_hook hook with the new Hook trait.

* Implement Lifetime.

* Rewrites function signature.

* Only apply lifetime if there're other lifetimes.

* Cleanup signature rewrite logic.

* Rewrite hook body.

* Port some built-in hooks.

* Finish porting all built-in hooks.

* Port tests.

* Fix tests.

* Migrate to macro-based hooks.

* Fix HookContext, add tests on non-possible locations.

* Fix stderr for trybuild.

* Add 1 more test case.

* Adjust doc location.

* Pretty print hook signature.

* Fix Items & std::ops::Fn*.

* Add use_memo.

* Optimise Implementation of hooks.

* Use Box to capture function value only.

* Detect whether needs boxing.

* Add args if boxing not needed.

* Enforce hook number.

* Deduplicate use_effect.

* Optimise Implementation.

* Update documentation.

* Fix website test. Strip BoxedHook implementation from it.

* Allow doc string.

* Workaround doc tests.

* Optimise codebase & documentation.

* Fix website test.

* Reduce implementation complexity.

* Destructor is no more.

* Do not detach child element if parent element is about to be detached as well.

* Fix tests.
2022-01-30 13:24:33 +02:00
Kaede Hoshikawa
485a1b8c4a
Function Components & Hooks V2 (#2401)
* Make a use_hook hook with the new Hook trait.

* Implement Lifetime.

* Rewrites function signature.

* Only apply lifetime if there're other lifetimes.

* Cleanup signature rewrite logic.

* Rewrite hook body.

* Port some built-in hooks.

* Finish porting all built-in hooks.

* Port tests.

* Fix tests.

* Migrate to macro-based hooks.

* Fix HookContext, add tests on non-possible locations.

* Fix stderr for trybuild.

* Add 1 more test case.

* Adjust doc location.

* Pretty print hook signature.

* Fix Items & std::ops::Fn*.

* Add use_memo.

* Optimise Implementation of hooks.

* Use Box to capture function value only.

* Detect whether needs boxing.

* Add args if boxing not needed.

* Enforce hook number.

* Deduplicate use_effect.

* Optimise Implementation.

* Update documentation.

* Fix website test. Strip BoxedHook implementation from it.

* Allow doc string.

* Workaround doc tests.

* Optimise codebase & documentation.

* Fix website test.

* Reduce implementation complexity.

* Destructor is no more.

* Documentation and macros.

* Reduce heap allocation and hook complexity.

* Remove Queue as well.

* Prefer Generics.

* Fix typo.

* Remove more allocations.

* Add comments.

* Remove outdated comment.

* Bare Function Pointer for better code size.
2022-01-28 11:51:37 +02:00