{"id":20872762,"url":"https://github.com/zalari/custom-elements-loader-prototype","last_synced_at":"2025-05-12T13:33:55.767Z","repository":{"id":41719512,"uuid":"238673890","full_name":"zalari/custom-elements-loader-prototype","owner":"zalari","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-07T14:42:15.000Z","size":1230,"stargazers_count":6,"open_issues_count":19,"forks_count":1,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-04-01T06:34:06.806Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zalari.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-06T11:31:39.000Z","updated_at":"2024-09-23T18:39:49.000Z","dependencies_parsed_at":"2023-02-07T11:01:49.979Z","dependency_job_id":null,"html_url":"https://github.com/zalari/custom-elements-loader-prototype","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalari%2Fcustom-elements-loader-prototype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalari%2Fcustom-elements-loader-prototype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalari%2Fcustom-elements-loader-prototype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zalari%2Fcustom-elements-loader-prototype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zalari","download_url":"https://codeload.github.com/zalari/custom-elements-loader-prototype/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253748393,"owners_count":21957916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T06:20:48.394Z","updated_at":"2025-05-12T13:33:55.430Z","avatar_url":"https://github.com/zalari.png","language":"TypeScript","readme":"# Custom-Element-Loader-Prototype\n\n## Intro\nThis is a rough-but-working prototype, that showcases loading CustomElements via `script` tags _as often_ as you like and it will re-apply the code by internally _monkey-patching_ the `CustomElements` API (for your own good!).\n\nThis can be used to either conditionally reload composable code pieces that are either natively written as _Custom Elements_ (vulgo **Web Components**) or are wrapped as those or simply reload them, **without** a reload of the hosting web page.\n\nThink of it as _production HotModuleReplacement_; but without _augmenting_ your code, nor maintaining a deep reference to use code paths.\n\nThis will happily work together with a CDN like [Unpkg.com](https://unpkg.com) because the code gets loaded via `script tags` there is also no problem with the _Same-Origin-Policy_ at all. Even _Content-Secure-Policy_ should be no problem, if you have proper _white-lists_ in place.\n\n## Example\n* basically you have to _just_ load the custom-element-loader-prototype **as early as possible** and then _things should just work_(**TM**):\n  * _add_ the markup for your _CustomElement_ to your code\n  * _load_ your _CustomElement_ the way you want to load it and _define_ it: `CustomElements.define()`...\n  * _rinse_ and _repeat_, i.e. repeat the above steps but with an _updated_ version of your code and remove and add the initial markup for your custom element in your app _dynamically_\n\n* see [src/examples/simple-static.html](src/examples/simple-static.html) for a simple example with a CustomElement fetched via [unpkg](https://unpkg.com/)\n\n## Known Limitations\n* currently only tested in a most most recentish Chrome (but the actual technique should even work with Polyfills for the Custom Element API)\n* not-memory optimized, meaning it is unlikely whether _old_ versions of a Custom Element are properly _garbage-collected_\n* no _event-rerouting_ this is in theory possible via _monkey-patching_ `.addEventListener` and `.dispatchEvent` as well; but I'd suggest using an indirection mechanism (read: message bus) for inter-component communication.\n\n## TODOs:\n* write at least basic tests, that are running the _manual integration tests_(**TM**) _automatically_ via [Puppeteer](https://github.com/puppeteer/puppeteer)\n  * test for good impl of CE API\n* actually do not abuse TS anymore:\n  * get rid of `any`\n  * use DOM Interfaces for contracts\n* re-route attributes\n* re-route slot projections\n* do some naive comparison whether new version of CE is the same as old one...\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzalari%2Fcustom-elements-loader-prototype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzalari%2Fcustom-elements-loader-prototype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzalari%2Fcustom-elements-loader-prototype/lists"}