import React from 'react'; import ReactDOM from 'react-dom/server.js'; import StaticHtml from './static-html.js'; const slotName = (str) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase()); const reactTypeof = Symbol.for('react.element'); function errorIsComingFromPreactComponent(err) { return ( err.message && (err.message.startsWith("Cannot read property '__H'") || err.message.includes("(reading '__H')")) ); } function check(Component, props, children) { // Note: there are packages that do some unholy things to create "components". // Checking the $$typeof property catches most of these patterns. if (typeof Component === 'object') { const $$typeof = Component['$$typeof']; return $$typeof && $$typeof.toString().slice('Symbol('.length).startsWith('react'); } if (typeof Component !== 'function') return false; if (Component.prototype != null && typeof Component.prototype.render === 'function') { return React.Component.isPrototypeOf(Component) || React.PureComponent.isPrototypeOf(Component); } let error = null; let isReactComponent = false; function Tester(...args) { try { const vnode = Component(...args); if (vnode && vnode['$$typeof'] === reactTypeof) { isReactComponent = true; } } catch (err) { if (!errorIsComingFromPreactComponent(err)) { error = err; } } return React.createElement('div'); } renderToStaticMarkup(Tester, props, children, {}); if (error) { throw error; } return isReactComponent; } function renderToStaticMarkup(Component, props, { default: children, ...slotted }, metadata) { delete props['class']; const slots = {}; for (const [key, value] of Object.entries(slotted)) { const name = slotName(key); slots[name] = React.createElement(StaticHtml, { value, name }); } // Note: create newProps to avoid mutating `props` before they are serialized const newProps = { ...props, ...slots, }; const newChildren = children ?? props.children; if (newChildren != null) { newProps.children = React.createElement(StaticHtml, { value: newChildren }); } const vnode = React.createElement(Component, newProps); let html; if (metadata && metadata.hydrate) { html = ReactDOM.renderToString(vnode); } else { html = ReactDOM.renderToStaticMarkup(vnode); } return { html }; } export default { check, renderToStaticMarkup, }; d'>chris/social-feed Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/packages/astro/e2e/fixtures/prefetch/src/pages/prefetch-tap.astro (unfollow)
AgeCommit message (Collapse)AuthorFilesLines
2024-11-14Update to svelte 5 (#12364)Gravatar Jacob Jenkins 77-636/+459
Co-authored-by: bluwy <bjornlu.dev@gmail.com>
2024-11-14[ci] formatGravatar Arpan Patel 1-6/+2
2024-11-14Fix script injection during build (#12392)Gravatar Arpan Patel 5-37/+48
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
2024-11-13[ci] release (#12422)astro@4.16.12Gravatar Houston (Bot) 28-54/+55
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-11-13fix(routing): middleware in dev (#12420)Gravatar Emanuele Stoppa 6-9/+52
2024-11-12[ci] release (#12403)astro@4.16.11Gravatar Houston (Bot) 30-73/+68
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-11-11[ci] formatGravatar Sarah Rainsberger 1-38/+38
2024-11-11update markdown config docs (#12382)Gravatar Sarah Rainsberger 1-4/+45
Co-authored-by: ArmandPhilippot <59021693+ArmandPhilippot@users.noreply.github.com> Co-authored-by: ematipico <602478+ematipico@users.noreply.github.com> Co-authored-by: jsparkdev <39112954+jsparkdev@users.noreply.github.com> Co-authored-by: bluwy <34116392+bluwy@users.noreply.github.com>
2024-11-08Fix incorrect status code in dev server for action errors (#12401)Gravatar Ben Holmes 2-13/+21
* remove default status that swallows response.status * refactor status compute to be more readable * changeset
2024-11-08fix(actions): better runtime check for invalid usages (#12402)Gravatar Emanuele Stoppa 8-5/+47
2024-11-08fix: error overlay message escape (#12305)Gravatar Florian Lefebvre 3-0/+28
Co-authored-by: Princesseuh <3019731+Princesseuh@users.noreply.github.com>
2024-11-06[ci] release (#12369)astro@4.16.10@astrojs/svelte@5.7.3Gravatar Houston (Bot) 34-81/+74
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-11-06[ci] formatGravatar Bjorn Lu 2-18/+17
2024-11-06Add support for Svelte 5 @render syntax (#12390)Gravatar Bjorn Lu 3-0/+30
Co-authored-by: Jonas Robertsson <jonas.robertsson@icloud.com>
2024-11-06fix(deps): update all non-major dependencies (#12366)Gravatar renovate[bot] 29-533/+552
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: bluwy <bjornlu.dev@gmail.com>
2024-11-06add `checked` to htmlBooleanAttributes (#12311)Gravatar Sujal Gurung 2-1/+6
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
2024-11-06fix: show file name with invalid frontmatter errors for MDX (#12355)Gravatar Arpan Patel 6-63/+50
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: Princesseuh <3019731+Princesseuh@users.noreply.github.com>
2024-11-06[ci] formatGravatar Emanuele Stoppa 2-3/+3
2024-11-06chore: codspeed benchmark (#12347)Gravatar Emanuele Stoppa 19-42/+527
2024-11-06Fix `astro add` generated import identifier (#12363)Gravatar Luiz Ferraz 2-1/+11
2024-11-04Improve tinyexec errors (#12368)Gravatar Bjorn Lu 11-5/+45
2024-11-04[ci] release (#12345)astro@4.16.9Gravatar Houston (Bot) 33-79/+65
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-11-04fix: honor getViteConfig inlineAstroConfig.logLevel setting (#12358)Gravatar Paul Welsh 2-7/+8
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
2024-11-04Fix watchfile multiple dev server restart (#12353)Gravatar Hippo 2-1/+8
2024-11-01fix: revert #12227 (#12351)Gravatar Florian Lefebvre 4-8/+11
2024-11-01[ci] formatGravatar Vladislav Mamon 2-5/+7
2024-11-01fix(assets): fix `getImage` options type (#12349)Gravatar Vladislav Mamon 3-3/+13
2024-11-01Fix prefetch sourcemap generation (#12346)Gravatar Bjorn Lu 2-6/+21
2024-10-31fix: Destroy the node http server response stream if there was a caught ↵Gravatar Matt Callaway 2-2/+9
error (#12333)
2024-10-31[ci] release (#12290)astro@4.16.8@astrojs/mdx@3.1.9Gravatar Houston (Bot) 36-93/+80
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-10-31Fix cli command typo (#12342)Gravatar liruifengv 2-1/+6
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
2024-10-31[ci] formatGravatar situ2001 1-1/+1
2024-10-31fix(cli): reset `NODE_ENV` to ensure install command run in dev mode (#12338)Gravatar situ2001 2-1/+12