241 Commits

Author SHA1 Message Date
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
Anuvrat Singh
4580d94c59
Add ContextHandle in yew::prelude (#2372)
* Adds ContextHandle in yew::prelude

* Adds ContextHandle in yew::prelude

Added ContextHandle in /yew/src/lib.rs and updated stderr with test-overwrite

* Formats code using cargo fmt

* Revert "Adds ContextHandle in yew::prelude"

This reverts commit abdf21f2d523ac2df56cca3d29f8860dbefc5cc5.
2022-01-25 14:51:16 +02:00
Kaede Hoshikawa
38021e31fe
Separate scheduler rendered call from create and render (#2374)
* Separate push_component_rendered from push_component_render and push_component_update.

* Fix pr-flow.

* Make first_render more reliable.
2022-01-22 20:04:12 +02:00
Alexander Mescheryakov
fac220fd64
Fix add a listener to VTag when the listeners is None (#2375)
* Fix add listener and remove unused listener code

* Format code
2022-01-20 20:30:36 +01:00
Shivam
01a259431d
resolve some dead links as mentioned in issue #2379 (#2380)
* resolve some dead links as mentioned in issue #2379

* done the required changes
2022-01-19 18:20:24 +02:00
Muhammad Hamza
62e3194d5f
Improve hosted API docs (#2373)
* build up redirects for API docs hosting

* build with all features and documenting config

* fix warnings

* can rustdoc please provide a way to modify the base url?

I want to host the docs at /next/:crate_name, not at /:crate_name ffs

* Don't clean URLs... what is rustdoc doing?

* now it wants to work???

* build a next index page

* unreleased docs banner

* show coverage

* remove ./ ???

* try 2?

* api-docs/ not api-docs-public/

* please
2022-01-15 19:57:35 +01:00
Muhammad Hamza
f05ba4152c
Update to edition 2021 (#2354)
* cargo fix --edition

* change edition="2018" to edition="2021" in Cargo.toml
2022-01-12 16:22:00 +02:00
Kaede Hoshikawa
d8c2550fc7
Server-side Rendering (without hydration) (#2335)
* Basic render to html implementation.

* Remove HtmlWriter.

* Escape html content.

* Add non-suspense tests.

* Add Suspense tests.

* Gated "ssr" feature.

* Add example.

* Fix tests.

* Fix docs.

* Fix heading size.

* Remove the unused YewRenderer.

* Remove extra comment.

* unify naming.

* Update docs.

* Update docs.

* Update docs.

* Isolate spawn_local.

* Add doc flags.

* Add ssr feature to docs.

* Move ServerRenderer into their own file.

* Fix docs.

* Update features and docs.

* Fix example.

* Adjust comment position.

* Fix effects being wrongly called when a component is suspended.

* Fix clippy.

* Uuid & no double boxing.

Co-authored-by: Muhammad Hamza <muhammadhamza1311@gmail.com>
2022-01-12 18:43:09 +05:00
Julius Lungys
99f949da9a
Remove important note from API docs (#2363) 2022-01-12 18:30:11 +05:00
Jonathan Bailey
923f6434df
Support named wildcards when deriving Routable. (#2345) 2022-01-12 18:27:14 +05:00
Kaede Hoshikawa
5dd8b7635c
Make BaseComponent Sealed. (#2359) 2022-01-11 17:00:41 +02:00